SpotLight : Applied the same changes to terrain lighting

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7979 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 9e5f9be5ec
commit 5476be99f7
  1. 12
      engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.frag
  2. 10
      engine/src/terrain/Common/MatDefs/Terrain/TerrainLighting.vert

@ -1,5 +1,6 @@
uniform float m_Shininess; uniform float m_Shininess;
uniform vec4 g_LightDirection;
varying vec4 AmbientSum; varying vec4 AmbientSum;
varying vec4 DiffuseSum; varying vec4 DiffuseSum;
@ -12,8 +13,7 @@ varying vec3 vnPosition;
varying vec3 vViewDir; varying vec3 vViewDir;
varying vec4 vLightDir; varying vec4 vLightDir;
varying vec4 vnLightDir; varying vec4 vnLightDir;
varying vec4 lightVec; varying vec3 lightVec;
varying vec4 spotVec;
#ifdef DIFFUSEMAP #ifdef DIFFUSEMAP
@ -647,12 +647,12 @@ void main(){
#endif #endif
float spotFallOff = 1.0; float spotFallOff = 1.0;
if(spotVec.w!=0.0){ if(g_LightDirection.w!=0.0){
vec3 L=normalize(lightVec.xyz); vec3 L=normalize(lightVec.xyz);
vec3 spotdir = normalize(spotVec.xyz); vec3 spotdir = normalize(g_LightDirection.xyz);
float curAngleCos = dot(-L, spotdir); float curAngleCos = dot(-L, spotdir);
float innerAngleCos = spotVec.w; float innerAngleCos = floor(g_LightDirection.w) * 0.001;
float outerAngleCos = lightVec.w; float outerAngleCos = fract(g_LightDirection.w);
float innerMinusOuter = innerAngleCos - outerAngleCos; float innerMinusOuter = innerAngleCos - outerAngleCos;
spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0); spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
if(spotFallOff<=0.0){ if(spotFallOff<=0.0){

@ -5,7 +5,6 @@ uniform mat4 g_ViewMatrix;
uniform vec4 g_LightColor; uniform vec4 g_LightColor;
uniform vec4 g_LightPosition; uniform vec4 g_LightPosition;
uniform vec4 g_LightDirection;
uniform vec4 g_AmbientLightColor; uniform vec4 g_AmbientLightColor;
uniform float m_Shininess; uniform float m_Shininess;
@ -24,8 +23,7 @@ varying vec3 vnViewDir;
varying vec4 vLightDir; varying vec4 vLightDir;
varying vec4 vnLightDir; varying vec4 vnLightDir;
varying vec4 lightVec; varying vec3 lightVec;
varying vec4 spotVec;
varying vec4 AmbientSum; varying vec4 AmbientSum;
varying vec4 DiffuseSum; varying vec4 DiffuseSum;
@ -92,9 +90,9 @@ void main(){
#endif #endif
//computing spot direction in view space and unpacking spotlight cos //computing spot direction in view space and unpacking spotlight cos
spotVec=(g_ViewMatrix *vec4(g_LightDirection.xyz,0.0) ); // spotVec=(g_ViewMatrix *vec4(g_LightDirection.xyz,0.0) );
spotVec.w=floor(g_LightDirection.w)*0.001; // spotVec.w=floor(g_LightDirection.w)*0.001;
lightVec.w = fract(g_LightDirection.w); // lightVec.w = fract(g_LightDirection.w);
AmbientSum = vec4(0.2, 0.2, 0.2, 1.0) * g_AmbientLightColor; // Default: ambient color is dark gray AmbientSum = vec4(0.2, 0.2, 0.2, 1.0) * g_AmbientLightColor; // Default: ambient color is dark gray
DiffuseSum = lightColor; DiffuseSum = lightColor;

Loading…
Cancel
Save