Ignore:
Timestamp:
10/19/08 23:42:15 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg

    r3044 r3045  
    1 //-------------------------------------------------------------------------------------- 
    2 // Input and Output structs 
    3 //-------------------------------------------------------------------------------------- 
     1/***********************************************/ 
     2/*     Vertex shaders for tree animation       */ 
     3/***********************************************/ 
    44 
    55 
     
    77{ 
    88        float4 position: POSITION; 
    9         float3 normal: NORMAL; 
     9        float4 normal: NORMAL; 
     10         
    1011        float4 color: COLOR; 
     12        //float4 color1: COLOR1; 
     13 
    1114        float4 texCoord: TEXCOORD0; 
    1215}; 
     
    1922 
    2023        float4 color: COLOR0;   
     24        //float4 color1: COLOR1;   
    2125        float4 eyePos: TEXCOORD1; // eye position 
    2226        float3 normal: TEXCOORD2; 
     
    2428 
    2529 
    26 //-------------------------------------------------------------------------------------- 
    27 // Vertex Shaders 
    28 //-------------------------------------------------------------------------------------- 
    29  
    30  
     30/** Vertex shader which conducts an simple tree animation 
     31        that bends the tree depending quadratically on the height 
     32*/ 
    3133vtxout animateVtx(vtxin IN, 
    3234                                  uniform float3 windDir, 
     
    3436                                  uniform float frequency, 
    3537                                  uniform float2 minMaxPos, 
    36                                   uniform float timer) 
     38                                  uniform float timer, 
     39                                  uniform float3 lightDir) 
    3740{ 
    3841        vtxout OUT; 
    3942 
    40         OUT.color = float4(0);//IN.color; 
     43/* 
     44// Transform vertex position into homogenous clip-space. 
     45OUT.HPosition = mul(ModelViewProj, IN.Position); 
     46// Transform normal from model-space to view-space. 
     47float3 normalVec = normalize(mul(ModelViewIT, 
     48IN.Normal).xyz); 
     49// Store normalized light vector. 
     50float3 lightVec = normalize(LightVec.xyz); 
     51// Calculate half angle vector. 
     52float3 eyeVec = float3(0.0, 0.0, 1.0); 
     53float3 halfVec = normalize(lightVec + eyeVec); 
     54// Calculate diffuse component. 
     55float diffuse = dot(normalVec, lightVec); 
     56// Calculate specular component. 
     57float specular = dot(normalVec, halfVec); 
     58// Use the lit function to compute lighting vector from 
     59// diffuse and specular values. 
     60float4 lighting = lit(diffuse, specular, 32); 
     61// Blue diffuse material 
     62float3 diffuseMaterial = float3(0.0, 0.0, 1.0); 
     63// White specular material 
     64float3 specularMaterial = float3(1.0, 1.0, 1.0); 
     65// Combine diffuse and specular contributions and 
     66// output final vertex color. 
     67OUT.Color.rgb = lighting.y * diffuseMaterial + 
     68lighting.z * specularMaterial; 
     69OUT.Color.a = 1.0; 
     70return OUT; 
     71} 
     72*/ 
    4173        OUT.texCoord = IN.texCoord; 
    4274                 
    4375        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); 
     76        float factor = pos * pos * windStrength * sin(timer * frequency); 
    4477 
     78        // transform the vertex position into post projection space 
     79        OUT.position = mul(glstate.matrix.mvp, IN.position); 
     80        // displace the input position 
     81        OUT.position += float4(factor * windDir, 0); 
     82 
     83        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
     84 
     85        Out.color = IN.color * max(0, dot(OUT.normal, lightDir)); 
     86        //OUT.color1 = IN.color1; 
     87 
     88        return OUT; 
     89} 
     90 
     91/** vertex shader which conducts an simple tree animation 
     92        that bends the tree depending quadratically on the height 
     93        This version of the shader is used for deferred shading and thus only  
     94        displaces the vertices and outputs the color, put does not do any shading. 
     95*/ 
     96vtxout animateVtxMrt(vtxin IN, 
     97                                         uniform float3 windDir, 
     98                                         uniform float windStrength, 
     99                                         uniform float frequency, 
     100                                         uniform float2 minMaxPos, 
     101                                         uniform float timer) 
     102{ 
     103        vtxout OUT; 
     104 
     105        OUT.color = IN.color; 
     106        //OUT.color1 = IN.color1; 
     107 
     108        OUT.texCoord = IN.texCoord; 
     109                 
     110        const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); 
    45111        float factor = pos * pos * windStrength * sin(timer * frequency); 
    46112 
     
    54120        OUT.eyePos += float4(factor * windDir, 0); 
    55121 
    56         OUT.normal = IN.normal; 
    57  
     122        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
     123         
    58124        return OUT; 
    59125} 
Note: See TracChangeset for help on using the changeset viewer.