From 5bc840e57ab451c42ce3180056fdf171f7d70d2c Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Tue, 17 Sep 2013 16:58:35 +0000 Subject: [PATCH] Fixed an isse where shader compilation would fail for shadows because of deprecated usage of varying in glsl1.5 shaders. Alsofixed an issue with the filter version of the shadow processor git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10788 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../Common/MatDefs/Light/Lighting.j3md | 2 +- .../Common/MatDefs/Misc/Unshaded.j3md | 2 +- .../Common/MatDefs/Shadow/PostShadow.j3md | 2 +- .../Common/MatDefs/Shadow/PostShadow15.vert | 78 +++++++++++++++++++ .../MatDefs/Shadow/PostShadowFilter.j3md | 6 +- .../MatDefs/Shadow/PostShadowFilter.vert | 5 +- .../MatDefs/Shadow/PostShadowFilter15.vert | 6 +- 7 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 engine/src/core-data/Common/MatDefs/Shadow/PostShadow15.vert diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md index ed4e67670..acfbc7e72 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md @@ -207,7 +207,7 @@ MaterialDef Phong Lighting { Technique PostShadow15{ - VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow.vert + VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow15.vert FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag WorldParameters { diff --git a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md index 460ad4ed1..aae534582 100644 --- a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md +++ b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md @@ -115,7 +115,7 @@ MaterialDef Unshaded { Technique PostShadow15{ - VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow.vert + VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow15.vert FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag WorldParameters { diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md index 9ce31b654..a79e7ba61 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.j3md @@ -31,7 +31,7 @@ MaterialDef Post Shadow { } Technique { - VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow.vert + VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow15.vert FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag WorldParameters { diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow15.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow15.vert new file mode 100644 index 000000000..0488440e1 --- /dev/null +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow15.vert @@ -0,0 +1,78 @@ +#import "Common/ShaderLib/Skinning.glsllib" +uniform mat4 m_LightViewProjectionMatrix0; +uniform mat4 m_LightViewProjectionMatrix1; +uniform mat4 m_LightViewProjectionMatrix2; +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; +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; +#endif + +#ifdef PSSM +out float shadowPosition; +#endif +out vec3 lightVec; + +out vec2 texCoord; + +in vec3 inPosition; + +#ifdef DISCARD_ALPHA + in vec2 inTexCoord; +#endif + +const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + + +void main(){ + vec4 modelSpacePos = vec4(inPosition, 1.0); + + #ifdef NUM_BONES + Skinning_Compute(modelSpacePos); + #endif + gl_Position = g_WorldViewProjectionMatrix * modelSpacePos; + + #ifndef POINTLIGHT + #ifdef PSSM + shadowPosition = gl_Position.z; + #endif + vec4 worldPos=vec4(0.0); + #endif + // get the vertex in world space + worldPos = g_WorldMatrix * modelSpacePos; + + #ifdef DISCARD_ALPHA + texCoord = inTexCoord; + #endif + // populate the light view matrices array and convert vertex to light viewProj space + projCoord0 = biasMat * m_LightViewProjectionMatrix0 * worldPos; + projCoord1 = biasMat * m_LightViewProjectionMatrix1 * worldPos; + projCoord2 = biasMat * m_LightViewProjectionMatrix2 * worldPos; + projCoord3 = biasMat * m_LightViewProjectionMatrix3 * worldPos; + #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; + #endif +} \ No newline at end of file diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.j3md b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.j3md index b3aa35ac9..8fd8b82f0 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.j3md +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.j3md @@ -43,8 +43,7 @@ MaterialDef Post Shadow { VertexShader GLSL150: Common/MatDefs/Shadow/PostShadowFilter15.vert FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadowFilter15.frag - WorldParameters { - WorldViewProjectionMatrix + WorldParameters { } Defines { @@ -65,8 +64,7 @@ MaterialDef Post Shadow { VertexShader GLSL100: Common/MatDefs/Shadow/PostShadowFilter.vert FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadowFilter.frag - WorldParameters { - WorldViewProjectionMatrix + WorldParameters { } Defines { diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.vert index 6d80905cd..8ddf7cfee 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.vert +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter.vert @@ -1,10 +1,9 @@ -uniform mat4 g_WorldViewProjectionMatrix; - attribute vec4 inPosition; attribute vec2 inTexCoord; varying vec2 texCoord; void main() { - gl_Position = inPosition * 2.0 - 1.0; //vec4(pos, 0.0, 1.0); + vec2 pos = inPosition.xy * 2.0 - 1.0; + gl_Position = vec4(pos, 0.0, 1.0); texCoord = inTexCoord; } \ No newline at end of file diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter15.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter15.vert index 367c3306b..2f09f4f29 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter15.vert +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadowFilter15.vert @@ -1,12 +1,10 @@ -uniform mat4 g_WorldViewProjectionMatrix; - in vec4 inPosition; in vec2 inTexCoord; out vec2 texCoord; void main() { - vec2 pos = (g_WorldViewProjectionMatrix * inPosition).xy; - gl_Position = vec4(pos, 0.0, 1.0); + vec2 pos = inPosition.xy * 2.0 - 1.0; + gl_Position = vec4(pos, 0.0, 1.0); texCoord = inTexCoord; } \ No newline at end of file