KHR_material_volume: refraction inconsistency?
https://github.com/KhronosGroup/glTF-Sample-Environments/issues/7 My apologies if I originally posted this in the incorrect location.

We will have a look at it.
The reason for visual differences compared to a ray caster might be the surface normal of the exiting ray. Our rasterization-based algorithm (and Babylon.js) assumes the same surface normal at the entry point and at the exit point of the volume. This means, as soon as the ray leaves the volume, the ray is parallel to the incident ray. As the beads change their normals abruptly, a ray caster delivers better results especially in this case.
The reason for visual differences compared to Babylon.js is the KHR_materials_volume.thicknessFactor. The model has a thicknessFactor of 0.02, however, Babylon.js seems to ignore this thicknessFactor and assumes a thicknessFactor of 1.
Attached is a rendering done in Sample Viewer of a version of the stained glass lamp where I have manually set the thicknessFactor to 1. With this, you get the same visual result compared to Babylon.js.


Ah, thank you.
I wonder why a proper thickness value appears incorrect, compared to reference photography? The bead shapes in the model aren't a perfect match, but should be close enough. (oh sorry, re-reading your reply, it's the exit ray!)

I've set the thickness a bit too generous, the horizontal thickness ranges between 0.013 and 0.007 meters.

Same model, in the Enterprise PBR Sample Renderer pathtracer:

So does this mean I should be setting the thickness to 1 meter?
So does this mean I should be setting the thickness to 1 meter?
In this case yes, however, it is more of a lucky chance that this looks similar to raytraced refraction.
I wonder why a proper thickness value appears incorrect, compared to reference photography?
This is one of the limitations of the rasterized version of the volume extension. The rasterizer cannot take the geometry of the transmissive object into account, it only uses the thickness value as specified in the material for all fragments of the transmissive object. This can look good enough, as with the mosquito in amber model, but will not be able to display effects involving complex optics such as e.g. lenses, diamond shapes, or drops.
I've set the thickness a bit too generous, the horizontal thickness ranges between 0.013 and 0.007 meters.
For many assets measuring the thickness can be a good starting point, for us it helped to tweak the parameter in a live preview to get the most pleasing results.
As Eric stated in the call today, we can close it.
Thanks, this resolves the issue for me.
Apparently thicknessFactor should only be used to modulate attenuationColor, and not IOR? See this comment: https://github.com/BabylonJS/Babylon.js/issues/10193#issuecomment-820362391
Responding to this comment https://github.com/BabylonJS/Babylon.js/issues/10193#issuecomment-820362391
I can see in the Khronos GLTF viewer that the IOR is modified by the thickness factor (or at least it's what it seems):
From my understanding of the spec, IOR should not be modified by the volume extension...
glTF Sample Viewer also does not modify the IOR value for different thickness factors.
In accordance with the spec
We use the thickness map to estimate the distance that a light ray will travel until it exists the volume
we use the thickness value to determine the length of the ray in the volume. Therefore higher values can lead to a larger offset of the ray
There's no thickness map in this asset, so the thickness is a constant all over the mesh. Also, it seems you change the direction of the refracted ray according to some calculation involving the thickness before querying the refraction texture (at least that's what the deformation inside each sphere suggests): that's something we don't do in Babylon, so that would explain the difference.
There's no thickness map in this asset, so the thickness is a constant all over the mesh.
We combine thicknessFactor and the value sampled from thicknessTexture (which defaults to 1.0 if no thicknessTexture is specified) by multiplication to a thickness value. This value is then used as the length of the refracted ray. Therefore if no thicknessTexture is specified, the thickness value will be constant for the material.
Also, it seems you change the direction of the refracted ray according
The direction of the refraced ray is not changed by the thickness value, the effect in the above mentioned screenshot is only the result of different ray lengths.
Ok thanks for the explanation. I have also looked at the shader code to better understand. We do have a depth parameter in Babylon that is a multiplier for the ray, but it is a user defined value that existed before the thickness support and so which is not related to it. I guess we could add an option to also multiply by the thickness value when available...
