1 | struct VS_OUTPUT {
|
---|
2 | float4 Pos: POSITION;
|
---|
3 | float3 normal: TEXCOORD0;
|
---|
4 | float4 lightVec : TEXCOORD1;
|
---|
5 | float4 viewVec: TEXCOORD2;
|
---|
6 | float4 shadowCrd: TEXCOORD3;
|
---|
7 | float2 texCoord: TEXCOORD4;
|
---|
8 | float2 texCoordNormalized: TEXCOORD5;
|
---|
9 | float4 lightVecNM: TEXCOORD6;
|
---|
10 | float3 halfvec: TEXCOORD7;
|
---|
11 | };
|
---|
12 |
|
---|
13 | float distanceScale;
|
---|
14 | float4 lattenuation;
|
---|
15 | float4 lightPosition;
|
---|
16 | float4 lightDirection;
|
---|
17 | float4 cameraPosition;
|
---|
18 | float4x4 worldviewproj;
|
---|
19 | float4x4 worldmatrix;
|
---|
20 | float4x4 proj_matrix;
|
---|
21 | float time_0_X;
|
---|
22 |
|
---|
23 | VS_OUTPUT main_vp(
|
---|
24 | float4 position : POSITION,
|
---|
25 | float3 normal : NORMAL,
|
---|
26 | float2 texCoord : TEXCOORD0,
|
---|
27 | float2 texCoordNormalized : TEXCOORD1,
|
---|
28 | float3 inTangent : TEXCOORD2,
|
---|
29 | float3 inBinormal : BINORMAL
|
---|
30 | )
|
---|
31 | {
|
---|
32 |
|
---|
33 | VS_OUTPUT Out;
|
---|
34 |
|
---|
35 | Out.Pos = mul(worldviewproj, position);
|
---|
36 |
|
---|
37 | //------------------------------------------------------------
|
---|
38 | // World-space lighting
|
---|
39 | //------------------------------------------------------------
|
---|
40 | // world_pos,lightPosition,
|
---|
41 | float world_pos = mul(worldmatrix,position);
|
---|
42 | Out.normal = normal;
|
---|
43 | Out.lightVec = lightPosition - world_pos; // Used for shadow mapping
|
---|
44 | float dist = length(Out.lightVec.xyz);
|
---|
45 | Out.lightVecNM.xyz = -Out.lightVec.xyz / dist; // For shadow mapping we were using distanceScale
|
---|
46 | Out.lightVecNM.w = clamp(0.0,1.0,1.0 / (lattenuation.x + lattenuation.y * dist + lattenuation.z * dist * dist) );
|
---|
47 |
|
---|
48 | // Debugging purpose...
|
---|
49 | normal = mul(worldmatrix,normal);
|
---|
50 | inTangent = mul(worldmatrix,inTangent);
|
---|
51 | inBinormal = mul(worldmatrix,inBinormal);
|
---|
52 |
|
---|
53 | float3x3 tangentSpace;
|
---|
54 | // In Ogre3D the TAG BINORMAL and TANGENT are not used...
|
---|
55 | tangentSpace[0] = inTangent;
|
---|
56 | tangentSpace[1] = cross(inTangent,normal.xyz);
|
---|
57 | tangentSpace[2] = normal.xyz;
|
---|
58 |
|
---|
59 | Out.viewVec = normalize(cameraPosition - world_pos);
|
---|
60 |
|
---|
61 | // Converted to Tangent-space
|
---|
62 | Out.halfvec = mul(tangentSpace,normalize(Out.lightVecNM.xyz+Out.viewVec.xyz));
|
---|
63 | Out.lightVecNM = float4(mul(tangentSpace,Out.lightVecNM.xyz),Out.lightVecNM.w);
|
---|
64 |
|
---|
65 | Out.texCoord = texCoord;
|
---|
66 | Out.texCoordNormalized = texCoordNormalized;
|
---|
67 |
|
---|
68 | //------------------------------------------------------------
|
---|
69 | // Light-space coordinates
|
---|
70 | //------------------------------------------------------------
|
---|
71 | float4 sPos = mul(proj_matrix, position);
|
---|
72 | //float4 sPos = mul(position,proj_matrix);
|
---|
73 | sPos.z += 10;
|
---|
74 | //Out.shadowCrd.x = 0.5 * (sPos.z + sPos.x);
|
---|
75 | //Out.shadowCrd.y = 0.5 * (sPos.z - sPos.y);
|
---|
76 | //Out.shadowCrd.z = 0;
|
---|
77 | //Out.shadowCrd.w = sPos.z;
|
---|
78 |
|
---|
79 | //Out.shadowCrd.x = sPos.x;
|
---|
80 | //Out.shadowCrd.y = 1.0 - sPos.y;
|
---|
81 | //Out.shadowCrd.z = 0.0;
|
---|
82 | //Out.shadowCrd.w = sPos.z;
|
---|
83 |
|
---|
84 | Out.shadowCrd.x = sPos.x;
|
---|
85 | Out.shadowCrd.y = 1.0 - sPos.y;
|
---|
86 | Out.shadowCrd.z = 0.0;
|
---|
87 | Out.shadowCrd.w = sPos.z;
|
---|
88 |
|
---|
89 | return Out;
|
---|
90 | } |
---|