@@ -73,33 +73,51 @@ vec3 CalculateImageBasedLighting(
7373 float metallic,
7474 vec3 F0,
7575 float NdotV,
76- vec3 albedo
76+ vec3 albedo,
77+ float transmission,
78+ float refractionIndex
7779) {
7880 // 0. Constants
7981 const int environmentMaxLOD = textureQueryLevels(environmentMap) - 1;
80-
82+
8183 // 1. Calculate reflection vector
8284 const vec3 R = ParallaxCorrect(reflect(-V, N), fragPos);
8385
84- // 2. Diffuse irradiance (environment lighting)
85- const vec3 irradiance = textureLod(environmentMap, N, environmentMaxLOD).rgb; // High mip level for diffuse
86+ // 2. Calculate refraction vector
87+ const vec3 T = ParallaxCorrect(refract(-V, N, 1.0 / refractionIndex), fragPos);
88+
89+ // 3. Diffuse irradiance (environment lighting)
90+ const vec3 irradiance = textureLod(environmentMap, N, environmentMaxLOD).rgb;
91+
92+ // 4. Specular reflection
93+ const vec3 reflectedColor = textureLod(environmentMap, R, roughness * environmentMaxLOD).rgb;
8694
87- // 3. Specular reflection
88- const vec3 prefilteredColor = textureLod(environmentMap, R , roughness * environmentMaxLOD).rgb;
95+ // 5. Refracted environment sampling
96+ const vec3 refractedColor = textureLod(environmentMap, T , roughness * environmentMaxLOD).rgb;
8997
90- // 4 . Apply BRDF
98+ // 6 . Apply BRDF
9199 const vec2 brdf = EnvBRDFApprox(NdotV, roughness);
92-
93- // 5 . Calculate Fresnel for IBL
100+
101+ // 7 . Calculate Fresnel for IBL
94102 const vec3 F_IBL = FresnelSchlickRoughness(NdotV, F0, roughness);
95103
96- // 6. Calculate specular and diffuse IBL components
104+ // 8. Calculate transmission factor based on Fresnel
105+ // Higher Fresnel = more reflection, less transmission
106+ const float avgFresnel = (F_IBL.r + F_IBL.g + F_IBL.b) / 3.0;
107+ const float transmissionFactor = transmission * (1.0 - avgFresnel);
108+
109+ // 9. Calculate diffuse and reflection IBL components
97110 const vec3 kS_IBL = F_IBL;
98111 const vec3 kD_IBL = (1.0 - kS_IBL) * (1.0 - metallic);
99-
100112 const vec3 diffuseIBL = kD_IBL * irradiance * albedo;
101- const vec3 specularIBL = prefilteredColor * (F_IBL * brdf.x + brdf.y);
113+ const vec3 reflectionIBL = reflectedColor * (F_IBL * brdf.x + brdf.y);
102114
103- // 7. Return IBL contribution
115+ // 10. Calculate refraction IBL component
116+ const vec3 refractionIBL = refractedColor * albedo;
117+
118+ // 11. Mix reflection and refraction contributions based on transmission factor
119+ const vec3 specularIBL = mix(reflectionIBL, refractionIBL, transmissionFactor);
120+
121+ // 12. Return combined IBL contribution
104122 return (diffuseIBL + specularIBL) * ubo_ReflectionProbeData.brightness;
105123}
0 commit comments