SpotLightShadowRenderer, fixed an issue where a spot light would wast shadows behind itself

git-svn-id: https://jmonkeyengine.googlecode.com/svn/branches/gradle-restructure@11027 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
rem..om 11 years ago
parent fd8a69707b
commit 4e63056be9
  1. 2
      jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java
  2. 1
      jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
  3. 1
      jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md
  4. 8
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.frag
  5. 1
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.j3md
  6. 24
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.vert
  7. 12
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow15.frag
  8. 28
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow15.vert
  9. 15
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.frag
  10. 1
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md
  11. 12
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter15.frag

@ -164,6 +164,8 @@ public class SpotLightShadowRenderer extends AbstractShadowRenderer {
@Override
protected void setMaterialParameters(Material material) {
material.setVector3("LightPos", light.getPosition());
material.setVector3("LightDir", light.getDirection());
}
/**

@ -124,6 +124,7 @@ MaterialDef Phong Lighting {
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir
Float PCFEdge
Float ShadowMapSize

@ -43,6 +43,7 @@ MaterialDef Unshaded {
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir
Float PCFEdge

@ -14,6 +14,10 @@ varying vec4 projCoord3;
varying vec4 projCoord5;
uniform vec3 m_LightPos;
varying vec4 worldPos;
#else
#ifndef PSSM
varying float lightDot;
#endif
#endif
#ifdef DISCARD_ALPHA
@ -57,6 +61,10 @@ void main(){
projCoord0, projCoord1, projCoord2, projCoord3);
#else
//spotlight
if(lightDot < 0){
outFragColor = vec4(1.0);
return;
}
shadow = getSpotLightShadows(m_ShadowMap0,projCoord0);
#endif
#endif

@ -24,6 +24,7 @@ MaterialDef Post Shadow {
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir
Float PCFEdge

@ -15,11 +15,17 @@ varying vec4 projCoord2;
varying vec4 projCoord3;
#ifdef POINTLIGHT
uniform mat4 m_LightViewProjectionMatrix4;
uniform mat4 m_LightViewProjectionMatrix5;
varying vec4 projCoord4;
varying vec4 projCoord5;
varying vec4 worldPos;
uniform mat4 m_LightViewProjectionMatrix4;
uniform mat4 m_LightViewProjectionMatrix5;
varying vec4 projCoord4;
varying vec4 projCoord5;
varying vec4 worldPos;
#else
#ifndef PSSM
uniform vec3 m_LightPos;
uniform vec3 m_LightDir;
varying float lightDot;
#endif
#endif
#ifdef PSSM
@ -70,9 +76,9 @@ void main(){
projCoord4 = biasMat * m_LightViewProjectionMatrix4 * worldPos;
projCoord5 = biasMat * m_LightViewProjectionMatrix5 * worldPos;
#else
vec4 vLightPos = g_ViewMatrix * vec4(m_LightPos,1.0);
vec4 vPos = g_ViewMatrix * worldPos;
lightVec = vLightPos.xyz - vPos.xyz;
#ifndef PSSM
vec3 lightDir = worldPos.xyz - m_LightPos;
lightDot = dot(m_LightDir,lightDir);
#endif
#endif
}

@ -16,6 +16,10 @@ in vec4 projCoord3;
in vec4 projCoord5;
in vec4 worldPos;
uniform vec3 m_LightPos;
#else
#ifndef PSSM
in float lightDot;
#endif
#endif
#ifdef DISCARD_ALPHA
@ -33,7 +37,7 @@ uniform vec2 m_FadeInfo;
#endif
void main(){
#ifdef DISCARD_ALPHA
#ifdef COLOR_MAP
float alpha = texture2D(m_ColorMap,texCoord).a;
@ -56,8 +60,12 @@ void main(){
shadow = getDirectionalLightShadows(m_Splits, shadowPosition,
m_ShadowMap0,m_ShadowMap1,m_ShadowMap2,m_ShadowMap3,
projCoord0, projCoord1, projCoord2, projCoord3);
#else
#else
//spotlight
if(lightDot < 0){
outFragColor = vec4(1.0);
return;
}
shadow = getSpotLightShadows(m_ShadowMap0,projCoord0);
#endif
#endif

@ -6,8 +6,6 @@ uniform mat4 m_LightViewProjectionMatrix3;
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldMatrix;
uniform mat4 g_ViewMatrix;
uniform vec3 m_LightPos;
out vec4 projCoord0;
out vec4 projCoord1;
@ -15,11 +13,17 @@ out vec4 projCoord2;
out vec4 projCoord3;
#ifdef POINTLIGHT
uniform mat4 m_LightViewProjectionMatrix4;
uniform mat4 m_LightViewProjectionMatrix5;
out vec4 projCoord4;
out vec4 projCoord5;
out vec4 worldPos;
uniform mat4 m_LightViewProjectionMatrix4;
uniform mat4 m_LightViewProjectionMatrix5;
out vec4 projCoord4;
out vec4 projCoord5;
out vec4 worldPos;
#else
#ifndef PSSM
uniform vec3 m_LightPos;
uniform vec3 m_LightDir;
out float lightDot;
#endif
#endif
#ifdef PSSM
@ -69,10 +73,10 @@ void main(){
#ifdef POINTLIGHT
projCoord4 = biasMat * m_LightViewProjectionMatrix4 * worldPos;
projCoord5 = biasMat * m_LightViewProjectionMatrix5 * worldPos;
#else
vec4 vLightPos = g_ViewMatrix * vec4(m_LightPos,1.0);
vec4 vPos = g_ViewMatrix * worldPos;
lightVec = vLightPos.xyz - vPos.xyz;
#else
#ifndef PSSM
vec3 lightDir = worldPos.xyz - m_LightPos;
lightDot = dot(m_LightDir,lightDir);
#endif
#endif
}

@ -22,6 +22,11 @@ uniform mat4 m_LightViewProjectionMatrix3;
uniform vec3 m_LightPos;
uniform mat4 m_LightViewProjectionMatrix4;
uniform mat4 m_LightViewProjectionMatrix5;
#else
#ifndef PSSM
uniform vec3 m_LightPos;
uniform vec3 m_LightDir;
#endif
#endif
#ifdef FADE
@ -51,7 +56,15 @@ void main(){
// get the vertex in world space
vec4 worldPos = vec4(getPosition(depth,texCoord),1.0);
#if (!defined(POINTLIGHT) && !defined(PSSM))
vec3 lightDir = worldPos.xyz - m_LightPos;
if( dot(m_LightDir,lightDir)<0){
gl_FragColor = color;
return;
}
#endif
// populate the light view matrices array and convert vertex to light viewProj space
vec4 projCoord0 = biasMat * m_LightViewProjectionMatrix0 * worldPos;
vec4 projCoord1 = biasMat * m_LightViewProjectionMatrix1 * worldPos;

@ -24,6 +24,7 @@ MaterialDef Post Shadow {
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir
Float PCFEdge

@ -24,6 +24,11 @@ uniform mat4 m_LightViewProjectionMatrix3;
uniform vec3 m_LightPos;
uniform mat4 m_LightViewProjectionMatrix4;
uniform mat4 m_LightViewProjectionMatrix5;
#else
#ifndef PSSM
uniform vec3 m_LightPos;
uniform vec3 m_LightDir;
#endif
#endif
#ifdef FADE
@ -48,6 +53,13 @@ vec4 main_multiSample(in int numSample){
// get the vertex in world space
vec4 worldPos = vec4(getPosition(depth,texCoord),1.0);
#if (!defined(POINTLIGHT) && !defined(PSSM))
vec3 lightDir = worldPos.xyz - m_LightPos;
if( dot(m_LightDir,lightDir)<0){
return color;
}
#endif
// populate the light view matrices array and convert vertex to light viewProj space
vec4 projCoord0 = biasMat * m_LightViewProjectionMatrix0 * worldPos;
vec4 projCoord1 = biasMat * m_LightViewProjectionMatrix1 * worldPos;

Loading…
Cancel
Save