source: GTP/trunk/App/Demos/Illum/IBRBillboardCloudTrees/OGRE/IBRTreesOGRE/media/oldgeneral/tree_idtexturing_spotlight_vp.shd.bak @ 1493

Revision 1493, 2.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1struct 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
13float distanceScale;
14float4 lattenuation;
15float4 lightPosition;
16float4 lightDirection;
17float4 cameraPosition;
18float4x4 worldviewproj;
19float4x4 worldmatrix;
20float4x4 proj_matrix;
21float time_0_X;
22
23VS_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}
Note: See TracBrowser for help on using the repository browser.