From b6afd61ef07efe65cc8eda721d9d49ad9dd090ac Mon Sep 17 00:00:00 2001 From: "sha..RD" Date: Thu, 18 Apr 2013 03:03:55 +0000 Subject: [PATCH] * Lighting shader now supports HW skinning git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10554 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../Common/MatDefs/Light/Lighting.j3md | 10 +++++++- .../Common/MatDefs/Light/Lighting.vert | 25 +++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md index b4a8e6c53..8bf63223f 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md @@ -127,6 +127,10 @@ MaterialDef Phong Lighting { Float PCFEdge Float ShadowMapSize + + // For hardware skinning + Int NumberOfBones + Matrix4Array BoneMatrices } Technique { @@ -169,7 +173,9 @@ MaterialDef Phong Lighting { SEPARATE_TEXCOORD : SeparateTexCoord USE_REFLECTION : EnvMap - SPHERE_MAP : SphereMap + SPHERE_MAP : SphereMap + + NUM_BONES : NumberOfBones } } @@ -319,6 +325,8 @@ MaterialDef Phong Lighting { NEED_TEXCOORD1 HAS_GLOWMAP : GlowMap HAS_GLOWCOLOR : GlowColor + + NUM_BONES : NumberOfBones } } diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert index 042cba9bf..f9a303631 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.vert +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.vert @@ -1,6 +1,8 @@ #define ATTENUATION //#define HQ_ATTENUATION +#import "Common/ShaderLib/Skinning.glsllib" + uniform mat4 g_WorldViewProjectionMatrix; uniform mat4 g_WorldViewMatrix; uniform mat3 g_NormalMatrix; @@ -68,8 +70,8 @@ varying vec3 lightVec; * Output: * varying refVec */ - void computeRef(){ - vec3 worldPos = (g_WorldMatrix * vec4(inPosition,1.0)).xyz; + void computeRef(in vec4 modelSpacePos){ + vec3 worldPos = (g_WorldMatrix * modelSpacePos).xyz; vec3 I = normalize( g_CameraPosition - worldPos ).xyz; vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).xyz ); @@ -131,15 +133,22 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 w #endif void main(){ - vec4 pos = vec4(inPosition, 1.0); - gl_Position = g_WorldViewProjectionMatrix * pos; + vec4 modelSpacePos = vec4(inPosition, 1.0); + vec3 modelSpaceNorm = inNormal; + vec3 modelSpaceTan = inTangent.xyz; + + #ifdef NUM_BONES + Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan); + #endif + + gl_Position = g_WorldViewProjectionMatrix * modelSpacePos; texCoord = inTexCoord; #ifdef SEPARATE_TEXCOORD texCoord2 = inTexCoord2; #endif - vec3 wvPosition = (g_WorldViewMatrix * pos).xyz; - vec3 wvNormal = normalize(g_NormalMatrix * inNormal); + vec3 wvPosition = (g_WorldViewMatrix * modelSpacePos).xyz; + vec3 wvNormal = normalize(g_NormalMatrix * modelSpaceNorm); vec3 viewDir = normalize(-wvPosition); //vec4 lightColor = g_LightColor[gl_InstanceID]; @@ -152,7 +161,7 @@ void main(){ vec4 lightColor = g_LightColor; #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) - vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz); + vec3 wvTangent = normalize(g_NormalMatrix * modelSpaceTan); vec3 wvBinormal = cross(wvNormal, wvTangent); mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal); @@ -202,6 +211,6 @@ void main(){ #endif #ifdef USE_REFLECTION - computeRef(); + computeRef(modelSpacePos); #endif } \ No newline at end of file