/***********************************************/ /* Vertex shaders for tree animation */ /***********************************************/ struct vtxin { float4 position: POSITION; float4 normal: NORMAL; float4 color: COLOR; float4 texCoord: TEXCOORD0; }; // vtx output struct vtxout { float4 position: POSITION; float4 texCoord: TEXCOORD0; float4 color: COLOR0; // eye position float4 eyePos: TEXCOORD1; float4 normal: TEXCOORD2; float4 worldPos: TEXCOORD3; float4 oldWorldPos: TEXCOORD4; }; /** 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 diffuse = 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 * diffuse; 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, uniform float oldTimer ) { 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); const float4 offs = float4(factor * windDir, 0); float oldFactor = pos * pos * windStrength * sin(oldTimer * frequency); const float4 oldOffs = float4(oldFactor * windDir, 0); // transform the vertex position into post projection space OUT.position = mul(glstate.matrix.mvp, IN.position); // displace the input position OUT.position += offs; // transform the vertex position into eye space OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); OUT.eyePos += offs; OUT.normal = normalize(mul(glstate.matrix.invtrans.modelview[0], IN.normal)); // hack: no translational component anyway OUT.oldWorldPos = oldOffs; OUT.worldPos = offs; return OUT; }