source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg @ 3046

Revision 3046, 2.9 KB checked in by mattausch, 16 years ago (diff)

added shader for forward shadin tree animation program

Line 
1/***********************************************/
2/*     Vertex shaders for tree animation       */
3/***********************************************/
4
5
6struct vtxin
7{
8        float4 position: POSITION;
9        float4 normal: NORMAL;
10       
11        float4 color: COLOR;
12        //float4 color1: COLOR1;
13
14        float4 texCoord: TEXCOORD0;
15};
16
17// vtx output
18struct vtxout
19{
20        float4 position: POSITION;
21        float4 texCoord: TEXCOORD0;   
22
23        float4 color: COLOR0; 
24        //float4 color1: COLOR1; 
25        float4 eyePos: TEXCOORD1; // eye position
26        float4 normal: TEXCOORD2;
27};
28
29
30/** Vertex shader which conducts an simple tree animation
31        that bends the tree depending quadratically on the height
32*/
33vtxout animateVtx(vtxin IN,
34                                  uniform float3 windDir,
35                                  uniform float windStrength,
36                                  uniform float frequency,
37                                  uniform float2 minMaxPos,
38                                  uniform float timer,
39                                  uniform float3 lightDir)
40{
41        vtxout OUT;
42        OUT.texCoord = IN.texCoord;
43               
44        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y);
45        float factor = pos * pos * windStrength * sin(timer * frequency);
46
47        // transform the vertex position into post projection space
48        OUT.position = mul(glstate.matrix.mvp, IN.position);
49        // displace the input position
50        OUT.position += float4(factor * windDir, 0);
51
52        OUT.normal = normalize(mul(glstate.matrix.invtrans.modelview[0], IN.normal));
53        //const float3 l = normalize(mul(glstate.matrix.modelview[0], float4(lightDir, 0))).xyz;
54        const float3 l = normalize(lightDir);
55
56        const float dif = max(.0f, dot(OUT.normal.xyz, l));
57
58        //OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir)));
59        OUT.color = glstate.material.ambient + glstate.material.front.diffuse * dif;
60        OUT.color.w = IN.color.w;
61        return OUT;
62}
63
64/** vertex shader which provides an simple tree animation
65        that bends the tree depending quadratically on the height using vertex displacement.
66        This version of the shader is used for deferred shading and thus only
67        displaces the vertices and outputs the color, put does not do any shading.
68*/
69vtxout animateVtxMrt(vtxin IN,
70                                         uniform float3 windDir,
71                                         uniform float windStrength,
72                                         uniform float frequency,
73                                         uniform float2 minMaxPos,
74                                         uniform float timer)
75{
76        vtxout OUT;
77
78        OUT.color = IN.color;
79        OUT.texCoord = IN.texCoord;
80               
81        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y);
82        float factor = pos * pos * windStrength * sin(timer * frequency);
83
84        // transform the vertex position into post projection space
85        OUT.position = mul(glstate.matrix.mvp, IN.position);
86        // displace the input position
87        OUT.position += float4(factor * windDir, 0);
88
89        // transform the vertex position into eye space
90        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
91        OUT.eyePos += float4(factor * windDir, 0);
92
93        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
94       
95        return OUT;
96}
Note: See TracBrowser for help on using the repository browser.