Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2011
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.93 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. bool xShowNormals;
  22. float3 xCamPos;
  23. float3 xCamUp;
  24. float xPointSpriteSize;
  25.  
  26. //------- Texture Samplers --------
  27.  
  28. Texture xTexture;
  29. sampler TextureSampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};
  30.  
  31. //------- Technique: Pretransformed --------
  32.  
  33. VertexToPixel PretransformedVS( float4 inPos : POSITION, float4 inColor: COLOR)
  34. {  
  35.     VertexToPixel Output = (VertexToPixel)0;
  36.    
  37.     Output.Position = inPos;
  38.     Output.Color = inColor;
  39.    
  40.     return Output;    
  41. }
  42.  
  43. PixelToFrame PretransformedPS(VertexToPixel PSIn)
  44. {
  45.     PixelToFrame Output = (PixelToFrame)0;     
  46.    
  47.     Output.Color = PSIn.Color;
  48.  
  49.     return Output;
  50. }
  51.  
  52. technique Pretransformed
  53. {
  54.     pass Pass0
  55.     {  
  56.         VertexShader = compile vs_2_0 PretransformedVS();
  57.         PixelShader  = compile ps_2_0 PretransformedPS();
  58.     }
  59. }
  60.  
  61. //------- Technique: Colored --------
  62.  
  63. VertexToPixel ColoredVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float4 inColor: COLOR)
  64. {  
  65.     VertexToPixel Output = (VertexToPixel)0;
  66.     float4x4 preViewProjection = mul (xView, xProjection);
  67.     float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  68.    
  69.     Output.Position = mul(inPos, preWorldViewProjection);
  70.     Output.Color = inColor;
  71.    
  72.     float3 Normal = normalize(mul(normalize(inNormal), xWorld));   
  73.     Output.LightingFactor = 1;
  74.     if (xEnableLighting)
  75.         Output.LightingFactor = dot(Normal, -xLightDirection);
  76.    
  77.     return Output;    
  78. }
  79.  
  80. PixelToFrame ColoredPS(VertexToPixel PSIn)
  81. {
  82.     PixelToFrame Output = (PixelToFrame)0;     
  83.    
  84.     Output.Color = PSIn.Color;
  85.     Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
  86.  
  87.     return Output;
  88. }
  89.  
  90. technique Colored
  91. {
  92.     pass Pass0
  93.     {  
  94.         VertexShader = compile vs_2_0 ColoredVS();
  95.         PixelShader  = compile ps_2_0 ColoredPS();
  96.     }
  97. }
  98.  
  99. //------- Technique: ColoredNoShading --------
  100.  
  101. VertexToPixel ColoredNoShadingVS( float4 inPos : POSITION, float4 inColor: COLOR)
  102. {  
  103.     VertexToPixel Output = (VertexToPixel)0;
  104.     float4x4 preViewProjection = mul (xView, xProjection);
  105.     float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  106.    
  107.     Output.Position = mul(inPos, preWorldViewProjection);
  108.     Output.Color = inColor;
  109.    
  110.     return Output;    
  111. }
  112.  
  113. PixelToFrame ColoredNoShadingPS(VertexToPixel PSIn)
  114. {
  115.     PixelToFrame Output = (PixelToFrame)0;     
  116.    
  117.     Output.Color = PSIn.Color;
  118.  
  119.     return Output;
  120. }
  121.  
  122. technique ColoredNoShading
  123. {
  124.     pass Pass0
  125.     {  
  126.         VertexShader = compile vs_2_0 ColoredNoShadingVS();
  127.         PixelShader  = compile ps_2_0 ColoredNoShadingPS();
  128.     }
  129. }
  130.  
  131.  
  132. //------- Technique: Textured --------
  133.  
  134. VertexToPixel TexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
  135. {  
  136.     VertexToPixel Output = (VertexToPixel)0;
  137.     float4x4 preViewProjection = mul (xView, xProjection);
  138.     float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  139.    
  140.     Output.Position = mul(inPos, preWorldViewProjection);  
  141.     Output.TextureCoords = inTexCoords;
  142.    
  143.     float3 Normal = normalize(mul(normalize(inNormal), xWorld));   
  144.     Output.LightingFactor = 1;
  145.     if (xEnableLighting)
  146.         Output.LightingFactor = dot(Normal, -xLightDirection);
  147.    
  148.     return Output;    
  149. }
  150.  
  151. PixelToFrame TexturedPS(VertexToPixel PSIn)
  152. {
  153.     PixelToFrame Output = (PixelToFrame)0;     
  154.    
  155.     Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
  156.     Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
  157.  
  158.     return Output;
  159. }
  160.  
  161. technique Textured
  162. {
  163.     pass Pass0
  164.     {  
  165.         VertexShader = compile vs_2_0 TexturedVS();
  166.         PixelShader  = compile ps_2_0 TexturedPS();
  167.     }
  168. }
  169.  
  170. //------- Technique: TexturedNoShading --------
  171.  
  172. VertexToPixel TexturedNoShadingVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
  173. {  
  174.     VertexToPixel Output = (VertexToPixel)0;
  175.     float4x4 preViewProjection = mul (xView, xProjection);
  176.     float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
  177.    
  178.     Output.Position = mul(inPos, preWorldViewProjection);  
  179.     Output.TextureCoords = inTexCoords;
  180.    
  181.     return Output;    
  182. }
  183.  
  184. PixelToFrame TexturedNoShadingPS(VertexToPixel PSIn)
  185. {
  186.     PixelToFrame Output = (PixelToFrame)0;     
  187.    
  188.     Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
  189.  
  190.     return Output;
  191. }
  192.  
  193. technique TexturedNoShading
  194. {
  195.     pass Pass0
  196.     {  
  197.         VertexShader = compile vs_2_0 TexturedNoShadingVS();
  198.         PixelShader  = compile ps_2_0 TexturedNoShadingPS();
  199.     }
  200. }
  201.  
  202. //------- Technique: PointSprites --------
  203.  
  204. VertexToPixel PointSpriteVS(float3 inPos: POSITION0, float2 inTexCoord: TEXCOORD0)
  205. {
  206.     VertexToPixel Output = (VertexToPixel)0;
  207.  
  208.     float3 center = mul(inPos, xWorld);
  209.     float3 eyeVector = center - xCamPos;
  210.  
  211.     float3 sideVector = cross(eyeVector,xCamUp);
  212.     sideVector = normalize(sideVector);
  213.     float3 upVector = cross(sideVector,eyeVector);
  214.     upVector = normalize(upVector);
  215.  
  216.     float3 finalPosition = center;
  217.     finalPosition += (inTexCoord.x-0.5f)*sideVector*0.5f*xPointSpriteSize;
  218.     finalPosition += (0.5f-inTexCoord.y)*upVector*0.5f*xPointSpriteSize;
  219.  
  220.     float4 finalPosition4 = float4(finalPosition, 1);
  221.  
  222.     float4x4 preViewProjection = mul (xView, xProjection);
  223.     Output.Position = mul(finalPosition4, preViewProjection);
  224.  
  225.     Output.TextureCoords = inTexCoord;
  226.  
  227.     return Output;
  228. }
  229.  
  230. PixelToFrame PointSpritePS(VertexToPixel PSIn) : COLOR0
  231. {
  232.     PixelToFrame Output = (PixelToFrame)0;
  233.     Output.Color = tex2D(TextureSampler, PSIn.TextureCoords);
  234.     return Output;
  235. }
  236.  
  237. technique PointSprites
  238. {
  239.     pass Pass0
  240.     {  
  241.         VertexShader = compile vs_2_0 PointSpriteVS();
  242.         PixelShader  = compile ps_2_0 PointSpritePS();
  243.     }
  244. }
  245.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement