summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-09-29 19:17:34 -0300
committerJuan Linietsky <reduzio@gmail.com>2018-09-29 19:17:52 -0300
commit3333166b070dea0e1d1255a9f9c4cfefe0ec32e5 (patch)
treedce517791b6ff162c8d555448a1777ab653ed1d1 /drivers/gles2/shaders
parent0378a9ba80dc5083bbafa4a216ed70ea5d450c03 (diff)
Many more GLES2 fixes
Diffstat (limited to 'drivers/gles2/shaders')
-rw-r--r--drivers/gles2/shaders/scene.glsl75
1 files changed, 53 insertions, 22 deletions
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index 462aff8828..fc20cb81a2 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -165,7 +165,7 @@ uniform vec3 light_direction;
uniform vec3 light_position;
uniform float light_range;
-uniform vec4 light_attenuation;
+uniform float light_attenuation;
// spot
uniform float light_spot_attenuation;
@@ -463,10 +463,15 @@ VERTEX_SHADER_CODE
float normalized_distance = light_length / light_range;
- float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+ if (normalized_distance < 1.0) {
- vec3 attenuation = vec3(omni_attenuation);
- light_att = vec3(omni_attenuation);
+ float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation);
+
+ vec3 attenuation = vec3(omni_attenuation);
+ light_att = vec3(omni_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_vec);
@@ -478,17 +483,30 @@ VERTEX_SHADER_CODE
float light_length = length(light_rel_vec);
float normalized_distance = light_length / light_range;
- float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
- vec3 spot_dir = light_direction;
+ if (normalized_distance < 1.0) {
+
+ float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation);
+ vec3 spot_dir = light_direction;
+
+ float spot_cutoff = light_spot_angle;
- float spot_cutoff = light_spot_angle;
+ float angle = dot(-normalize(light_rel_vec), spot_dir);
- float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
- float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+ if (angle > spot_cutoff) {
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+ float scos = max(angle, spot_cutoff);
+ float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+
+ spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+
+ light_att = vec3(spot_attenuation);
+ } else {
+ light_att=vec3(0.0);
+ }
+ } else {
+ light_att=vec3(0.0);
+ }
- light_att = vec3(spot_attenuation);
L = normalize(light_rel_vec);
#endif
@@ -814,7 +832,7 @@ uniform vec3 light_direction;
// omni
uniform vec3 light_position;
-uniform vec4 light_attenuation;
+uniform float light_attenuation;
// spot
uniform float light_spot_attenuation;
@@ -1267,6 +1285,7 @@ void main() {
float clearcoat_gloss = 0.0;
float anisotropy = 0.0;
vec2 anisotropy_flow = vec2(1.0, 0.0);
+ float sss_strength = 0.0; //unused
float alpha = 1.0;
float side = 1.0;
@@ -1474,10 +1493,14 @@ FRAGMENT_SHADER_CODE
float light_length = length(light_vec);
float normalized_distance = light_length / light_range;
+ if (normalized_distance < 1.0) {
- float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+ float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation);
- light_att = vec3(omni_attenuation);
+ light_att = vec3(omni_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_vec);
#endif
@@ -1643,17 +1666,25 @@ FRAGMENT_SHADER_CODE
float light_length = length(light_rel_vec);
float normalized_distance = light_length / light_range;
- float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
- vec3 spot_dir = light_direction;
-
- float spot_cutoff = light_spot_angle;
+ if (normalized_distance < 1.0) {
+ float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation);
+ vec3 spot_dir = light_direction;
- float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
- float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+ float spot_cutoff = light_spot_angle;
+ float angle = dot(-normalize(light_rel_vec), spot_dir);
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+ if (angle > spot_cutoff) {
+ float scos = max(angle, spot_cutoff);
+ float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+ spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
- light_att = vec3(spot_attenuation);
+ light_att = vec3(spot_attenuation);
+ } else {
+ light_att = vec3(0.0);
+ }
+ } else {
+ light_att = vec3(0.0);
+ }
L = normalize(light_rel_vec);