From 5476be99f75b654f98a0d91641618b0de7628012 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Fri, 5 Aug 2011 17:37:29 +0000 Subject: [PATCH] SpotLight : Applied the same changes to terrain lighting git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7979 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../Common/MatDefs/Terrain/TerrainLighting.frag | 12 ++++++------ .../Common/MatDefs/Terrain/TerrainLighting.vert | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag b/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag index e9f2e8467..bf79d84fa 100644 --- a/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag +++ b/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag @@ -1,5 +1,6 @@ uniform float m_Shininess; +uniform vec4 g_LightDirection; varying vec4 AmbientSum; varying vec4 DiffuseSum; @@ -12,8 +13,7 @@ varying vec3 vnPosition; varying vec3 vViewDir; varying vec4 vLightDir; varying vec4 vnLightDir; -varying vec4 lightVec; -varying vec4 spotVec; +varying vec3 lightVec; #ifdef DIFFUSEMAP @@ -647,12 +647,12 @@ void main(){ #endif float spotFallOff = 1.0; - if(spotVec.w!=0.0){ + if(g_LightDirection.w!=0.0){ vec3 L=normalize(lightVec.xyz); - vec3 spotdir = normalize(spotVec.xyz); + vec3 spotdir = normalize(g_LightDirection.xyz); float curAngleCos = dot(-L, spotdir); - float innerAngleCos = spotVec.w; - float outerAngleCos = lightVec.w; + float innerAngleCos = floor(g_LightDirection.w) * 0.001; + float outerAngleCos = fract(g_LightDirection.w); float innerMinusOuter = innerAngleCos - outerAngleCos; spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0); if(spotFallOff<=0.0){ diff --git a/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.vert b/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.vert index 648289e66..a3a1cc24e 100644 --- a/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.vert +++ b/engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.vert @@ -5,7 +5,6 @@ uniform mat4 g_ViewMatrix; uniform vec4 g_LightColor; uniform vec4 g_LightPosition; -uniform vec4 g_LightDirection; uniform vec4 g_AmbientLightColor; uniform float m_Shininess; @@ -24,8 +23,7 @@ varying vec3 vnViewDir; varying vec4 vLightDir; varying vec4 vnLightDir; -varying vec4 lightVec; -varying vec4 spotVec; +varying vec3 lightVec; varying vec4 AmbientSum; varying vec4 DiffuseSum; @@ -92,9 +90,9 @@ void main(){ #endif //computing spot direction in view space and unpacking spotlight cos - spotVec=(g_ViewMatrix *vec4(g_LightDirection.xyz,0.0) ); - spotVec.w=floor(g_LightDirection.w)*0.001; - lightVec.w = fract(g_LightDirection.w); + // spotVec=(g_ViewMatrix *vec4(g_LightDirection.xyz,0.0) ); + // spotVec.w=floor(g_LightDirection.w)*0.001; + // lightVec.w = fract(g_LightDirection.w); AmbientSum = vec4(0.2, 0.2, 0.2, 1.0) * g_AmbientLightColor; // Default: ambient color is dark gray DiffuseSum = lightColor;