pex-gl / pex-renderer

Physically based renderer (PBR) and scene graph for PEX.
https://pex-gl.github.io/pex-renderer/examples/index.html
MIT License
234 stars 16 forks source link

Alpha blended transmission #377

Open vorg opened 1 month ago

vorg commented 1 month ago

In the previous version of pex-renderer we could combine transmission with alpha blending and have reflective glass 50% faded out based on baseColor.a opacity. That is no longer possible. Setting alpha blending disables transmission. What does the glTF spec says here?

dmnsgn commented 1 month ago

https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_transmission#blend-mode

The glTF alphaMode is used for alpha-as-coverage, NOT for physically-based transparency (i.e. this extension). If alpha-as-coverage is not being used, the blend mode of the material should be set to "OPAQUE" even though it is transparent. Again, it's helpful to think of alpha-as-coverage as whether the physical surface is there or not. transmission applies to the surface material that exists. Note that alpha-as-coverage can still be used along with transmission as shown in the example below.

But filament and three.js allow alpha:

https://github.com/mrdoob/three.js/blob/f0f0e195e16490dac58520cdae23a9feee7547f5/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js#L31

https://github.com/mrdoob/three.js/blob/f0f0e195e16490dac58520cdae23a9feee7547f5/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js#L7

https://github.com/google/filament/commit/25a82911016e8a9d6917688d530ea54c4d84a5c2