Advertisement
Delta

HLSL shaders

Apr 3rd, 2011
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. float4x4 World;
  2. float4x4 View;
  3. float4x4 Projection;
  4. Texture ModelTexture;
  5.  
  6. sampler2D TexSampler = sampler_state
  7. {
  8. Texture = (ModelTexture);
  9. MinFilter = Linear;
  10. MagFilter = Linear;
  11. AddressU = Wrap;
  12. AddressV = Wrap;
  13. };
  14.  
  15. struct A2V
  16. {
  17. float4 Position : POSITION0;
  18. float4 Normal : NORMAL0;
  19. float2 TexCoords : TEXCOORD0;
  20. };
  21.  
  22. struct V2P
  23. {
  24. float4 Position : POSITION0;
  25. float2 TexCoords : TEXCOORD0;
  26. float4 Lighting : TEXCOORD1;
  27. };
  28.  
  29. float4 AmbientLight = float4(1.0f, 1.0f, 1.0f, 1.0f);
  30. float AmbientLightIntensity = -0.2f;
  31.  
  32. float4 DiffuseLight = float4(1.0f, 1.0f, 0.6f, 1.0f);
  33. float4 DiffuseLightSource = float4(0.0f, 0.0f, 50.0f, 1.0f);
  34. float DiffuseLightIntensity = 0.5f;
  35. float4x4 WorldTransposedInverse;
  36.  
  37. bool EnableLighting = true;
  38.  
  39. V2P LOLVS(A2V Input)
  40. {
  41. V2P Output = (V2P)0;
  42.  
  43. Output.TexCoords = Input.TexCoords;
  44.  
  45. float4 iTransformed = mul(Input.Position, World);
  46. float4 iView = mul(iTransformed, View);
  47. float4 iProjection = mul(iView, Projection);
  48.  
  49. Output.Position = iProjection;
  50.  
  51. float4 Normal = normalize(mul(Input.Normal, WorldTransposedInverse));
  52. float DiffuseLightVertexIntensity = dot(Normal, normalize(DiffuseLightSource));
  53.  
  54. Output.Lighting = AmbientLight * AmbientLightIntensity + DiffuseLight * DiffuseLightIntensity * DiffuseLightVertexIntensity;
  55.  
  56. return Output;
  57. }
  58.  
  59. float4 LOLPS(V2P Input) : COLOR
  60. {
  61. float4 TextureColor = float4(tex2D(TexSampler, Input.TexCoords).rgb, 1.0f);
  62. if(EnableLighting)
  63. return saturate(TextureColor + Input.Lighting);
  64. else
  65. return TextureColor;
  66. }
  67.  
  68. technique LOL
  69. {
  70. Pass lmfao
  71. {
  72. VertexShader = compile vs_2_0 LOLVS();
  73. PixelShader = compile ps_2_0 LOLPS();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement