Advertisement
Guest User

Untitled

a guest
Nov 5th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #define VS_SHADERMODEL vs_4_0_level_9_1
  2. #define PS_SHADERMODEL ps_4_0_level_9_1
  3.  
  4. //-----------------------------------------------------
  5.  
  6. matrix World;
  7. matrix View;
  8. matrix Projection;
  9.  
  10. //-----------------------------------------------------
  11.  
  12. struct VertexShaderInput
  13. {
  14.     float4 Position : SV_POSITION;
  15.     float3 Normal : NORMAL0;
  16. };
  17.  
  18. struct VertexShaderOutput
  19. {
  20.     float4 Position : SV_POSITION;
  21.     float4 Color : COLOR0;
  22. };
  23.  
  24. //-----------------------------------------------------
  25.  
  26. VertexShaderOutput MainVS(in VertexShaderInput input)
  27. {
  28.     VertexShaderOutput output = (VertexShaderOutput)0;
  29.  
  30.     float4 worldPosition = mul(input.Position, World);
  31.     float4 viewPosition = mul(worldPosition, View);
  32.     output.Position = mul(viewPosition, Projection);
  33.    
  34.     float4 N = mul(input.Normal, World); // normal in world space
  35.     float3 L = normalize(float3(0, 1, 0)); // light direction
  36.     float4 diffuse = dot(L, N) * float4(1,1,1,1); // dot * light color
  37.  
  38.     output.Color = saturate(diffuse);
  39.  
  40.     return output;
  41. }
  42.  
  43. float4 MainPS(VertexShaderOutput input) : COLOR
  44. {
  45.     return saturate(input.Color);
  46. }
  47.  
  48. //-----------------------------------------------------
  49.  
  50. technique Phong
  51. {
  52.     pass P0
  53.     {
  54.         VertexShader = compile VS_SHADERMODEL MainVS();
  55.         PixelShader = compile PS_SHADERMODEL MainPS();
  56.     }
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement