Advertisement
Guest User

Effects file XNA Riemer

a guest
Mar 7th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. struct VertexToPixel
  2. {
  3. float4 Position : POSITION;
  4. float4 Color : COLOR0;
  5. float LightingFactor: TEXCOORD0;
  6. float2 TextureCoords: TEXCOORD1;
  7. };
  8.  
  9. struct PixelToFrame
  10. {
  11. float4 Color : COLOR0;
  12. };
  13.  
  14. //------- Constants --------
  15. float4x4 xView;
  16. float4x4 xProjection;
  17. float4x4 xWorld;
  18. float3 xLightDirection;
  19. float xAmbient;
  20. bool xEnableLighting;
  21.  
  22. //------- Texture Samplers --------
  23.  
  24. Texture xTexture;
  25. sampler TextureSampler = sampler_state { texture = <xTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = Clamp; AddressV = Clamp;};
  26.  
  27. //------- Technique: Colored --------
  28.  
  29. VertexToPixel ColoredVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float4 inColor: COLOR)
  30. {
  31. VertexToPixel Output = (VertexToPixel)0;
  32. float4x4 preViewProjection = mul (xView, xProjection);
  33. float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  34.  
  35. Output.Position = mul(inPos, preWorldViewProjection);
  36. Output.Color = inColor;
  37.  
  38. float3 Normal = normalize(mul(normalize(inNormal), xWorld));
  39. Output.LightingFactor = 1;
  40. if (xEnableLighting)
  41. Output.LightingFactor = dot(Normal, -xLightDirection);
  42.  
  43. return Output;
  44. }
  45.  
  46. PixelToFrame ColoredPS(VertexToPixel PSIn)
  47. {
  48. PixelToFrame Output = (PixelToFrame)0;
  49.  
  50. Output.Color = PSIn.Color;
  51. Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
  52.  
  53. return Output;
  54. }
  55.  
  56. technique Colored
  57. {
  58. pass Pass0
  59. {
  60. VertexShader = compile vs_2_0 ColoredVS();
  61. PixelShader = compile ps_2_0 ColoredPS();
  62. }
  63. }
  64.  
  65. //------- Technique: Textured --------
  66.  
  67. VertexToPixel TexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
  68. {
  69. VertexToPixel Output = (VertexToPixel)0;
  70. float4x4 preViewProjection = mul (xView, xProjection);
  71. float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  72.  
  73. Output.Position = mul(inPos, preWorldViewProjection);
  74. Output.TextureCoords = inTexCoords;
  75.  
  76. float3 Normal = normalize(mul(normalize(inNormal), xWorld));
  77. Output.LightingFactor = 1;
  78. if (xEnableLighting)
  79. Output.LightingFactor = dot(Normal, -xLightDirection);
  80.  
  81. return Output;
  82. }
  83.  
  84. PixelToFrame TexturedPS(VertexToPixel PSIn)
  85. {
  86. PixelToFrame Output = (PixelToFrame)0;
  87.  
  88. Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
  89. Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
  90.  
  91. return Output;
  92. }
  93.  
  94. technique Textured
  95. {
  96. pass Pass0
  97. {
  98. VertexShader = compile vs_2_0 TexturedVS();
  99. PixelShader = compile ps_2_0 TexturedPS();
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement