1 | struct VS_OUTPUT {
|
---|
2 | float4 Pos: POSITION;
|
---|
3 | float3 normal: TEXCOORD0;
|
---|
4 | float4 lightVec : TEXCOORD1;
|
---|
5 | float3 halfvec: TEXCOORD2;
|
---|
6 | float4 shadowCrd: TEXCOORD3;
|
---|
7 | float2 texCoord: TEXCOORD4;
|
---|
8 | float2 texCoordNormalized: TEXCOORD5;
|
---|
9 | float4 lightVecNM: TEXCOORD6;
|
---|
10 | float backside: TEXCOORD7;
|
---|
11 | };
|
---|
12 |
|
---|
13 | float distanceScale;
|
---|
14 | float4 lattenuation;
|
---|
15 | float4 lightPosition;
|
---|
16 | float4 lightDirection;
|
---|
17 | float4 cameraPosition;
|
---|
18 | float4 cameraDirection;
|
---|
19 | float4x4 worldviewproj;
|
---|
20 | float4x4 worldmatrix;
|
---|
21 | float4x4 proj_matrix;
|
---|
22 | float time_0_X;
|
---|
23 |
|
---|
24 | VS_OUTPUT main_vp(
|
---|
25 | float4 position : POSITION,
|
---|
26 | float3 normal : NORMAL,
|
---|
27 | float2 texCoord : TEXCOORD0,
|
---|
28 | float2 texCoordNormalized : TEXCOORD1,
|
---|
29 | float3 inTangent : TEXCOORD2,
|
---|
30 | float3 inBinormal : BINORMAL
|
---|
31 | )
|
---|
32 | {
|
---|
33 |
|
---|
34 | VS_OUTPUT Out;
|
---|
35 |
|
---|
36 | Out.Pos = mul(worldviewproj, position);
|
---|
37 | float4 world_pos = mul(worldmatrix,position);
|
---|
38 | Out.backside = 0.0;
|
---|
39 |
|
---|
40 | // Thats why we compute the backside before converting
|
---|
41 | // the normal to world-space coordinates...
|
---|
42 | // cameraDirection is expressed in object space
|
---|
43 | if (dot(normal,cameraDirection) < 0.0)
|
---|
44 | {
|
---|
45 | Out.backside = 1.0;
|
---|
46 | }
|
---|
47 | cameraDirection = mul(worldmatrix,cameraDirection);
|
---|
48 | normal = mul(worldmatrix,normal);
|
---|
49 | Out.normal = normal;
|
---|
50 | //Out.lightVec = lightPosition - world_pos;
|
---|
51 | Out.lightVec = lightDirection;
|
---|
52 | float dist = length(Out.lightVec.xyz);
|
---|
53 | Out.lightVecNM.xyz = -Out.lightVec.xyz / dist; // For shadow mapping we were using distanceScale
|
---|
54 | Out.lightVecNM.w = clamp(0.0,1.0,1.0 / (lattenuation.x + lattenuation.y * dist + lattenuation.z * dist * dist) );
|
---|
55 | normal = mul(worldmatrix,normal);
|
---|
56 | inTangent = mul(worldmatrix,inTangent);
|
---|
57 | inBinormal = mul(worldmatrix,inBinormal);
|
---|
58 | float3x3 tangentSpace;
|
---|
59 | tangentSpace[0] = inTangent;
|
---|
60 | tangentSpace[1] = cross(inTangent,normal.xyz);
|
---|
61 | tangentSpace[2] = normal.xyz;
|
---|
62 | float4 oviewVec = normalize(cameraPosition - world_pos);
|
---|
63 | Out.halfvec = mul(tangentSpace,normalize(Out.lightVecNM.xyz+oviewVec.xyz));
|
---|
64 | Out.lightVecNM = oviewVec;
|
---|
65 | Out.texCoord = texCoord;
|
---|
66 | Out.texCoordNormalized = texCoordNormalized;
|
---|
67 | Out.shadowCrd = mul(proj_matrix, position);
|
---|
68 |
|
---|
69 | return Out;
|
---|
70 | } |
---|