Advertisement
Guest User

Untitled

a guest
Feb 9th, 2021
40
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. float4x4 World;
  3. float4x4 View;
  4. float4x4 Projection;
  5.  
  6. float4 AmbientColor = float4(1, 1, 1, 1);
  7. float AmbientIntensity = 0.1;
  8.  
  9. float4x4 WorldInverseTranspose;
  10.  
  11. float3 DiffuseLightDirection = float3(1, 0, 0);
  12. float4 DiffuseColor = float4(1, 1, 1, 1);
  13. float DiffuseIntensity = 1.0;
  14.  
  15. float Shininess = 200;
  16. float4 SpecularColor = float4(1, 1, 1, 1);
  17. float SpecularIntensity = 1;
  18. float3 ViewVector = float3(1, 0, 0);
  19.  
  20. struct VertexShaderInput
  21. {
  22. float4 Position : SV_POSITION;
  23. float4 Normal : NORMAL0;
  24. };
  25.  
  26. struct VertexShaderOutput
  27. {
  28. float4 Position : SV_POSITION;
  29. float4 Color : COLOR0;
  30. float3 Normal : TEXCOORD0;
  31. };
  32.  
  33. VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
  34. {
  35. VertexShaderOutput output;
  36.  
  37. float4 worldPosition = mul(input.Position, World);
  38. float4 viewPosition = mul(worldPosition, View);
  39. output.Position = mul(viewPosition, Projection);
  40.  
  41. float4 normal = normalize(mul(input.Normal, WorldInverseTranspose));
  42. float lightIntensity = dot(normal.xyz, DiffuseLightDirection);
  43. output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);
  44.  
  45. output.Normal = normal.xyz;
  46.  
  47. return output;
  48. }
  49.  
  50. float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET0
  51. {
  52. float3 light = normalize(DiffuseLightDirection);
  53. float3 normal = normalize(input.Normal);
  54. float3 r = normalize(2 * dot(light, normal) * normal - light);
  55. float3 v = normalize(mul(normalize(ViewVector), (float3x3) World));
  56.  
  57. float dotProduct = dot(r, v);
  58. float4 specular = SpecularIntensity * SpecularColor * max(pow(abs(dotProduct), Shininess), 0) * length(input.Color);
  59.  
  60. return saturate(input.Color + AmbientColor * AmbientIntensity + specular);
  61. }
  62.  
  63. technique Specular
  64. {
  65. pass Pass1
  66. {
  67. VertexShader = compile vs_4_0 VertexShaderFunction();
  68. PixelShader = compile ps_4_0 PixelShaderFunction();
  69. }
  70. }
Advertisement
RAW Paste Data Copied
Advertisement