Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float4x4 World;
- float4x4 View;
- float4x4 Projection;
- float4 LightAmbient;
- float4 LightDiffuse0;
- float3 LightDir0;
- texture hm;//heighmap
- float mh = 64;//maximum heigh
- sampler hms = sampler_state{ //this sampler will be used to read (sample) the heightmap
- Texture = <hm>;
- MipFilter = Point;
- MinFilter = Point;
- MagFilter = Point;
- AddressU = Clamp;
- AddressV = Clamp;
- };
- struct VertexShaderInput
- {
- float4 Position : POSITION0;
- float4 uv : TEXCOORD0;
- };
- struct VertexShaderOutput
- {
- float4 Position : POSITION0;
- float3 Normal : TEXCOORD0;
- };
- VertexShaderOutput VertexShaderFunction(VertexShaderInput input, float3 Normal : NORMAL)
- {
- VertexShaderOutput output;
- float height = tex2Dlod ( hms, float4(input.uv.xy , 0 , 0 ) );
- input.Position.y = height * -mh;
- float4 worldPosition = mul(input.Position, World);
- float4 viewPosition = mul(worldPosition, View);
- output.Position = mul(viewPosition, Projection);
- //I need somehow recalculate normals here
- float3 normal = normalize(mul(Normal, World));
- output.Normal = normal;
- return output;
- }
- float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
- {
- float4 norm = float4(Normal, 1.0);
- float4 diffuse0 = saturate(dot(-LightDir0 ,norm));
- return LightAmbient*0.7 + LightDiffuse0 * diffuse0;
- }
- technique T1
- {
- pass Pass1
- {
- VertexShader = compile vs_3_0 VertexShaderFunction();
- PixelShader = compile ps_3_0 PixelShaderFunction();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment