////////////////////////////// MOVING GRASS // Vertex program to wave some grass about // Assumes UV texture coords of v==0 indicates the top of the grass void grass_vp(float4 position : POSITION, float3 normal : NORMAL, float2 uv : TEXCOORD0, out float4 oPosition : POSITION, out float2 oUv : TEXCOORD0, out float4 oColour : COLOR, uniform float4x4 worldViewProj, //uniform float4 camObjPos, uniform float4 ambient, uniform float4 objSpaceLight, uniform float4 lightColour, uniform float4 offset) { float4 mypos = position; //offset = float4(0.5, 0, 0, 0); float4 factor = float4(1,1,1,1) - uv.yyyy; mypos = mypos + offset * factor; oPosition = mul(worldViewProj, mypos); oUv = uv; // Color // get vertex light direction (support directional and point) float3 light = normalize(objSpaceLight.xyz - (mypos.xyz * objSpaceLight.w)); // grass is just 2D quads, so if light passes underneath we need to invert the normal // abs() will have the same effect float diffuseFactor = abs(dot(normal.xyz, light)); oColour = ambient + diffuseFactor * lightColour; } void grass_fp( float4 position : POSITION, float2 uv : TEXCOORD0, float4 colour : COLOR, out float4 oColour : COLOR, uniform float alphaThresh, uniform sampler2D diffuseMap ) { float4 texColor = tex2D(diffuseMap, uv.xy); oColour = float4(texColor.rgb * colour.rgb, texColor.a); if(oColour.a < alphaThresh) discard; }