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

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@11026 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
rem..om 11 years ago
parent 1ef4c21391
commit 31b9c41e8a
  1. 20
      engine/src/core-data/Common/MatDefs/Light/Lighting.j3md
  2. 1
      engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md
  3. 8
      engine/src/core-data/Common/MatDefs/Shadow/PostShadow.frag
  4. 1
      engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md
  5. 24
      engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert
  6. 12
      engine/src/core-data/Common/MatDefs/Shadow/PostShadow15.frag
  7. 28
      engine/src/core-data/Common/MatDefs/Shadow/PostShadow15.vert
  8. 15
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.frag
  9. 1
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.j3md
  10. 12
      engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter15.frag
  11. 2
      engine/src/core/com/jme3/shadow/SpotLightShadowRenderer.java

@ -124,6 +124,7 @@ MaterialDef Phong Lighting {
Matrix4 LightViewProjectionMatrix4
Matrix4 LightViewProjectionMatrix5
Vector3 LightPos
Vector3 LightDir
Float PCFEdge
Float ShadowMapSize
@ -282,6 +283,25 @@ MaterialDef Phong Lighting {
}
Technique PreNormalPassDerivative {
VertexShader GLSL100 : Common/MatDefs/MSSAO/normal.vert
FragmentShader GLSL100 : Common/MatDefs/MSSAO/normal.frag
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
NUM_BONES : NumberOfBones
}
}
Technique GBuf {
VertexShader GLSL100: Common/MatDefs/Light/GBuf.vert

@ -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;

@ -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());
}
/**

Loading…
Cancel
Save