Guest User

HLSL Shader

a guest
Jan 29th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. float4x4 World;
  2. float4x4 View;
  3. float4x4 Projection;
  4.  
  5. float4 LightAmbient;
  6.  
  7. float4 LightDiffuse0;
  8. float3 LightDir0;
  9.  
  10. texture hm;//heighmap
  11. float mh = 64;//maximum heigh
  12.  
  13. sampler hms = sampler_state{ //this sampler will be used to read (sample) the heightmap
  14. Texture = <hm>;
  15. MipFilter = Point;
  16. MinFilter = Point;
  17. MagFilter = Point;
  18. AddressU = Clamp;
  19. AddressV = Clamp;
  20. };
  21.  
  22. struct VertexShaderInput
  23. {
  24. float4 Position : POSITION0;
  25. float4 uv : TEXCOORD0;
  26. };
  27.  
  28. struct VertexShaderOutput
  29. {
  30. float4 Position : POSITION0;
  31. float3 Normal : TEXCOORD0;
  32. };
  33.  
  34. VertexShaderOutput VertexShaderFunction(VertexShaderInput input, float3 Normal : NORMAL)
  35. {
  36. VertexShaderOutput output;
  37. float height = tex2Dlod ( hms, float4(input.uv.xy , 0 , 0 ) );
  38. input.Position.y = height * -mh;
  39. float4 worldPosition = mul(input.Position, World);
  40. float4 viewPosition = mul(worldPosition, View);
  41. output.Position = mul(viewPosition, Projection);
  42. //I need somehow recalculate normals here
  43. float3 normal = normalize(mul(Normal, World));
  44. output.Normal = normal;
  45.  
  46. return output;
  47. }
  48.  
  49. float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
  50. {
  51. float4 norm = float4(Normal, 1.0);
  52. float4 diffuse0 = saturate(dot(-LightDir0 ,norm));
  53. return LightAmbient*0.7 + LightDiffuse0 * diffuse0;
  54. }
  55.  
  56. technique T1
  57. {
  58. pass Pass1
  59. {
  60. VertexShader = compile vs_3_0 VertexShaderFunction();
  61. PixelShader = compile ps_3_0 PixelShaderFunction();
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment