source: GTP/trunk/App/Demos/Illum/IBRBillboardCloudTrees/OGRE/IBRTreesOGRE/media/oldgeneral/ground_vp.txt @ 1493

Revision 1493, 2.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1float4x4 viewProjectionMatrix: register(c0);
2float4 lightPosition: register(c4);
3float4 view_position: register(c5);
4float4x4 proj_matrix: register(c6);
5float distanceScale: register(c10);
6float time_0_X: register(c11);
7float3 lookAt;
8float factor;
9
10struct VS_OUTPUT {
11   float4 Pos:       POSITION;
12   float3 normal:    TEXCOORD0;
13   float3 lightVec:  TEXCOORD1;
14   float3 viewVec:   TEXCOORD2;
15   float4 shadowCrd: TEXCOORD3;
16   float3 texCoord: TEXCOORD4;
17};
18
19VS_OUTPUT main(float4 Pos: POSITION, float3 normal: NORMAL, float3 texCoord: TEXCOORD0){
20   VS_OUTPUT Out;
21
22   // Animate the light position.
23   // Comment out this code to use a static light.
24   // In real applications this work is better done on
25   // the CPU as it's constant for the whole scene.
26   float3 lightPosition;
27   lightPosition.x = cos(1.321 * time_0_X);
28   lightPosition.z = sin(0.923 * time_0_X);
29   lightPosition.xz = 100 * normalize(lightPosition.xz);
30   lightPosition.y = 100;
31
32   // Flip, scale and translate our model to suit our scene
33   // In real applications, this work should normally be
34   // done at load time, alternatively if animation is desired,
35   // be altered by a world matrix.
36   normal = normal.xyz;
37
38   Out.Pos = mul(viewProjectionMatrix, Pos); 
39   // World-space lighting
40   Out.normal = normal;
41   Out.lightVec = distanceScale * (lightPosition - Pos.xyz);
42   Out.viewVec = view_position - Pos.xyz;
43   Out.texCoord = texCoord;
44
45   // Create view vectors for the light, looking at (0,0,0)
46   // In real applications this work is better done on
47   // the CPU as it's constant for the whole scene.
48   float3 dirZ = -normalize(lightPosition);
49   float3 up = float3(0.0,0.0,1.0);
50   float3 dirX = cross(up, dirZ);
51   float3 dirY = cross(dirZ, dirX);
52
53   // Transform into light's view space.
54   // In real applications we would be better off using a 4x4
55   // matrix instead, but for this shader it's cheaper to
56   // just transpose and rotate into light's view space.
57   float4 pos;
58   Pos.xyz -= lightPosition;
59   pos.x = dot(dirX, Pos);
60   pos.y = dot(dirY, Pos);
61   pos.z = dot(dirZ, Pos);
62   pos.w = 1;
63
64   // Project it. For this sample using the normal projection
65   // matrix suffices, however, real applications will typically
66   // use a separate projection matrix for each light depending
67   // on its properties such as FOV and range.
68   float4 sPos = mul(proj_matrix, pos);
69
70   // Use projective texturing to map the position of each fragment
71   // to its corresponding texel in the shadow map.
72   sPos.z += 10;
73   Out.shadowCrd.x = 0.5 * (sPos.z + sPos.x);
74   Out.shadowCrd.y = 0.5 * (sPos.z - sPos.y);
75   Out.shadowCrd.z = 0;
76   Out.shadowCrd.w = sPos.z;
77
78   return Out;
79}
80
81
Note: See TracBrowser for help on using the repository browser.