source: GTP/trunk/App/Demos/Illum/Rain/rainMaterials/gouttesTexCoordsVP.cg @ 2221

Revision 2221, 4.6 KB checked in by plemenos, 18 years ago (diff)
  • Property svn:executable set to *
Line 
1
2///////////////////////////////////////////////////////////////////////////
3//
4//              vertex program used to render the particles.
5//              sets the particle position reading from the position texture
6//              and stretches the particle onscreen.
7//
8///////////////////////////////////////////////////////////////////////////
9
10
11
12struct entree
13{
14        float4 position : POSITION;
15        float4 texCoords0 : TEXCOORD0;
16};
17
18struct sortie
19{
20        float4 position    : POSITION;
21        float2 texCoords0  : TEXCOORD0;
22        float2 texCoords1  : TEXCOORD1;
23        float4 posworld    : TEXCOORD2;
24        float4 normale     : TEXCOORD3;
25        float3 eyetovert   : TEXCOORD4;
26};
27
28
29
30#define SCREEN_RATIO            (1280.0/1024.0)
31
32sortie mainNoStreaks(entree IN,
33                     uniform float3 viewPos,
34                     uniform float3 viewDir,
35                     uniform float3 boxMin,
36                     uniform float3 boxMax,
37                     uniform float rainBbSide,
38                     uniform float4x4  worldviewproj,
39                     uniform float4x4  worldview,
40                     uniform sampler2D texPos : TEXUNIT1)
41{
42        sortie OUT;
43       
44        //we get the position of the vertex from the texture
45       
46        float4 posFromTexture = tex2D(texPos, IN.texCoords0.zw);
47       
48        float4 thePos;
49        thePos.x = viewPos.x + posFromTexture.x * (boxMax.x - boxMin.x) + boxMin.x - viewDir.x * ((boxMax.x - boxMin.x) / 2.0);
50        thePos.y = viewPos.y + posFromTexture.y * (boxMax.y - boxMin.y) + boxMin.y;
51        thePos.z = viewPos.z + posFromTexture.z * (boxMax.z - boxMin.z) + boxMin.z - viewDir.z * ((boxMax.z - boxMin.z) / 2.0);
52        thePos.w = 1.0;
53       
54        // USE FOLLOWING LINE TO AVOID READING POSITION FROM TEXTURE
55        //float4 thePos = IN.position + 0.000000001 * (viewPos.x + boxMax.x + boxMin.x + viewDir.x);
56       
57        // transform it to screen space
58        OUT.position = mul(worldviewproj, thePos);
59       
60        // shape it as a quad (oriented on camera plane)
61        OUT.position.x += rainBbSide * (IN.texCoords0.x - 0.5f);
62        OUT.position.y -= rainBbSide * SCREEN_RATIO * (IN.texCoords0.y - 0.5f);
63
64
65        // don't change the fist texture coordinates
66        OUT.texCoords0 = IN.texCoords0.xy;
67       
68        // second texture coordinates receive the position of the drop, in screen space
69        float4 VposEye = mul(worldviewproj, thePos);
70        VposEye.xyz /= VposEye.w;       
71    OUT.texCoords1 = (1.0 + VposEye.xy).xy / 2.0;
72        OUT.texCoords1.y = 1.0 - OUT.texCoords1.y;
73       
74        OUT.normale.x = (IN.texCoords0.x - 0.5) * 2.0;
75    OUT.normale.y = -(IN.texCoords0.y - 0.5) * 2.0;
76        OUT.normale.zw = 1.0;
77       
78        OUT.posworld = thePos; // unprojected vertex coordinate
79        OUT.eyetovert = mul(worldview, thePos).xyz;
80       
81        return OUT;
82}
83
84
85
86
87
88
89sortie mainStreaks(entree IN,
90                   uniform float3 viewPos,
91                   uniform float3 viewDir,
92                   uniform float3 boxMin,
93                   uniform float3 boxMax,
94                   uniform float3 fallVect,
95                   uniform float rainBbSide,
96                   uniform float streaksHeight,
97                   uniform float4x4  worldviewproj,
98                   uniform float4x4  worldview,
99                   uniform sampler2D texPos : TEXUNIT1)
100{
101        sortie OUT;
102       
103         
104        //we get the position of the vertex from the texture
105        float4 posFromTexture = tex2D(texPos, IN.texCoords0.zw);
106        float4 thePos;
107        thePos.x = viewPos.x + posFromTexture.x * (boxMax.x - boxMin.x) + boxMin.x - viewDir.x * ((boxMax.x - boxMin.x) / 2.0);
108        thePos.y = viewPos.y + posFromTexture.y * (boxMax.y - boxMin.y) + boxMin.y;
109        thePos.z = viewPos.z + posFromTexture.z * (boxMax.z - boxMin.z) + boxMin.z - viewDir.z * ((boxMax.z - boxMin.z) / 2.0);
110        thePos.w = 1.0;
111       
112        // USE FOLLOWING LINE TO AVOID READING POSITION FROM TEXTURE
113        //float4 thePos = IN.position + 0.000000001 * (viewPos.x + boxMax.x + boxMin.x + viewDir.x);
114       
115// stetch the streak vertically
116        thePos.y += (1.0 - IN.texCoords0.y) * streaksHeight;
117// make it follow the wind direction
118        thePos.xz += (IN.texCoords0.y * 2.0 - 1.0) * fallVect.xz;
119// transform its coordinate to screen space
120        OUT.position = mul(worldviewproj, thePos);
121       
122        // shape it as a quad (oriented on camera plane)
123        OUT.position.x += rainBbSide * (IN.texCoords0.x - 0.5f);
124
125
126// don't change the first texture coordinates
127        OUT.texCoords0 = IN.texCoords0.xy;
128       
129        float4 VposEye = OUT.position;
130        VposEye.xyz /= VposEye.w;
131        OUT.texCoords1 = (1.0 + VposEye.xy).xy / 2.0;
132        OUT.texCoords1.y = 1.0 - OUT.texCoords1.y;
133       
134        OUT.normale.x = (IN.texCoords0.x - 0.5) * 2.0;
135        OUT.normale.y = -(IN.texCoords0.y - 0.5) * 2.0;
136        OUT.normale.zw = 1.0;
137       
138        OUT.posworld = thePos;
139        OUT.eyetovert = mul(worldview, thePos).xyz;
140       
141        return OUT;
142}
Note: See TracBrowser for help on using the repository browser.