Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 26th, 2012  |  syntax: C#  |  size: 2.71 KB  |  views: 92  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. texture2D diffuseMap0;
  2. sampler2D d0_Sampler = sampler_state
  3. {
  4.         Texture   = <diffuseMap0>;
  5.         MinFilter = linear;
  6.         MagFilter = linear;
  7.         MipFilter = linear;
  8. };
  9.  
  10. texture2D normalMap0;
  11. sampler2D n0_Sampler = sampler_state
  12. {
  13.         Texture = <normalMap0>;
  14.         MinFilter = linear;
  15.         MagFilter = linear;
  16.         MipFilter = linear;
  17. };
  18.  
  19.  
  20. struct VertexIn
  21. {
  22.         float4 vec4_position      : POSITION0;
  23.         float3 vec3_normal                : NORMAL0;
  24.         float2 vec2_textureCoords : TEXCOORD0;
  25.         float3 vec3_tangent       : TANGENT0;
  26.         float3 vec3_binormal      : BINORMAL0;
  27. };
  28.  
  29. struct PixelIn
  30. {
  31.         float4 vec4_position      : POSITION0;
  32.         float2 vec2_textureCoords : TEXCOORD0;
  33.         float3 vec3_View          : TEXCOORD1;
  34.         float3x3 WorldToTangentSpace : TEXCOORD2;
  35. };
  36.  
  37. struct PixelOut
  38. {
  39.     float4 color : COLOR0;
  40. };
  41.  
  42.  
  43. float3 LightDirection;  // 0.7 0 -0.7
  44. float4 DiffuseColor;     //White
  45. float  DiffuseIntensity; // 0.5
  46.  
  47. float4 vec4_Eye;  //last column in view matrix
  48. float4 SpecularColor; //white
  49.  
  50. float4x4 mat_World; //identity
  51. float4x4 mat_View;  //camera matrix
  52. float4x4 mat_Projection; //projection
  53. float4x4 WorldInverseTranspose;
  54.  
  55. float4 AmbientColor; //white
  56. float AmbientIntensity; // 1.0
  57.  
  58.  
  59. PixelIn TexturedVS(VertexIn input)
  60. {      
  61.         PixelIn output = (PixelIn)0;
  62.        
  63.         float4 worldPosition = mul(input.vec4_position, mat_World);
  64.     float4 viewPosition = mul(worldPosition, mat_View);
  65.     output.vec4_position = mul(viewPosition, mat_Projection);
  66.        
  67.         output.vec3_View = normalize(vec4_Eye - worldPosition);
  68.        
  69.         output.WorldToTangentSpace[0] = mul(normalize(input.vec3_tangent), WorldInverseTranspose);
  70.         output.WorldToTangentSpace[1] = mul(normalize(input.vec3_binormal), WorldInverseTranspose);
  71.         output.WorldToTangentSpace[2] = mul(normalize(input.vec3_normal), WorldInverseTranspose);
  72.        
  73.         output.vec2_textureCoords=input.vec2_textureCoords;
  74.        
  75.         return output;    
  76. }
  77.  
  78. PixelOut TexturedPS(PixelIn input)
  79. {
  80.         PixelOut output = (PixelOut)0; 
  81.  
  82.         float3 color=tex2D(d0_Sampler,input.vec2_textureCoords);
  83.        
  84.         float3 bump = 2.0 *(tex2D(n0_Sampler, input.vec2_textureCoords)) - 1.0;
  85.         bump = normalize(mul(bump, input.WorldToTangentSpace));
  86.        
  87.         float3 diffuse = saturate(dot(-LightDirection,bump));
  88.        
  89.         float3 reflect = normalize(2*diffuse*bump-LightDirection);
  90.         float3 specular = pow(saturate(dot(reflect,input.vec3_View)),5);
  91.        
  92.         float3 ambientColor=color*AmbientColor*AmbientIntensity;
  93.         float3 diffuseColor=color*DiffuseColor*DiffuseIntensity*diffuse;
  94.         float3 specularColor=color*SpecularColor*specular;
  95.        
  96.         output.color=float4(ambientColor+diffuseColor+specularColor,1);
  97.  
  98.         return output;
  99. }
  100.  
  101. technique Textured
  102. {
  103.         pass Pass0
  104.         {  
  105.                 VertexShader = compile vs_2_0 TexturedVS();
  106.                 PixelShader  = compile ps_2_0 TexturedPS();
  107.         }
  108. }