Advertisement
Razer

Simple Ambient Light Shader

Mar 1st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // ----------------------------------------------------------------------------------
  2. // Parameters
  3. // ----------------------------------------------------------------------------------
  4. // Global matrix paramters
  5. float4x4 World;
  6. float4x4 View;
  7. float4x4 Projection;
  8.  
  9. // Ambient Light Parameters
  10. float4 AmbientColor = float4(1, 1, 1, 1);
  11. float AmbientIntensity = 0.1;
  12.  
  13. // Diffuse Light Parameters
  14.  
  15. // ----------------------------------------------------------------------------------
  16. // States
  17. // ----------------------------------------------------------------------------------
  18. RasterizerState rsSolid
  19. {
  20. FillMode = Solid;
  21. CullMode = NONE;
  22. FrontCounterClockwise = false;
  23. };
  24.  
  25. // ----------------------------------------------------------------------------------
  26. // Inputs / Outputs
  27. // ----------------------------------------------------------------------------------
  28. struct VertexShaderInput
  29. {
  30. float4 Position : POSITION;
  31. float2 Texture : TEXCOORD;
  32. float4 Color : COLOR;
  33. float3 Normal : NORMAL;
  34. };
  35.  
  36. struct PixelShaderInput
  37. {
  38. float4 Position : SV_POSITION;
  39. float2 Texture : TEXCOORD;
  40. float4 Color : COLOR;
  41. };
  42.  
  43. // ----------------------------------------------------------------------------------
  44. // Shaders
  45. // ----------------------------------------------------------------------------------
  46. PixelShaderInput VS_Ambient(VertexShaderInput input)
  47. {
  48. PixelShaderInput i = (PixelShaderInput)0;
  49.  
  50. i.Position = mul(input.Position, World);
  51. i.Position = mul(i.Position, View);
  52. i.Position = mul(i.Position, Projection);
  53.  
  54. i.Texture = input.Texture;
  55. i.Color = input.Color;
  56.  
  57. return i;
  58. }
  59.  
  60. float4 PS_Ambient(PixelShaderInput input) : SV_Target
  61. {
  62. return mul(input.Color, AmbientColor * AmbientIntensity);
  63. }
  64.  
  65. // ----------------------------------------------------------------------------------
  66. // Techniques
  67. // ----------------------------------------------------------------------------------
  68. technique10 Ambient
  69. {
  70. pass P0
  71. {
  72. SetVertexShader(CompileShader(vs_4_0, VS_Ambient()));
  73. SetGeometryShader(NULL);
  74. SetPixelShader(CompileShader(ps_4_0, PS_Ambient()));
  75. SetRasterizerState(rsSolid);
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement