/***********************************************/ /* 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.oldWorldPos = float4(1e20f, 1e20f, 1e20f, oldOffs.w); OUT.worldPos = offs; return OUT; } /* pixel fragtex(fragin IN, uniform sampler2D tex: TEXUNIT0, uniform float4x4 viewMatrix ) { float4 texColor = tex2D(tex, IN.texCoord.xy); // account for alpha blending if (texColor.w < 0.5f) discard; pixel pix; // save color in first render target // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; // save world space normal in rt => transform back into world space by // multiplying with inverse view. since transforming normal with T means to // multiply with the inverse transpose of T, we multiple with // Transp(Inv(Inv(view))) = Transp(view) pix.norm = normalize(mul(transpose(viewMatrix), IN.normal).xyz); //pix.norm = IN.normal.xyz; // compute eye linear depth pix.col.w = 1e20f;//length(IN.eyePos.xyz); // the scene entity id //pix.id = glstate.fog.color.xyz; // the offset to the world pos from old frame pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz; return pix; }*/