- Timestamp:
- 10/19/08 23:42:15 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
r3044 r3045 1 / /--------------------------------------------------------------------------------------2 / / Input and Output structs3 / /--------------------------------------------------------------------------------------1 /***********************************************/ 2 /* Vertex shaders for tree animation */ 3 /***********************************************/ 4 4 5 5 … … 7 7 { 8 8 float4 position: POSITION; 9 float3 normal: NORMAL; 9 float4 normal: NORMAL; 10 10 11 float4 color: COLOR; 12 //float4 color1: COLOR1; 13 11 14 float4 texCoord: TEXCOORD0; 12 15 }; … … 19 22 20 23 float4 color: COLOR0; 24 //float4 color1: COLOR1; 21 25 float4 eyePos: TEXCOORD1; // eye position 22 26 float3 normal: TEXCOORD2; … … 24 28 25 29 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 */ 31 33 vtxout animateVtx(vtxin IN, 32 34 uniform float3 windDir, … … 34 36 uniform float frequency, 35 37 uniform float2 minMaxPos, 36 uniform float timer) 38 uniform float timer, 39 uniform float3 lightDir) 37 40 { 38 41 vtxout OUT; 39 42 40 OUT.color = float4(0);//IN.color; 43 /* 44 // Transform vertex position into homogenous clip-space. 45 OUT.HPosition = mul(ModelViewProj, IN.Position); 46 // Transform normal from model-space to view-space. 47 float3 normalVec = normalize(mul(ModelViewIT, 48 IN.Normal).xyz); 49 // Store normalized light vector. 50 float3 lightVec = normalize(LightVec.xyz); 51 // Calculate half angle vector. 52 float3 eyeVec = float3(0.0, 0.0, 1.0); 53 float3 halfVec = normalize(lightVec + eyeVec); 54 // Calculate diffuse component. 55 float diffuse = dot(normalVec, lightVec); 56 // Calculate specular component. 57 float specular = dot(normalVec, halfVec); 58 // Use the lit function to compute lighting vector from 59 // diffuse and specular values. 60 float4 lighting = lit(diffuse, specular, 32); 61 // Blue diffuse material 62 float3 diffuseMaterial = float3(0.0, 0.0, 1.0); 63 // White specular material 64 float3 specularMaterial = float3(1.0, 1.0, 1.0); 65 // Combine diffuse and specular contributions and 66 // output final vertex color. 67 OUT.Color.rgb = lighting.y * diffuseMaterial + 68 lighting.z * specularMaterial; 69 OUT.Color.a = 1.0; 70 return OUT; 71 } 72 */ 41 73 OUT.texCoord = IN.texCoord; 42 74 43 75 const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); 76 float factor = pos * pos * windStrength * sin(timer * frequency); 44 77 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 */ 96 vtxout 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); 45 111 float factor = pos * pos * windStrength * sin(timer * frequency); 46 112 … … 54 120 OUT.eyePos += float4(factor * windDir, 0); 55 121 56 OUT.normal = IN.normal;57 122 OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 123 58 124 return OUT; 59 125 }
Note: See TracChangeset
for help on using the changeset viewer.