diff options
author | Liso <anlismon@gmail.com> | 2021-06-06 18:51:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-06 18:51:21 +0200 |
commit | c47313db65f968559711ac1b505ef341a9872017 (patch) | |
tree | 63d9b1b2be512918e2361d96e4fb52ff1ec3f9de /client/shaders/object_shader/opengl_vertex.glsl | |
parent | 46f42e15c41cf4ab23c5ff4cd8a7d99d94d10d7b (diff) | |
download | hax-minetest-server-c47313db65f968559711ac1b505ef341a9872017.tar.gz hax-minetest-server-c47313db65f968559711ac1b505ef341a9872017.zip |
Shadow mapping render pass (#11244)
Co-authored-by: x2048 <codeforsmile@gmail.com>
Diffstat (limited to 'client/shaders/object_shader/opengl_vertex.glsl')
-rw-r--r-- | client/shaders/object_shader/opengl_vertex.glsl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index f26224e82..f135ab9dc 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -13,12 +13,37 @@ varying mediump vec2 varTexCoord; centroid varying vec2 varTexCoord; #endif +#ifdef ENABLE_DYNAMIC_SHADOWS + // shadow uniforms + uniform vec3 v_LightDirection; + uniform float f_textureresolution; + uniform mat4 m_ShadowViewProj; + uniform float f_shadowfar; + uniform float f_shadow_strength; + uniform float f_timeofday; + varying float cosLight; + varying float normalOffsetScale; + varying float adj_shadow_strength; + varying float f_normal_length; +#endif + varying vec3 eyeVec; varying float vIDiff; const float e = 2.718281828459; const float BS = 10.0; +#ifdef ENABLE_DYNAMIC_SHADOWS +// custom smoothstep implementation because it's not defined in glsl1.2 +// https://docs.gl/sl4/smoothstep +float mtsmoothstep(in float edge0, in float edge1, in float x) +{ + float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); + return t * t * (3.0 - 2.0 * t); +} +#endif + + float directional_ambient(vec3 normal) { vec3 v = normal * normal; @@ -54,4 +79,25 @@ void main(void) #else varColor = inVertexColor; #endif + +#ifdef ENABLE_DYNAMIC_SHADOWS + + cosLight = max(0.0, dot(vNormal, -v_LightDirection)); + float texelSize = 0.51; + float slopeScale = clamp(1.0 - cosLight, 0.0, 1.0); + normalOffsetScale = texelSize * slopeScale; + if (f_timeofday < 0.2) { + adj_shadow_strength = f_shadow_strength * 0.5 * + (1.0 - mtsmoothstep(0.18, 0.2, f_timeofday)); + } else if (f_timeofday >= 0.8) { + adj_shadow_strength = f_shadow_strength * 0.5 * + mtsmoothstep(0.8, 0.83, f_timeofday); + } else { + adj_shadow_strength = f_shadow_strength * + mtsmoothstep(0.20, 0.25, f_timeofday) * + (1.0 - mtsmoothstep(0.7, 0.8, f_timeofday)); + } + f_normal_length = length(vNormal); + +#endif } |