This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Generated code

By: AvengerDr on Oct 25th, 2013  |  syntax: C  |  size: 2.83 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // PhongPS
  2. // Pixel Shader (ps_4_0_level_9_1)
  3. //
  4. // Built with Odyssey Shader Generator v0.1.5045.27441
  5. // 25/10/2013 14:55:42
  6.  
  7.  
  8.  
  9. //------------------------------------------------------------------------------
  10. // Input/Output Structs
  11. //------------------------------------------------------------------------------
  12.  
  13.  
  14. struct VSOut
  15. {
  16.     float4 Position: SV_POSITION0;
  17.     float4 WorldPosition: POSITION0;
  18.     float3 Normal: NORMAL0;
  19.     float2 TextureUV: TEXCOORD0;
  20. };
  21.  
  22. struct PSOut
  23. {
  24.     float4 Color: SV_Target0;
  25. };
  26.  
  27.  
  28.  
  29. //------------------------------------------------------------------------------
  30. // Custom Struct Definition
  31. //------------------------------------------------------------------------------
  32.  
  33.  
  34. struct Material
  35. {
  36.     float kA;
  37.     float kD;
  38.     float kS;
  39.     float SpecularPower;
  40.     float4 Ambient;
  41.     float4 Diffuse;
  42.     float4 Specular;
  43. };
  44.  
  45. struct PointLight
  46. {
  47.     float Intensity;
  48.     float Radius;
  49.     float4 Diffuse;
  50.     float3 Position;
  51. };
  52.  
  53.  
  54.  
  55. //------------------------------------------------------------------------------
  56. // ConstantBuffers
  57. //------------------------------------------------------------------------------
  58.  
  59.  
  60. cbuffer cbStatic : register(b0)
  61. {
  62.     Material material;
  63.     PointLight lPoint;
  64. };
  65.  
  66. cbuffer cbFrame : register(b1)
  67. {
  68.     float3 vCameraPosition;
  69. };
  70.  
  71.  
  72.  
  73. //------------------------------------------------------------------------------
  74. // Required methods
  75. //------------------------------------------------------------------------------
  76.  
  77.  
  78. float4 PhongLighting(PointLight light, Material material, float3 vViewDirection, float3 vLightDirection, float3 vNormal)
  79. {
  80.     float3 L = -normalize(vLightDirection);
  81.     float3 V = normalize(vViewDirection);
  82.     float3 N = normalize(vNormal);
  83.     float NdotL = saturate(dot(N, L));
  84.     float fSelfShadow = saturate(4 * NdotL);
  85.     float4 cDiffuse = material.kD * NdotL * material.Diffuse * light.Diffuse;
  86.  
  87.     float4 cAmbient = material.kA * material.Ambient;
  88.     float3 R = reflect(-L, N);
  89.     float RdotV = dot(R,V);
  90.     float fSpecular = pow(max(RdotV, 0.0f), material.SpecularPower);
  91.     float4 cSpecular = material.kS * fSpecular * material.Specular;
  92.     float4 color = cAmbient + fSelfShadow *(cDiffuse + cSpecular);
  93.     return color;
  94. }
  95.  
  96.  
  97.  
  98. //------------------------------------------------------------------------------
  99. // Pixel Shader
  100. //------------------------------------------------------------------------------
  101.  
  102.  
  103. PSOut PhongPS(VSOut input) : SV_Target
  104. {
  105.     float3 vWorldPos = input.WorldPosition.xyz;
  106.     float3 vViewDirection = vCameraPosition - vWorldPos;
  107.     float3 vLightDirection = vWorldPos - lPoint.Position;
  108.     float4 cFinal = PhongLighting(lPoint, material, vViewDirection, vLightDirection, input.Normal);
  109.     PSOut output;
  110.     output.Color = cFinal;
  111.     return output;
  112. }
clone this paste RAW Paste Data