From 84cf087ae6fa783100e382efac54f4d2fbeb0322 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 16 Dec 2014 02:10:26 +0100 Subject: [PATCH] Forget to update grass pass 2 sun location --- data/shaders/grass_pass2.frag | 7 +++---- data/shaders/instanced_grass_pass2.frag | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/data/shaders/grass_pass2.frag b/data/shaders/grass_pass2.frag index 0f881c161..311dab362 100644 --- a/data/shaders/grass_pass2.frag +++ b/data/shaders/grass_pass2.frag @@ -8,8 +8,6 @@ uniform sampler2D dtex; uniform sampler2D SpecMap; #endif -uniform vec3 SunDir; - in vec3 nor; in vec2 uv; out vec4 FragColor; @@ -35,10 +33,11 @@ void main(void) vec3 eyedir = normalize(xpos.xyz); // Inspired from http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html - float fEdotL = clamp(dot(SunDir, eyedir), 0., 1.); + vec3 L = normalize((transpose(InverseViewMatrix) * vec4(sun_direction, 0.)).xyz); + float fEdotL = clamp(dot(L, eyedir), 0., 1.); float fPowEdotL = pow(fEdotL, 4.); - float fLdotNBack = max(0., - dot(nor, SunDir) * 0.6 + 0.4); + float fLdotNBack = max(0., - dot(nor, L) * 0.6 + 0.4); float scattering = mix(fPowEdotL, fLdotNBack, .5); float specmap = texture(SpecMap, uv).g; diff --git a/data/shaders/instanced_grass_pass2.frag b/data/shaders/instanced_grass_pass2.frag index dace65097..f2201a82f 100644 --- a/data/shaders/instanced_grass_pass2.frag +++ b/data/shaders/instanced_grass_pass2.frag @@ -6,8 +6,6 @@ uniform sampler2D SpecMap; uniform sampler2D dtex; #endif -uniform vec3 SunDir; - #ifdef GL_ARB_bindless_texture flat in sampler2D handle; flat in sampler2D secondhandle; @@ -41,10 +39,11 @@ void main(void) vec3 eyedir = normalize(xpos.xyz); // Inspired from http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html - float fEdotL = clamp(dot(SunDir, eyedir), 0., 1.); + vec3 L = normalize((transpose(InverseViewMatrix) * vec4(sun_direction, 0.)).xyz); + float fEdotL = clamp(dot(L, eyedir), 0., 1.); float fPowEdotL = pow(fEdotL, 4.); - float fLdotNBack = max(0., - dot(nor, SunDir) * 0.6 + 0.4); + float fLdotNBack = max(0., - dot(nor, L) * 0.6 + 0.4); float scattering = mix(fPowEdotL, fLdotNBack, .5);