diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-04-18 13:50:09 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-04-18 14:10:17 +0300 |
commit | edcf128ce279e1fa721a1ba16fc3a3dfeac4833b (patch) | |
tree | 4317cd33b39f63f90a26c33faf5790b965ebc3cd /source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl | |
parent | f1fb605ec9ffd69b82652f3702de8b7ada570fd8 (diff) |
Eevee: Introduction of world preconvolved envmap.
For now only compute GGX convolution. The GGX LUT used for the split sum approximation (UE4) is merged with the LTX mag LUT that uses the same parameters (theta and roughness)
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl new file mode 100644 index 00000000000..b8fac61519e --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl @@ -0,0 +1,46 @@ + +out vec4 FragColor; + +void main() { + vec3 N, T, B, V; + + float NV = ( 1.0 - (clamp(gl_FragCoord.y / BRDF_LUT_SIZE, 1e-4, 0.9999))); + float sqrtRoughness = clamp(gl_FragCoord.x / BRDF_LUT_SIZE, 1e-4, 0.9999); + float a = sqrtRoughness * sqrtRoughness; + float a2 = a * a; + + N = vec3(0.0, 0.0, 1.0); + T = vec3(1.0, 0.0, 0.0); + B = vec3(0.0, 1.0, 0.0); + V = vec3(sqrt(1.0 - NV * NV), 0.0, NV); + + setup_noise(); + + /* Integrating BRDF */ + float brdf_accum = 0.0; + float fresnel_accum = 0.0; + for (float i = 0; i < sampleCount; i++) { + vec3 H = sample_ggx(i, a2, N, T, B); /* Microfacet normal */ + vec3 L = -reflect(V, H); + float NL = L.z; + + if (NL > 0.0) { + float NH = max(H.z, 0.0); + float VH = max(dot(V, H), 0.0); + + float G1_v = G1_Smith_GGX(NV, a2); + float G1_l = G1_Smith_GGX(NL, a2); + float G_smith = 4.0 * NV * NL / (G1_v * G1_l); /* See G1_Smith_GGX for explanations. */ + + float brdf = (G_smith * VH) / (NH * NV); + float Fc = pow(1.0 - VH, 5.0); + + brdf_accum += (1.0 - Fc) * brdf; + fresnel_accum += Fc * brdf; + } + } + brdf_accum /= sampleCount; + fresnel_accum /= sampleCount; + + FragColor = vec4(brdf_accum, fresnel_accum, 0.0, 1.0); +}
\ No newline at end of file |