diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index 1bbe36bff..b307d51a5 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -4,7 +4,8 @@ uniform sampler2D dtex; uniform vec3 direction; uniform vec3 col; -uniform mat4 invproj; +uniform float sunangle = .54; + //uniform int hasclouds; //uniform vec2 wind; @@ -37,7 +38,16 @@ void main() { float NdotL = max(0., dot(norm, L)); - vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * NdotL; + vec3 D = direction; + vec3 R = reflect(eyedir, norm); + float angle = 3.14 * sunangle / 180; + float d = cos(angle); + float r = sin(angle); + float DdotR = dot (D, R); + vec3 S = R - DdotR * D; + vec3 Lightdir = DdotR < d ? normalize (d * D + normalize (S) * r) : R; + + vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * dot(Lightdir, norm); vec3 outcol = NdotL * col; diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 4e6babc99..cc4e307d6 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -9,6 +9,7 @@ uniform float splitmax; uniform vec3 direction; uniform vec3 col; +uniform float sunangle = .54; in vec2 uv; out vec4 Diff; @@ -51,7 +52,16 @@ void main() { float NdotL = max(0., dot(norm, L)); - vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * NdotL; + vec3 D = direction; + vec3 R = reflect(eyedir, norm); + float angle = 3.14 * sunangle / 180; + float d = cos(angle); + float r = sin(angle); + float DdotR = dot (D, R); + vec3 S = R - DdotR * D; + vec3 Lightdir = DdotR < d ? normalize (d * D + normalize (S) * r) : R; + + vec3 Specular = getSpecular(norm, eyedir, Lightdir, col, roughness) * dot(norm, Lightdir); vec3 outcol = NdotL * col;