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

RevLine 
[3045]1/***********************************************/
2/*     Vertex shaders for tree animation       */
3/***********************************************/
[3038]4
5
[3040]6struct vtxin
[3038]7{
8        float4 position: POSITION;
[3045]9        float4 normal: NORMAL;
10       
[3041]11        float4 color: COLOR;
[3045]12        //float4 color1: COLOR1;
13
[3041]14        float4 texCoord: TEXCOORD0;
[3038]15};
16
17// vtx output
18struct vtxout
19{
[3041]20        float4 position: POSITION;
[3038]21        float4 texCoord: TEXCOORD0;   
22
23        float4 color: COLOR0; 
[3045]24        //float4 color1: COLOR1; 
[3041]25        float4 eyePos: TEXCOORD1; // eye position
[3046]26        float4 normal: TEXCOORD2;
[3038]27};
28
29
[3045]30/** Vertex shader which conducts an simple tree animation
31        that bends the tree depending quadratically on the height
32*/
[3040]33vtxout animateVtx(vtxin IN,
34                                  uniform float3 windDir,
35                                  uniform float windStrength,
[3041]36                                  uniform float frequency,
37                                  uniform float2 minMaxPos,
[3045]38                                  uniform float timer,
39                                  uniform float3 lightDir)
[3038]40{
41        vtxout OUT;
[3040]42        OUT.texCoord = IN.texCoord;
[3041]43               
44        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y);
[3045]45        float factor = pos * pos * windStrength * sin(timer * frequency);
[3038]46
[3045]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
[3046]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);
[3045]55
[3046]56        const float dif = max(.0f, dot(OUT.normal.xyz, l));
[3045]57
[3046]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;
[3045]61        return OUT;
62}
63
[3046]64/** vertex shader which provides an simple tree animation
65        that bends the tree depending quadratically on the height using vertex displacement.
[3045]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);
[3044]82        float factor = pos * pos * windStrength * sin(timer * frequency);
[3038]83
[3040]84        // transform the vertex position into post projection space
85        OUT.position = mul(glstate.matrix.mvp, IN.position);
[3041]86        // displace the input position
87        OUT.position += float4(factor * windDir, 0);
[3038]88
[3041]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
[3045]93        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
94       
[3038]95        return OUT;
96}
Note: See TracBrowser for help on using the repository browser.