* Lighting shader now supports HW skinning

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10554 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..RD 12 years ago
parent d9e3af1795
commit b6afd61ef0
  1. 8
      engine/src/core-data/Common/MatDefs/Light/Lighting.j3md
  2. 25
      engine/src/core-data/Common/MatDefs/Light/Lighting.vert

@ -127,6 +127,10 @@ MaterialDef Phong Lighting {
Float PCFEdge Float PCFEdge
Float ShadowMapSize Float ShadowMapSize
// For hardware skinning
Int NumberOfBones
Matrix4Array BoneMatrices
} }
Technique { Technique {
@ -170,6 +174,8 @@ MaterialDef Phong Lighting {
USE_REFLECTION : EnvMap USE_REFLECTION : EnvMap
SPHERE_MAP : SphereMap SPHERE_MAP : SphereMap
NUM_BONES : NumberOfBones
} }
} }
@ -319,6 +325,8 @@ MaterialDef Phong Lighting {
NEED_TEXCOORD1 NEED_TEXCOORD1
HAS_GLOWMAP : GlowMap HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor HAS_GLOWCOLOR : GlowColor
NUM_BONES : NumberOfBones
} }
} }

@ -1,6 +1,8 @@
#define ATTENUATION #define ATTENUATION
//#define HQ_ATTENUATION //#define HQ_ATTENUATION
#import "Common/ShaderLib/Skinning.glsllib"
uniform mat4 g_WorldViewProjectionMatrix; uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldViewMatrix; uniform mat4 g_WorldViewMatrix;
uniform mat3 g_NormalMatrix; uniform mat3 g_NormalMatrix;
@ -68,8 +70,8 @@ varying vec3 lightVec;
* Output: * Output:
* varying refVec * varying refVec
*/ */
void computeRef(){ void computeRef(in vec4 modelSpacePos){
vec3 worldPos = (g_WorldMatrix * vec4(inPosition,1.0)).xyz; vec3 worldPos = (g_WorldMatrix * modelSpacePos).xyz;
vec3 I = normalize( g_CameraPosition - worldPos ).xyz; vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
vec3 N = normalize( (g_WorldMatrix * vec4(inNormal, 0.0)).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 #endif
void main(){ void main(){
vec4 pos = vec4(inPosition, 1.0); vec4 modelSpacePos = vec4(inPosition, 1.0);
gl_Position = g_WorldViewProjectionMatrix * pos; vec3 modelSpaceNorm = inNormal;
vec3 modelSpaceTan = inTangent.xyz;
#ifdef NUM_BONES
Skinning_Compute(modelSpacePos, modelSpaceNorm, modelSpaceTan);
#endif
gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
texCoord = inTexCoord; texCoord = inTexCoord;
#ifdef SEPARATE_TEXCOORD #ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2; texCoord2 = inTexCoord2;
#endif #endif
vec3 wvPosition = (g_WorldViewMatrix * pos).xyz; vec3 wvPosition = (g_WorldViewMatrix * modelSpacePos).xyz;
vec3 wvNormal = normalize(g_NormalMatrix * inNormal); vec3 wvNormal = normalize(g_NormalMatrix * modelSpaceNorm);
vec3 viewDir = normalize(-wvPosition); vec3 viewDir = normalize(-wvPosition);
//vec4 lightColor = g_LightColor[gl_InstanceID]; //vec4 lightColor = g_LightColor[gl_InstanceID];
@ -152,7 +161,7 @@ void main(){
vec4 lightColor = g_LightColor; vec4 lightColor = g_LightColor;
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz); vec3 wvTangent = normalize(g_NormalMatrix * modelSpaceTan);
vec3 wvBinormal = cross(wvNormal, wvTangent); vec3 wvBinormal = cross(wvNormal, wvTangent);
mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal); mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
@ -202,6 +211,6 @@ void main(){
#endif #endif
#ifdef USE_REFLECTION #ifdef USE_REFLECTION
computeRef(); computeRef(modelSpacePos);
#endif #endif
} }
Loading…
Cancel
Save