/***********************************************/ /* 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 float4 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; 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 = normalize(mul(glstate.matrix.invtrans.modelview[0], IN.normal)); //const float3 l = normalize(mul(glstate.matrix.modelview[0], float4(lightDir, 0))).xyz; const float3 l = normalize(lightDir); const float dif = max(.0f, dot(OUT.normal.xyz, l)); //OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir))); OUT.color = glstate.material.ambient + glstate.material.front.diffuse * dif; OUT.color.w = IN.color.w; return OUT; } /** vertex shader which provides an simple tree animation that bends the tree depending quadratically on the height using vertex displacement. 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.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; }