Compute light attenuation using Beer's law#24516
Conversation
|
Edit: Actually I misread your explanation, looking at the code it's still reusing the fog math. I'm not sure why I went with this one instead. Might have been a mistake or misunderstanding of some paper on my part? |
Thank you for checking. I first tried to keep the existing approach by only adapting the coefficient used with I pushed an update that applies the Khronos Sample Renderer formula directly in the transmission path. This avoids relying on fog internals and makes the code closer to the KHR_materials_volume reference implementation. |
e606dd6 to
b2ad6f1
Compare
b2ad6f1 to
40b7d44
Compare
mardzie
left a comment
There was a problem hiding this comment.
The Rust code looks fine. I am not familiar with WGSL and the math, someone with that expertise should also review.
There was a problem hiding this comment.
Wgsl/math looks good! Always good to catch little errors like these in our volumetrics math.
Just for context, can you explain the addition to get_linear_textures? Were we not keeping track of the thickness texture at all, or just not as a linear texture?
We were keeping track of it, but not as a linear texture. Before this fix, I noticed that the |

Objective
Fix volume attenuation for glTF materials using
KHR_materials_volume.Bevy was converting
attenuationColorwithpow(1.0 - color, E)to reuse the existing fog mathatmospheric_fog(), which under-attenuates transmitted light. This makes dark volume materials render too bright.I first tried to keep the existing structure and only fix the coefficient passed to
atmospheric_fog()(first commit). Since that function attenuates with:and
KHR_materials_volumedefinesattenuationColoras the transmittance afterattenuationDistance, solving:gives:
After discussing this with @coreh, I switched to applying the volume attenuation directly instead of routing it through the fog abstraction.
Solution
thicknessTextureis now loaded as a linear data texture, since its G channel stores thickness rather than color.Testing
Reviewers can test visually by loading the Khronos
AttenuationTestandDragonAttenuationassetsShowcase
Before PR
After

Ref Khronos
Before
After
Ref Khronos