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

Revision 3116, 3.2 KB checked in by mattausch, 16 years ago (diff)

tree animation works somehow with flow vector

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;
12        float4 texCoord: TEXCOORD0;
[3038]13};
14
15// vtx output
16struct vtxout
17{
[3041]18        float4 position: POSITION;
[3038]19        float4 texCoord: TEXCOORD0;   
20
[3115]21        float4 color: COLOR0;
22        // eye position
23        float4 eyePos: TEXCOORD1;
[3046]24        float4 normal: TEXCOORD2;
[3115]25
26        float4 worldPos: TEXCOORD3;
27        float4 oldWorldPos: TEXCOORD4;
[3038]28};
29
30
[3045]31/** Vertex shader which conducts an simple tree animation
32        that bends the tree depending quadratically on the height
33*/
[3040]34vtxout animateVtx(vtxin IN,
35                                  uniform float3 windDir,
36                                  uniform float windStrength,
[3041]37                                  uniform float frequency,
38                                  uniform float2 minMaxPos,
[3045]39                                  uniform float timer,
40                                  uniform float3 lightDir)
[3038]41{
42        vtxout OUT;
[3040]43        OUT.texCoord = IN.texCoord;
[3041]44               
45        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y);
[3045]46        float factor = pos * pos * windStrength * sin(timer * frequency);
[3038]47
[3045]48        // transform the vertex position into post projection space
49        OUT.position = mul(glstate.matrix.mvp, IN.position);
50        // displace the input position
51        OUT.position += float4(factor * windDir, 0);
52
[3046]53        OUT.normal = normalize(mul(glstate.matrix.invtrans.modelview[0], IN.normal));
54        //const float3 l = normalize(mul(glstate.matrix.modelview[0], float4(lightDir, 0))).xyz;
55        const float3 l = normalize(lightDir);
[3045]56
[3115]57        const float diffuse = max(.0f, dot(OUT.normal.xyz, l));
[3045]58
[3046]59        //OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir)));
[3115]60        OUT.color = glstate.material.ambient + glstate.material.front.diffuse * diffuse;
[3046]61        OUT.color.w = IN.color.w;
[3045]62        return OUT;
63}
64
[3046]65/** vertex shader which provides an simple tree animation
66        that bends the tree depending quadratically on the height using vertex displacement.
[3045]67        This version of the shader is used for deferred shading and thus only
68        displaces the vertices and outputs the color, put does not do any shading.
69*/
70vtxout animateVtxMrt(vtxin IN,
71                                         uniform float3 windDir,
72                                         uniform float windStrength,
73                                         uniform float frequency,
74                                         uniform float2 minMaxPos,
[3115]75                                         uniform float timer,
76                                         uniform float oldTimer
77                                         //uniform float4x4 modelMatrix,
78                                         //uniform float4x4 oldModelMatrix
79                                         )
[3045]80{
81        vtxout OUT;
82
83        OUT.color = IN.color;
84        OUT.texCoord = IN.texCoord;
85               
86        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y);
[3116]87
[3044]88        float factor = pos * pos * windStrength * sin(timer * frequency);
[3115]89        const float4 offs = float4(factor * windDir, 0);
90
[3116]91        float oldFactor = pos * pos * windStrength * sin(oldTimer * frequency);
92        const float4 oldOffs = float4(oldFactor * windDir, 0);
93
[3040]94        // transform the vertex position into post projection space
95        OUT.position = mul(glstate.matrix.mvp, IN.position);
[3041]96        // displace the input position
[3115]97        OUT.position += offs;
[3038]98
[3041]99        // transform the vertex position into eye space
100        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
[3115]101        OUT.eyePos += offs;
[3041]102
[3045]103        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
104       
[3115]105        // hack: no translational component anyway
[3116]106        OUT.oldWorldPos = oldOffs;
[3115]107        OUT.worldPos = offs;
108
[3038]109        return OUT;
110}
Note: See TracBrowser for help on using the repository browser.