Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. struct VertexShaderInput {
  2.     float4 Position     : SV_Position;
  3.     float3 Normal       : NORMAL;
  4.     float2 TextureCoords: TEXCOORD0;
  5. };
  6.  
  7. struct VertexShaderOutput {
  8.     float4 Position     : SV_Position;
  9.     float2 TextureCoords: TEXCOORD0;
  10.     float LightingFactor: TEXCOORD1;
  11. };
  12.  
  13. struct PixelShaderOutput {
  14.     float4 Color        : SV_Target;
  15. };
  16.  
  17. cbuffer Parameters {
  18.     float4x4 xView;
  19.     float4x4 xProjection;
  20.     float4x4 xWorld;
  21.     float3 xLightDirection;
  22.     float xAmbient;
  23. }
  24.  
  25. Texture2D dirtTexture;
  26. SamplerState WrapSampler {
  27.     Filter = MIN_MAG_MIP_LINEAR;
  28.     AddressU = Wrap;
  29.     AddressV = Wrap;
  30. };
  31.  
  32. VertexShaderOutput TexturedVS(VertexShaderInput VSin) {
  33.     VertexShaderOutput Output = (VertexShaderOutput)0;
  34.     float4x4 preViewProjection = mul(xView, xProjection);
  35.     float4x4 preWorldViewProjection = mul(xWorld, preViewProjection);
  36.    
  37.     Output.Position = mul(VSin.Position, preWorldViewProjection);
  38.     Output.TextureCoords = VSin.TextureCoords;
  39.    
  40.     float3 Normal = normalize(mul(normalize(VSin.Normal), xWorld));
  41.     Output.LightingFactor = dot(Normal, xLightDirection);
  42.    
  43.     return Output;    
  44. }
  45.  
  46. PixelShaderOutput TexturedPS(VertexShaderOutput PSIn) {
  47.     PixelShaderOutput Output = (PixelShaderOutput)0;
  48.    
  49.     Output.Color = dirtTexture.Sample(WrapSampler, PSIn.TextureCoords);
  50.     Output.Color.rgb *= saturate(PSIn.LightingFactor) + xAmbient;
  51.  
  52.     return Output;
  53. }
  54.  
  55. technique Textured {
  56.     pass p0 {
  57.         AlphaBlendEnable = false;
  58.         Profile = fx_4_0;
  59.         PixelShader = TexturedPS;
  60.         VertexShader = TexturedVS;
  61.         GeometryShader = 0;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement