Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Add example model for KHR_materials_transmission #265

Merged
merged 13 commits into from
Sep 15, 2020

Conversation

MiiBond
Copy link
Contributor

@MiiBond MiiBond commented Jun 16, 2020

No description provided.

@cx20
Copy link
Contributor

cx20 commented Jun 18, 2020

To be consistent with other samples, it is better to name the sample model file the same as the folder name is a good idea.

Folder Name File Name
Duck/glTF Duck.gltf
Duck/glTF-Binary Duck.glb

@MiiBond
Copy link
Contributor Author

MiiBond commented Jun 19, 2020

To be consistent with other samples, it is better to name the sample model file the same as the folder name is a good idea.

@cx20 Good point. Done.

@cx20
Copy link
Contributor

cx20 commented Jun 19, 2020

I tried adding this model to gltf-test as a trial.
https://github.com/cx20/gltf-test#extension-test-models

image

So far, only Babylon.js seems to support this extension.

BTW, it may be a matter of taste, but I prefer the model to be in the center of the Scene, as in the ClearCoatTest model.

…e requirement of texture transform extension
Copy link
Member

@emackey emackey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a beautiful model! I left some nit-picky comments.

2.0/TransmissionTest/glTF/TransmissionTest.gltf Outdated Show resolved Hide resolved
2.0/TransmissionTest/glTF/TransmissionTest.gltf Outdated Show resolved Hide resolved
@emackey
Copy link
Member

emackey commented Jun 25, 2020

@lexaknyazev It looks like CI didn't run here. Any ideas?

@emackey
Copy link
Member

emackey commented Jun 25, 2020

@lexaknyazev Correction, CI is running, just not showing up as green checkmarks or red X's on this PR. It's not warning me not to merge the PR with an error in it.

https://travis-ci.org/github/KhronosGroup/glTF-Sample-Models/builds

@emackey
Copy link
Member

emackey commented Jun 25, 2020

GitHub isn't showing it, but validation has passed: https://travis-ci.org/github/KhronosGroup/glTF-Sample-Models/builds/702172431

Copy link
Member

@emackey emackey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample model looks good to me. We'll hold off merging until KhronosGroup/glTF#1698 is merged.

@cx20
Copy link
Contributor

cx20 commented Jun 27, 2020

I tried displaying this model in Babylon.js Sandbox again. However, if you apply the glTF's built-in camera on the latest version of the model, it doesn't seem to fit in the frame.

Previous model result:
image

Current model result:
image

I would suggest removing the built-in camera or adjusting it to fit in the frame.

@abwood
Copy link
Contributor

abwood commented Jul 19, 2020

Great model! After taking a close look, I've got a few questions regarding the sample.

I noticed that in cases where a transmission texture is used (e.g., RedTransTexture), we specify a transmission texture but transmission factor is not specified. Does it need to be? The spec says that transmissionTexture and factor are to be combined, but transmissionFactor defaults to 0, resulting in no transmission.

"GreenMask" material is using alphaMode="Blend". Should alphaMode be set to Mask? The texture is indeed a masking texture. There are possibly other materials that could be set to Mask rather than blend. The more of these spheres that render in the opaque pass, the better.

A final minor comment is that all meshes are named "Sphere". For debugging purposes it would be helpful if these had unique names.

@MiiBond
Copy link
Contributor Author

MiiBond commented Jul 20, 2020

Thanks for catching that. I've updated transmissionFactor where appropriate.
The mask textures as basically black and white so, yeah, they could probably use "MASK". However, the point of including them was to test that a renderer is combining the transmission logic and alpha-blending transparency logic correctly. I could make these textures use more grey values to extenuate this.
I've renamed the spheres too.

@donmccurdy
Copy link
Contributor

In several renderers I'm seeing some issue that looks like imprecision in the alpha (UVs too close to a texture boundary?).

Screen Shot 2020-07-31 at 1 05 10 PM

The screenshot above is from three.js, which doesn't support the transmission extension yet, but the same thing appears in BabylonJS, which does.

@emackey
Copy link
Member

emackey commented Aug 3, 2020

@donmccurdy I should double-check, but that error looks very, very familiar to me. It's what happens when you have a double-sided sphere, with BLEND enabled and the z-buffer writes disabled, with no depth sorting.

I even have a hacky workaround for such models: Make two co-located single-sided spheres, as separate primitives. Either the inside or the outside will be consistently "on top", which looks better than the bands even if the order comes out wrong. But I don't know if such hacky workarounds belong in official sample models, probably they don't.

@elalish
Copy link
Contributor

elalish commented Aug 3, 2020 via email

@donmccurdy
Copy link
Contributor

@emackey Nice guess, you're correct that the model is using doubleSided: true and alphaMode: BLEND in some materials. I would've expected this model to only require single-sided materials and a combination of OPAQUE and MASK alpha modes, though.

Screen Shot 2020-08-03 at 11 29 51 AM

^table does not include transmissionTexture, as gltf-transform inspect doesn't detect that yet.

@abwood
Copy link
Contributor

abwood commented Aug 3, 2020

Yes, I can confirm this is an issue with BLEND mode, and the "easiest" way to fix this is to render doublesided transmission objects in two passes, backfaces then front faces. I raised the BLEND vs MASK point earlier in this PR, but the choice of BLEND mode is intentional and likely helped us uncover a bug in another engine as a result anyway. I think many of these spheres look better as doublesided anyway, as these patterns on the backside should be visible through the spheres.

@MiiBond
Copy link
Contributor Author

MiiBond commented Aug 4, 2020

Yes, double-sided is very intensional as these are thin-shells where you can see the inside surface.
We could include a alpha map with more greyscale values so that the choice of BLEND setting is more clear but I don't feel strongly about this.

@donmccurdy
Copy link
Contributor

donmccurdy commented Aug 4, 2020

From the proposed spec:

If alpha-as-coverage is not being used, the blend mode of the material should be set to "OPAQUE" even though it is transparent.

We don't typically expect transmissive or non-opaque materials to appear behind transmissive materials, do we? I understand that rendering doublesided transmission in two passes is useful here, but I worry that this model is testing many things not required in the spec:

  1. OPAQUE materials visible through transmission
  2. BLEND materials visible through transmission
  3. other transmissive object visible through transmission
  4. same transmissive object visible through transmission

(1) and (3) are fine, I'm wondering about (2) and (4). I'd rather not mix an alpha map with the sample, no. But should some of this be spelled out in the spec? Do we expect all clients to split doubleSided materials into two passes, or is that case-by-case?

@donmccurdy
Copy link
Contributor

However, the point of including [BLEND] was to test that a renderer is combining the transmission logic and alpha-blending transparency logic correctly.

I might still prefer that this use MASK, rather than BLEND. It seems better for this example to demonstrate best practice than to exercise all the edge cases, and if we're deviating from best practice in order to show an edge case we should be very clear about that in the README. But I think it would be easier to exercise those combinations in a separate example more like https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AlphaBlendModeTest, later.

@emackey
Copy link
Member

emackey commented Sep 11, 2020

@donmccurdy I'm not sure BLEND vs MASK makes much difference to this model, although I certainly agree we should have a separate test model to break out specific edge cases. Off-topic, but not everyone on the Filament team is on board with the way we did MASK, and there are separate open issues on that.

Can this sample go in as-is?

@donmccurdy
Copy link
Contributor

I'm not sure BLEND vs MASK makes much difference to this model....

That's almost the point — in a world where all engines support BLEND triangle sorting perfectly, you'd practically never need MASK, BLEND would always work fine. But implementation is not that simple, and so if you could use either, you should choose MASK.

I can't see any reason to use BLEND here, except to make implementation more difficult. I don't think that is the right goal for our sample models, which should aim to show best practice and be very clear about the reason when they do not. We deal with three.js users (very regularly) having trouble with models using BLEND that could be using OPAQUE or MASK, and I don't want to encourage that as the default for exporters with the new transmission materials. 😕

More generally: if alpha-as-coverage does not need semitransparency, the blend mode should be "MASK" and not "BLEND", as if the transmission property were not involved at all.

@emackey
Copy link
Member

emackey commented Sep 12, 2020

@donmccurdy Good points here.

@MiiBond You did say in an earlier comment here that the use of BLEND is intentional, but BLEND is known to be problematic when multiple polygons overlap, such as on a double-sided sphere, even in the absence of transmission. I think we need to test transmission with BLEND on geometry that doesn't overlap, which would mean a different test model than this. In light of that, would it be OK to switch this model to use MASK?

@MiiBond
Copy link
Contributor Author

MiiBond commented Sep 14, 2020

Hi. Sorry, I've been neglecting this PR.

Yeah, MASK is definitely more appropriate. I usually export with BLEND because it gives nicer edges and Dimension's web viewer does OIT.

@cx20
Copy link
Contributor

cx20 commented Sep 14, 2020

The following is the comparison result between the old and new models. The screenshot is a link to a sample. I can't determine if this is an expected result, but Babylon.js does show an improvement.

Before (BLEND) After (MASK)
Babylon.js image image
Filament image image

@donmccurdy
Copy link
Contributor

Thanks @MiiBond! Here's a summary of the materials in the latest draft:

Screen Shot 2020-09-14 at 2 48 21 PM

The only thing I might consider changing would be to replace the emissive "LabelMaterial" with an unlit material — it will behave better in path tracers or in rasterizers that use bloom effects. I'm not as concerned about that, so it's fine with me to merge this!

@MiiBond
Copy link
Contributor Author

MiiBond commented Sep 15, 2020

Re: unlit material. Are we okay including another extension in this sample model? I thought we were trying to avoid that.

@emackey
Copy link
Member

emackey commented Sep 15, 2020

Yeah, I think it's cleaner if we leave unlit out, so we're only testing the one extension here.

@donmccurdy
Copy link
Contributor

Ok, works for me. 👍

@emackey emackey merged commit 74898c2 into master Sep 15, 2020
@emackey emackey deleted the KHR_materials_transmission_test_model branch September 15, 2020 20:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants