summaryrefslogtreecommitdiff
path: root/drivers/gles3/shaders/scene.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles3/shaders/scene.glsl')
-rw-r--r--drivers/gles3/shaders/scene.glsl34
1 files changed, 26 insertions, 8 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 12cbe02d0c..bcaf4a57a8 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -3,6 +3,8 @@
#define M_PI 3.14159265359
+#define SHADER_IS_SRGB false
+
/*
from VisualServer:
@@ -514,6 +516,7 @@ VERTEX_SHADER_CODE
/* clang-format off */
[fragment]
+
/* texture unit usage, N is max_texture_unity-N
1-skeleton
@@ -533,6 +536,7 @@ uniform highp mat4 world_transform;
/* clang-format on */
#define M_PI 3.14159265359
+#define SHADER_IS_SRGB false
/* Varyings */
@@ -1020,16 +1024,27 @@ LIGHT_SHADER_CODE
#if defined(SPECULAR_BLINN)
+ //normalized blinn
vec3 H = normalize(V + L);
float cNdotH = max(dot(N, H), 0.0);
- float intensity = pow(cNdotH, (1.0 - roughness) * 256.0);
+ float cVdotH = max(dot(V, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float blinn = pow(cNdotH, shininess);
+ blinn *= (shininess + 8.0) / (8.0 * 3.141592654);
+ float intensity = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
+
specular_light += light_color * intensity * specular_blob_intensity * attenuation;
#elif defined(SPECULAR_PHONG)
vec3 R = normalize(-reflect(L, N));
float cRdotV = max(0.0, dot(R, V));
- float intensity = pow(cRdotV, (1.0 - roughness) * 256.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float phong = pow(cRdotV, shininess);
+ phong *= (shininess + 8.0) / (8.0 * 3.141592654);
+ float intensity = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
+
specular_light += light_color * intensity * specular_blob_intensity * attenuation;
#elif defined(SPECULAR_TOON)
@@ -1070,11 +1085,11 @@ LIGHT_SHADER_CODE
float G = G_GGX_2cos(cNdotL, alpha) * G_GGX_2cos(cNdotV, alpha);
#endif
// F
- float F0 = 1.0; // FIXME
- float cLdotH5 = SchlickFresnel(cLdotH);
- float F = mix(cLdotH5, 1.0, F0);
+ //float F0 = 1.0;
+ //float cLdotH5 = SchlickFresnel(cLdotH);
+ //float F = mix(cLdotH5, 1.0, F0);
- float specular_brdf_NL = cNdotL * D * F * G;
+ float specular_brdf_NL = cNdotL * D /* F */ * G;
specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
#endif
@@ -1121,8 +1136,9 @@ float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 p
avg += textureProj(shadow, vec4(pos + vec2(0.0, shadow_pixel_size.y * 2.0), depth, 1.0));
avg += textureProj(shadow, vec4(pos + vec2(0.0, -shadow_pixel_size.y * 2.0), depth, 1.0));
return avg * (1.0 / 13.0);
+#endif
-#elif defined(SHADOW_MODE_PCF_5)
+#ifdef SHADOW_MODE_PCF_5
float avg = textureProj(shadow, vec4(pos, depth, 1.0));
avg += textureProj(shadow, vec4(pos + vec2(shadow_pixel_size.x, 0.0), depth, 1.0));
@@ -1131,7 +1147,9 @@ float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 p
avg += textureProj(shadow, vec4(pos + vec2(0.0, -shadow_pixel_size.y), depth, 1.0));
return avg * (1.0 / 5.0);
-#else
+#endif
+
+#if !defined(SHADOW_MODE_PCF_5) || !defined(SHADOW_MODE_PCF_13)
return textureProj(shadow, vec4(pos, depth, 1.0));