diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-09-30 22:03:13 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-30 22:03:13 -0300 |
commit | 0c82d113edc4f7cc1bef11c2e03b2a1b39de90fb (patch) | |
tree | 8b3f3d861b2fbba39553f6440d2d7fc8e1c5467b | |
parent | 42e2821d04a5efd434fffa090e817905d30a0c73 (diff) | |
parent | dfaf071ae3c06cf8ccd82b4b1f0e089e00d937f1 (diff) |
Merge pull request #11733 from tagcup/env_brdf
Fix environmental BRDF.
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 5c7cfecf3e..507d15f678 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1944,18 +1944,19 @@ FRAGMENT_SHADER_CODE //simplify for toon, as specular_light *= specular * metallic * albedo * 2.0; #else - //brdf approximation (Lazarov 2013) - float ndotv = clamp(dot(normal,eye_vec),0.0,1.0); - vec3 dielectric = vec3(0.034) * specular * 2.0; //energy conservation - vec3 f0 = mix(dielectric, albedo, metallic); + vec3 dielectric = vec3(0.034) * specular * 2.0; + vec3 specular_color = mix(dielectric, albedo, metallic); + // Environment brdf approximation (Lazarov 2013) + // see https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022); const vec4 c1 = vec4( 1.0, 0.0425, 1.04, -0.04); vec4 r = roughness * c0 + c1; + float ndotv = clamp(dot(normal,eye_vec),0.0,1.0); float a004 = min( r.x * r.x, exp2( -9.28 * ndotv ) ) * r.x + r.y; - vec2 brdf = vec2( -1.04, 1.04 ) * a004 + r.zw; + vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw; - specular_light *= min(1.0,50.0 * f0.g) * brdf.y + brdf.x * f0; + specular_light *= AB.x * specular_color + AB.y; #endif } |