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

Revision 1493, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2void main_vp(
3      float4 position: POSITION,
4      float4 normal: NORMAL,
5      float2 texCoord : TEXCOORD0,
6
7      out float3 lightpos : TEXCOORD3,
8      out float3 eyePosition : TEXCOORD2,
9      out float4 oPosition: POSITION,
10      out float2 otexCoord : TEXCOORD0,
11      //out float3 otexPos : TEXCOORD1,
12      out float3 V : TEXCOORD1,
13      out float3 L : TEXCOORD4,
14      uniform float4 lightposition,             // world space
15      uniform float4 cameraposition,            // world space
16      uniform float3 camPosition : TEXCOORD2,   
17      uniform float3 lightposi : TEXCOORD3,
18      uniform float4x4 worldviewproj,
19      uniform float4x4 worldmatrix,
20      uniform float4x4 invworldmatrix,
21      uniform float4x4 viewmatrix,
22      uniform float4x4 projmatrix,
23      uniform float4x4 viewprojmatrix,
24      uniform float4x4 worldviewmatrix
25      )
26{
27        oPosition = mul(worldviewproj,position);
28        float4 pos = mul(worldviewmatrix,position);
29
30        //float4 campos = mul(viewmatrix,float4(camPosition,1.0));
31        float4 campos = mul(viewmatrix,cameraposition);
32        eyePosition = campos.xyz;
33       
34        float4 lightp = mul(viewmatrix,float4(lightposi,1.0));
35        //float4 lightp = mul(viewmatrix,lightposition);
36        lightpos = lightp.xyz;
37
38        V = -pos.xyz;
39        L = lightpos - pos.xyz;
40
41        otexCoord = texCoord;
42}
43*/
44/*
45void main_vp(
46      float4 position : POSITION,
47      float4 normal : NORMAL,
48      float2 texCoord : TEXCOORD0,
49      float2 texCoordNormalized : TEXCOORD1,
50
51      out float4 oPosition : POSITION,
52      out float2 otexCoord : TEXCOORD0,
53      out float2 otexCoordNormalized : TEXCOORD1,
54      uniform float4x4 worldviewproj
55      )
56{
57        oPosition = mul(worldviewproj,position);
58        otexCoord = texCoord;
59        otexCoordNormalized = texCoordNormalized;
60}
61*/
62
63
64
65
66struct VS_OUTPUT {
67   float4 Pos:       POSITION;
68   float3 normal:    TEXCOORD0;
69   float3 lightVec : TEXCOORD1;
70   float3 viewVec:   TEXCOORD2;
71   float4 shadowCrd: TEXCOORD3;
72   float2 texCoord:  TEXCOORD4;
73   float2 texCoordNormalized: TEXCOORD5;
74};
75
76void main_vp(
77      float4 position : POSITION,
78      float4 normal : NORMAL,
79      float2 texCoord : TEXCOORD0,
80      float2 texCoordNormalized : TEXCOORD1,
81
82      uniform float distanceScale,
83      uniform float4 lightPosition,
84      uniform float4 lightDirection,
85      uniform float4 camera_pos,
86      uniform float4x4 worldviewproj,
87      uniform float4x4 proj_matrix,
88      uniform float time_0_X,
89
90      out float4 opos:       POSITION,
91      out float3 onormal:    TEXCOORD0,
92      out float3 olightVec : TEXCOORD1,
93      out float3 oviewVec:   TEXCOORD2,
94      out float4 oshadowCrd: TEXCOORD3,
95      out float2 otexCoord:  TEXCOORD4,
96      out float2 otexCoordNormalized: TEXCOORD5
97      )
98{
99        opos = mul(worldviewproj, position);
100        // World-space lighting
101        onormal = normal;
102        //olightVec = distanceScale * (lightPosition - position.xyz);
103        olightVec = distanceScale * -lightDirection;
104        oviewVec = camera_pos - position.xyz;
105        otexCoord = texCoord;
106        otexCoordNormalized = texCoordNormalized;
107
108           // Create view vectors for the light, looking at (0,0,0)
109           // In real applications this work is better done on
110           // the CPU as it's constant for the whole scene.
111           //float3 dirZ = -normalize(lightPosition);
112           float3 dirZ = -normalize(lightDirection);
113           float3 up = float3(0.0,0.0,1.0);
114           float3 dirX = cross(up, dirZ);
115           float3 dirY = cross(dirZ, dirX);
116
117           // Transform into light's view space.
118           // In real applications we would be better off using a 4x4
119           // matrix instead, but for this shader it's cheaper to
120           // just transpose and rotate into light's view space.
121           float4 pos;
122           //position.xyz -= lightPosition;
123           position.xyz -= lightDirection;
124           pos.x = dot(dirX, position);
125           pos.y = dot(dirY, position);
126           pos.z = dot(dirZ, position);
127           pos.w = 1;
128
129           // Project it. For this sample using the normal projection
130           // matrix suffices, however, real applications will typically
131           // use a separate projection matrix for each light depending
132           // on its properties such as FOV and range.
133           float4 sPos = mul(proj_matrix, pos);
134
135           // Use projective texturing to map the position of each fragment
136           // to its corresponding texel in the shadow map.
137           sPos.z += 10;
138           oshadowCrd.x = 0.5 * (sPos.z + sPos.x);
139           oshadowCrd.y = 0.5 * (sPos.z - sPos.y);
140           oshadowCrd.z = 0;
141           oshadowCrd.w = sPos.z;
142}
Note: See TracBrowser for help on using the repository browser.