Guest User

Untitled

a guest
Oct 17th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. float4x4 WorldViewProj : WorldViewProjection;
  2. float4x4 World : World;
  3. float3 CameraPos : CameraPosition;
  4.  
  5. texture m_texture : DIFFUSE;
  6.  
  7. sampler texSampler = sampler_state
  8. {
  9. Texture = <m_texture>;
  10. FILTER = MIN_MAG_MIP_LINEAR;
  11. };
  12.  
  13. float4 diffuseColor
  14. <
  15. string UIName = "Diffuse Color";
  16. string UIWidget = "Color";
  17. > = (1,1,1,1);
  18.  
  19. float4 ambientColor
  20. <
  21. string UIName = "Ambient Color";
  22. string UIWidget = "Color";
  23. > = (1,1,1,1);
  24.  
  25. float3 Lamp0Pos : POSITION
  26. <
  27. string Object = "DirectionalLight0";
  28. string UIName = "Directional Light";
  29. string Space = "World";
  30. > = (0,0,0);
  31.  
  32. float phongExp
  33. <
  34. string UIName= "PhongExponent";
  35. > = (1);
  36.  
  37. struct VertexInput
  38. {
  39. float4 pos : POSITION;
  40. float2 uvCor : TEXCOORD0;
  41. float4 nor : NORMAL;
  42. };
  43.  
  44. struct VertexOutput
  45. {
  46. float4 pos : POSITION;
  47. float2 uvCor : TEXCOORD0;
  48. float4 lightColor : COLOR0;
  49. };
  50.  
  51. VertexOutput mainVS(VertexInput IN)
  52. {
  53. VertexOutput vOUT = (VertexOutput) 0;
  54. vOUT.pos = mul(float4(IN.pos.xyz, 1.0), WorldViewProj);
  55. vOUT.uvCor = IN.uvCor;
  56.  
  57. float4 worldPos = mul(IN.pos, World);
  58. float4 worldNor = mul(IN.nor, World);
  59.  
  60. //Specular
  61. float3 reflectedLight = normalize(reflect((Lamp0Pos-worldPos), worldNor));
  62. float3 viewVec = normalize(CameraPos-worldPos);
  63. float specIntensity = pow(clamp(dot(reflectedLight, viewVec), 0, 1), phongExp);
  64.  
  65. float lightIntensity = max(dot(normalize(Lamp0Pos-worldPos), normalize(worldNor)), 0);
  66.  
  67. vOUT.lightColor = lightIntensity * diffuseColor + ambientColor + specIntensity;
  68.  
  69. return vOUT;
  70. }
  71.  
  72. float4 mainPS(VertexOutput IN) : COLOR
  73. {
  74. return tex2D(texSampler, IN.uvCor) * IN.lightColor;
  75. }
  76.  
  77. technique technique0
  78. {
  79. pass p0
  80. {
  81. VertexShader = compile vs_3_0 mainVS();
  82. PixelShader = compile ps_3_0 mainPS();
  83. }
  84. }
Add Comment
Please, Sign In to add comment