From c4fc9b723fad12a514b907edb186b48bc803e94c Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sat, 27 Apr 2013 16:32:37 +0000 Subject: [PATCH] Shadows, SSAO and CartoonEdge now works with HardWareSkinning git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10580 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../Common/MatDefs/Light/Lighting.j3md | 12 +- .../Common/MatDefs/Misc/Unshaded.j3md | 134 ++++++++++++++++-- .../Common/MatDefs/Shadow/PostShadow.vert | 10 +- .../Common/MatDefs/Shadow/PreShadow.vert | 10 +- .../Common/MatDefs/SSAO/normal.vert | 10 +- 5 files changed, 154 insertions(+), 22 deletions(-) diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md index 8bf63223f..ae9d7705c 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md @@ -192,6 +192,7 @@ MaterialDef Phong Lighting { Defines { COLOR_MAP : ColorMap DISCARD_ALPHA : AlphaDiscardThreshold + NUM_BONES : NumberOfBones } ForcedRenderState { @@ -218,12 +219,13 @@ MaterialDef Phong Lighting { HARDWARE_SHADOWS : HardwareShadows FILTER_MODE : FilterMode PCFEDGE : PCFEdge - DISCARD_ALPHA : AlphaDiscardThreshold + DISCARD_ALPHA : AlphaDiscardThreshold COLOR_MAP : ColorMap SHADOWMAP_SIZE : ShadowMapSize FADE : FadeInfo PSSM : Splits POINTLIGHT : LightViewProjectionMatrix5 + NUM_BONES : NumberOfBones } ForcedRenderState { @@ -246,12 +248,13 @@ MaterialDef Phong Lighting { HARDWARE_SHADOWS : HardwareShadows FILTER_MODE : FilterMode PCFEDGE : PCFEdge - DISCARD_ALPHA : AlphaDiscardThreshold + DISCARD_ALPHA : AlphaDiscardThreshold COLOR_MAP : ColorMap SHADOWMAP_SIZE : ShadowMapSize FADE : FadeInfo PSSM : Splits POINTLIGHT : LightViewProjectionMatrix5 + NUM_BONES : NumberOfBones } ForcedRenderState { @@ -274,10 +277,7 @@ MaterialDef Phong Lighting { Defines { DIFFUSEMAP_ALPHA : DiffuseMap - } - - RenderState { - + NUM_BONES : NumberOfBones } } diff --git a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md index 744bb6e4d..64248ca0c 100644 --- a/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md +++ b/engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md @@ -15,6 +15,35 @@ MaterialDef Unshaded { // For hardware skinning Int NumberOfBones Matrix4Array BoneMatrices + + //Shadows + Int FilterMode + Boolean HardwareShadows + + Texture2D ShadowMap0 + Texture2D ShadowMap1 + Texture2D ShadowMap2 + Texture2D ShadowMap3 + //pointLights + Texture2D ShadowMap4 + Texture2D ShadowMap5 + + Float ShadowIntensity + Vector4 Splits + Vector2 FadeInfo + + Matrix4 LightViewProjectionMatrix0 + Matrix4 LightViewProjectionMatrix1 + Matrix4 LightViewProjectionMatrix2 + Matrix4 LightViewProjectionMatrix3 + //pointLight + Matrix4 LightViewProjectionMatrix4 + Matrix4 LightViewProjectionMatrix5 + Vector3 LightPos + + Float PCFEdge + + Float ShadowMapSize } Technique { @@ -38,21 +67,106 @@ MaterialDef Unshaded { Technique { } - Technique PreNormalPass { + Technique PreNormalPass { + + VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert + FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag + + WorldParameters { + WorldViewProjectionMatrix + WorldViewMatrix + NormalMatrix + } + + Defines { + NUM_BONES : NumberOfBones + } + } + + Technique PreShadow { + + VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert + FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag + + WorldParameters { + WorldViewProjectionMatrix + WorldViewMatrix + } + + Defines { + COLOR_MAP : ColorMap + DISCARD_ALPHA : AlphaDiscardThreshold + NUM_BONES : NumberOfBones + } + + ForcedRenderState { + FaceCull Off + DepthTest On + DepthWrite On + PolyOffset 5 3 + ColorWrite Off + } + + } + - VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert - FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag + Technique PostShadow15{ + VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow.vert + FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag - WorldParameters { - WorldViewProjectionMatrix - WorldViewMatrix - NormalMatrix - } + WorldParameters { + WorldViewProjectionMatrix + WorldMatrix + } + + Defines { + HARDWARE_SHADOWS : HardwareShadows + FILTER_MODE : FilterMode + PCFEDGE : PCFEdge + DISCARD_ALPHA : AlphaDiscardThreshold + COLOR_MAP : ColorMap + SHADOWMAP_SIZE : ShadowMapSize + FADE : FadeInfo + PSSM : Splits + POINTLIGHT : LightViewProjectionMatrix5 + NUM_BONES : NumberOfBones + } - RenderState { - } + ForcedRenderState { + Blend Modulate + DepthWrite Off + PolyOffset -0.1 0 } + } + Technique PostShadow{ + VertexShader GLSL100: Common/MatDefs/Shadow/PostShadow.vert + FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadow.frag + + WorldParameters { + WorldViewProjectionMatrix + WorldMatrix + } + + Defines { + HARDWARE_SHADOWS : HardwareShadows + FILTER_MODE : FilterMode + PCFEDGE : PCFEdge + DISCARD_ALPHA : AlphaDiscardThreshold + COLOR_MAP : ColorMap + SHADOWMAP_SIZE : ShadowMapSize + FADE : FadeInfo + PSSM : Splits + POINTLIGHT : LightViewProjectionMatrix5 + NUM_BONES : NumberOfBones + } + + ForcedRenderState { + Blend Modulate + DepthWrite Off + PolyOffset -0.1 0 + } + } Technique Glow { diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert index f10f526c2..50c228d63 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert +++ b/engine/src/core-data/Common/MatDefs/Shadow/PostShadow.vert @@ -1,3 +1,4 @@ +#import "Common/ShaderLib/Skinning.glsllib" uniform mat4 m_LightViewProjectionMatrix0; uniform mat4 m_LightViewProjectionMatrix1; uniform mat4 m_LightViewProjectionMatrix2; @@ -41,7 +42,12 @@ const mat4 biasMat = mat4(0.5, 0.0, 0.0, 0.0, void main(){ - gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0); + vec4 modelSpacePos = vec4(inPosition, 1.0); + + #ifdef NUM_BONES + Skinning_Compute(modelSpacePos); + #endif + gl_Position = g_WorldViewProjectionMatrix * modelSpacePos; #ifndef POINTLIGHT #ifdef PSSM @@ -50,7 +56,7 @@ void main(){ vec4 worldPos=vec4(0.0); #endif // get the vertex in world space - worldPos = g_WorldMatrix * vec4(inPosition, 1.0); + worldPos = g_WorldMatrix * modelSpacePos; #ifdef DISCARD_ALPHA texCoord = inTexCoord; diff --git a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert index fdd3a2511..e57d45141 100644 --- a/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert +++ b/engine/src/core-data/Common/MatDefs/Shadow/PreShadow.vert @@ -1,4 +1,5 @@ -attribute vec4 inPosition; +#import "Common/ShaderLib/Skinning.glsllib" +attribute vec3 inPosition; attribute vec2 inTexCoord; uniform mat4 g_WorldViewProjectionMatrix; @@ -7,6 +8,11 @@ uniform mat4 g_WorldViewMatrix; varying vec2 texCoord; void main(){ - gl_Position = g_WorldViewProjectionMatrix * inPosition; + vec4 modelSpacePos = vec4(inPosition, 1.0); + + #ifdef NUM_BONES + Skinning_Compute(modelSpacePos); + #endif + gl_Position = g_WorldViewProjectionMatrix * modelSpacePos; texCoord = inTexCoord; } \ No newline at end of file diff --git a/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert b/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert index 24a76cb38..7eb36c40c 100644 --- a/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert +++ b/engine/src/core-effects/Common/MatDefs/SSAO/normal.vert @@ -1,3 +1,4 @@ +#import "Common/ShaderLib/Skinning.glsllib" uniform mat4 g_WorldViewProjectionMatrix; uniform mat3 g_NormalMatrix; @@ -11,6 +12,11 @@ varying vec2 texCoord; void main(void) { texCoord=inTexCoord.xy; - normal = normalize(g_NormalMatrix * inNormal); - gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition,1.0); + vec4 modelSpacePos = vec4(inPosition, 1.0); + vec3 modelSpaceNormals = inNormal; + #ifdef NUM_BONES + Skinning_Compute(modelSpacePos,modelSpaceNormals); + #endif + normal = normalize(g_NormalMatrix * modelSpaceNormals); + gl_Position = g_WorldViewProjectionMatrix * modelSpacePos; } \ No newline at end of file