struct VS_OUTPUT { float4 Pos: POSITION; float3 normal: TEXCOORD0; float4 lightVec : TEXCOORD1; float4 viewVec: TEXCOORD2; float4 shadowCrd: TEXCOORD3; float2 texCoord: TEXCOORD4; float2 texCoordNormalized: TEXCOORD5; float4 lightVecNM: TEXCOORD6; float3 halfvec: TEXCOORD7; }; float distanceScale; float4 lattenuation; float4 lightPosition; float4 lightDirection; float4 cameraPosition; float4x4 worldviewproj; float4x4 worldmatrix; float4x4 proj_matrix; float time_0_X; VS_OUTPUT main_vp( float4 position : POSITION, float3 normal : NORMAL, float2 texCoord : TEXCOORD0, float2 texCoordNormalized : TEXCOORD1, float3 inTangent : TEXCOORD2, float3 inBinormal : BINORMAL ) { VS_OUTPUT Out; Out.Pos = mul(worldviewproj, position); //------------------------------------------------------------ // World-space lighting //------------------------------------------------------------ // world_pos,lightPosition, float world_pos = mul(worldmatrix,position); Out.normal = normal; Out.lightVec = lightPosition - world_pos; // Used for shadow mapping float dist = length(Out.lightVec.xyz); Out.lightVecNM.xyz = -Out.lightVec.xyz / dist; // For shadow mapping we were using distanceScale Out.lightVecNM.w = clamp(0.0,1.0,1.0 / (lattenuation.x + lattenuation.y * dist + lattenuation.z * dist * dist) ); // Debugging purpose... normal = mul(worldmatrix,normal); inTangent = mul(worldmatrix,inTangent); inBinormal = mul(worldmatrix,inBinormal); float3x3 tangentSpace; // In Ogre3D the TAG BINORMAL and TANGENT are not used... tangentSpace[0] = inTangent; tangentSpace[1] = cross(inTangent,normal.xyz); tangentSpace[2] = normal.xyz; Out.viewVec = normalize(cameraPosition - world_pos); // Converted to Tangent-space Out.halfvec = mul(tangentSpace,normalize(Out.lightVecNM.xyz+Out.viewVec.xyz)); Out.lightVecNM = float4(mul(tangentSpace,Out.lightVecNM.xyz),Out.lightVecNM.w); Out.texCoord = texCoord; Out.texCoordNormalized = texCoordNormalized; //------------------------------------------------------------ // Light-space coordinates //------------------------------------------------------------ float4 sPos = mul(proj_matrix, position); //float4 sPos = mul(position,proj_matrix); sPos.z += 10; //Out.shadowCrd.x = 0.5 * (sPos.z + sPos.x); //Out.shadowCrd.y = 0.5 * (sPos.z - sPos.y); //Out.shadowCrd.z = 0; //Out.shadowCrd.w = sPos.z; //Out.shadowCrd.x = sPos.x; //Out.shadowCrd.y = 1.0 - sPos.y; //Out.shadowCrd.z = 0.0; //Out.shadowCrd.w = sPos.z; Out.shadowCrd.x = sPos.x; Out.shadowCrd.y = 1.0 - sPos.y; Out.shadowCrd.z = 0.0; Out.shadowCrd.w = sPos.z; return Out; }