KhronosGroup / glTF-Sample-Viewer

Physically-Based Rendering in glTF 2.0 using WebGL
Apache License 2.0
1.27k stars 234 forks source link

Is MATERIAL_VOLUME needed for MATERIAL_TRANSMISSION? #367

Closed jnsmalm closed 1 year ago

jnsmalm commented 2 years ago

In my case I use MATERIAL_TRANSMISSION together with USE_IBL, but in the code below it also assumes I'm using MATERIAL_VOLUME because it calls getIBLVolumeRefraction, is this intended or a bug? Can't I use MATERIAL_TRANSMISSION without MATERIAL_VOLUME?

#if (defined(MATERIAL_TRANSMISSION) || defined(MATERIAL_VOLUME)) && (defined(USE_PUNCTUAL) || defined(USE_IBL))
    f_transmission += materialInfo.transmissionFactor * getIBLVolumeRefraction(
        n, v,
        materialInfo.perceptualRoughness,
        materialInfo.baseColor, materialInfo.f0, materialInfo.f90,
        v_Position, u_ModelMatrix, u_ViewMatrix, u_ProjectionMatrix,
        materialInfo.ior, materialInfo.thickness, materialInfo.attenuationColor, materialInfo.attenuationDistance);
#endif
UX3D-nopper commented 2 years ago

we will cross check

emackey commented 2 years ago

The default behavior of KHR_materials_transmission is thin-walled transmission, meaning you can have blurring due to roughness, but there is no refraction (the ray exits the volume in the same place it entered). In order to enable transmission with refraction, a glTF model also needs the KHR_materials_volume extension, to provide (or at least indicate) volumetric thickness, along with optional settings such as attenuation color & distance.

jnsmalm commented 2 years ago

I see. Is a u_TransmissionFramebufferSampler always required? I guess it should not be needed if transmission roughness is 0, but in shader it seams like u_TransmissionFramebufferSampler is always required, is this by design?

ghost commented 1 year ago

u_TransmissionFramebufferSampler is only required when MATERIAL_TRANSMISSION is enabled. Theoretically, the sampler would not be needed if the transmission factor is zero, but this value depends on the current transmission texture value (if one is supplied).