summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-01 16:28:17 +0200
committerGitHub <noreply@github.com>2019-07-01 16:28:17 +0200
commitb0eeb1233580420bfcbbdd989e4a1beeb4b5fc7a (patch)
tree207f8ddb0b01e28b8cc61e0033721abfefe954f9 /drivers
parent6b30f284a0544972f761be3e92ad8d1b176c9f9f (diff)
parent80d732082bbf9491f355ebe7a634c81234ebb74e (diff)
Merge pull request #29909 from clayjohn/gles2-light-scale
Scale vertex lit lights by environment scale
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/shaders/scene.glsl57
1 files changed, 35 insertions, 22 deletions
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index 2aef913ae8..ca222362e7 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -262,7 +262,7 @@ void light_compute(
#endif
SRGB_APPROX(specular_brdf_NL)
- specular_interp += specular_brdf_NL * light_color * attenuation;
+ specular_interp += specular_brdf_NL * light_color * attenuation * (1.0 / M_PI);
}
}
@@ -1641,18 +1641,30 @@ FRAGMENT_SHADER_CODE
#endif // defined(USE_REFLECTION_PROBE1) || defined(USE_REFLECTION_PROBE2)
- // scales the specular reflections, needs to be be computed before lighting happens,
- // but after environment and reflection probes are added
- //TODO: this curve is not really designed for gammaspace, should be adjusted
- 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_position), 0.0, 1.0);
- float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
- vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
+ // environment BRDF approximation
- vec3 f0 = F0(metallic, specular, albedo);
- specular_light *= env.x * f0 + env.y;
+ {
+
+#if defined(DIFFUSE_TOON)
+ //simplify for toon, as
+ specular_light *= specular * metallic * albedo * 2.0;
+#else
+
+ // scales the specular reflections, needs to be be computed before lighting happens,
+ // but after environment and reflection probes are added
+ //TODO: this curve is not really designed for gammaspace, should be adjusted
+ 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_position), 0.0, 1.0);
+ float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
+ vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
+
+ vec3 f0 = F0(metallic, specular, albedo);
+ specular_light *= env.x * f0 + env.y;
+
+#endif
+ }
#ifdef USE_LIGHTMAP
//ambient light will come entirely from lightmap is lightmap is used
@@ -2048,6 +2060,17 @@ FRAGMENT_SHADER_CODE
specular_light += specular_interp * specular_blob_intensity * light_att;
diffuse_light += diffuse_interp * albedo * light_att;
+ // Same as above, needed for VERTEX_LIGHTING or else lights are too bright
+ 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_position), 0.0, 1.0);
+ float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
+ vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
+
+ vec3 f0 = F0(metallic, specular, albedo);
+ specular_light *= env.x * f0 + env.y;
+
#else
//fragment lighting
light_compute(
@@ -2115,16 +2138,6 @@ FRAGMENT_SHADER_CODE
diffuse_light *= 1.0 - metallic;
ambient_light *= 1.0 - metallic;
- // environment BRDF approximation
-
- {
-
-#if defined(DIFFUSE_TOON)
- //simplify for toon, as
- specular_light *= specular * metallic * albedo * 2.0;
-#endif
- }
-
gl_FragColor = vec4(ambient_light + diffuse_light + specular_light, alpha);
//add emission if in base pass