Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/btdf_lut_frag.glsl
| #pragma BLENDER_REQUIRE(common_utiltex_lib.glsl) | #pragma BLENDER_REQUIRE(common_utiltex_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(bsdf_sampling_lib.glsl) | #pragma BLENDER_REQUIRE(bsdf_sampling_lib.glsl) | ||||
| uniform float sampleCount; | |||||
| uniform float z; | |||||
| out vec4 FragColor; | |||||
| void main() | void main() | ||||
| { | { | ||||
| float x = floor(gl_FragCoord.x) / (LUT_SIZE - 1.0); | float x = floor(gl_FragCoord.x) / (LUT_SIZE - 1.0); | ||||
| float y = floor(gl_FragCoord.y) / (LUT_SIZE - 1.0); | float y = floor(gl_FragCoord.y) / (LUT_SIZE - 1.0); | ||||
| float ior = clamp(sqrt(x), 0.05, 0.999); | float ior = clamp(sqrt(x), 0.05, 0.999); | ||||
| /* ior is sin of critical angle. */ | /* ior is sin of critical angle. */ | ||||
| float critical_cos = sqrt(1.0 - saturate(ior * ior)); | float critical_cos = sqrt(1.0 - saturate(ior * ior)); | ||||
| y = y * 2.0 - 1.0; | y = y * 2.0 - 1.0; | ||||
| /* Maximize texture usage on both sides of the critical angle. */ | /* Maximize texture usage on both sides of the critical angle. */ | ||||
| y *= (y > 0.0) ? (1.0 - critical_cos) : critical_cos; | y *= (y > 0.0) ? (1.0 - critical_cos) : critical_cos; | ||||
| /* Center LUT around critical angle to avoid strange interpolation issues when the critical | /* Center LUT around critical angle to avoid strange interpolation issues when the critical | ||||
| * angle is changing. */ | * angle is changing. */ | ||||
| y += critical_cos; | y += critical_cos; | ||||
| float NV = clamp(y, 1e-4, 0.9999); | float NV = clamp(y, 1e-4, 0.9999); | ||||
| float a = z * z; | float a = z_factor * z_factor; | ||||
| float a2 = clamp(a * a, 1e-8, 0.9999); | float a2 = clamp(a * a, 1e-8, 0.9999); | ||||
| vec3 V = vec3(sqrt(1.0 - NV * NV), 0.0, NV); | vec3 V = vec3(sqrt(1.0 - NV * NV), 0.0, NV); | ||||
| /* Integrating BTDF */ | /* Integrating BTDF */ | ||||
| float btdf_accum = 0.0; | float btdf_accum = 0.0; | ||||
| float fresnel_accum = 0.0; | float fresnel_accum = 0.0; | ||||
| for (float j = 0.0; j < sampleCount; j++) { | for (float j = 0.0; j < sampleCount; j++) { | ||||
| Show All 32 Lines | for (float i = 0.0; i < sampleCount; i++) { | ||||
| btdf_accum += btdf; | btdf_accum += btdf; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| btdf_accum /= sampleCount * sampleCount; | btdf_accum /= sampleCount * sampleCount; | ||||
| fresnel_accum /= sampleCount * sampleCount; | fresnel_accum /= sampleCount * sampleCount; | ||||
| if (z == 0.0) { | if (z_factor == 0.0) { | ||||
| /* Perfect mirror. Increased precision because the roughness is clamped. */ | /* Perfect mirror. Increased precision because the roughness is clamped. */ | ||||
| fresnel_accum = F_eta(ior, NV); | fresnel_accum = F_eta(ior, NV); | ||||
| } | } | ||||
| if (x == 0.0) { | if (x == 0.0) { | ||||
| /* Special case. */ | /* Special case. */ | ||||
| fresnel_accum = 1.0; | fresnel_accum = 1.0; | ||||
| btdf_accum = 0.0; | btdf_accum = 0.0; | ||||
| } | } | ||||
| /* There is place to put multi-scatter result (which is a little bit different still) | /* There is place to put multi-scatter result (which is a little bit different still) | ||||
| * and / or lobe fitting for better sampling of. */ | * and / or lobe fitting for better sampling of. */ | ||||
| FragColor = vec4(btdf_accum, fresnel_accum, 0.0, 1.0); | FragColor = vec4(btdf_accum, fresnel_accum, 0.0, 1.0); | ||||
| } | } | ||||