/***********************************************/ /* Vertex shaders for tree animation */ /***********************************************/ struct vtxin { float4 position: POSITION; float4 normal: NORMAL; float4 color: COLOR; //float4 color1: COLOR1; float4 texCoord: TEXCOORD0; }; // vtx output struct vtxout { float4 position: POSITION; float4 texCoord: TEXCOORD0; float4 color: COLOR0; //float4 color1: COLOR1; float4 eyePos: TEXCOORD1; // eye position float3 normal: TEXCOORD2; }; /** Vertex shader which conducts an simple tree animation that bends the tree depending quadratically on the height */ vtxout animateVtx(vtxin IN, uniform float3 windDir, uniform float windStrength, uniform float frequency, uniform float2 minMaxPos, uniform float timer, uniform float3 lightDir) { vtxout OUT; /* // Transform vertex position into homogenous clip-space. OUT.HPosition = mul(ModelViewProj, IN.Position); // Transform normal from model-space to view-space. float3 normalVec = normalize(mul(ModelViewIT, IN.Normal).xyz); // Store normalized light vector. float3 lightVec = normalize(LightVec.xyz); // Calculate half angle vector. float3 eyeVec = float3(0.0, 0.0, 1.0); float3 halfVec = normalize(lightVec + eyeVec); // Calculate diffuse component. float diffuse = dot(normalVec, lightVec); // Calculate specular component. float specular = dot(normalVec, halfVec); // Use the lit function to compute lighting vector from // diffuse and specular values. float4 lighting = lit(diffuse, specular, 32); // Blue diffuse material float3 diffuseMaterial = float3(0.0, 0.0, 1.0); // White specular material float3 specularMaterial = float3(1.0, 1.0, 1.0); // Combine diffuse and specular contributions and // output final vertex color. OUT.Color.rgb = lighting.y * diffuseMaterial + lighting.z * specularMaterial; OUT.Color.a = 1.0; return OUT; } */ OUT.texCoord = IN.texCoord; const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); float factor = pos * pos * windStrength * sin(timer * frequency); // transform the vertex position into post projection space OUT.position = mul(glstate.matrix.mvp, IN.position); // displace the input position OUT.position += float4(factor * windDir, 0); OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); Out.color = IN.color * max(0, dot(OUT.normal, lightDir)); //OUT.color1 = IN.color1; return OUT; } /** vertex shader which conducts an simple tree animation that bends the tree depending quadratically on the height This version of the shader is used for deferred shading and thus only displaces the vertices and outputs the color, put does not do any shading. */ vtxout animateVtxMrt(vtxin IN, uniform float3 windDir, uniform float windStrength, uniform float frequency, uniform float2 minMaxPos, uniform float timer) { vtxout OUT; OUT.color = IN.color; //OUT.color1 = IN.color1; OUT.texCoord = IN.texCoord; const float pos = (minMaxPos.x - IN.position.z) / (minMaxPos.x - minMaxPos.y); float factor = pos * pos * windStrength * sin(timer * frequency); // transform the vertex position into post projection space OUT.position = mul(glstate.matrix.mvp, IN.position); // displace the input position OUT.position += float4(factor * windDir, 0); // transform the vertex position into eye space OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); OUT.eyePos += float4(factor * windDir, 0); OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); return OUT; }