Advertisement
TalesM

AdvRend2012Shader7

Dec 21st, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.21 KB | None | 0 0
  1. texture theEnvironmentCube
  2. <
  3.     string ResourceName = "default_reflection.dds";
  4.     string TextureType = "CUBE";
  5. >;
  6.  
  7. samplerCUBE environmentTexture = sampler_state
  8. {
  9.     Texture = <theEnvironmentCube>;
  10.     MinFilter = Linear;
  11.     MagFilter = Linear;
  12.     MipFilter = Linear;
  13.     AddressU = Clamp;
  14.     AddressV = Clamp;
  15.     AddressW = Clamp;
  16. };
  17.  
  18. /************* NON-TWEAKABLES **************/
  19. float4x4 viewI         : ViewInverse            < string UIWidget="None"; >;
  20. float4x4 viewT         : ViewTranspose            < string UIWidget="None"; >;
  21. float4x4 worldIT       : WorldInverseTranspose  < string UIWidget="None"; >;
  22. float4x4 world       : World  < string UIWidget="None"; >;
  23. float4x4 worldView     : WorldView              < string UIWidget="None"; >;
  24. float4x4 worldViewIT     : WorldViewInverseTranspose              < string UIWidget="None"; >;
  25. float4x4 worldViewProj : WorldViewProjection    < string UIWidget="None"; >;
  26.  
  27. /*********** Vertex shader ******/
  28.  
  29. void reflectionVS(float4 position   : POSITION,
  30.                   float4 normal     : NORMAL,
  31.        
  32.               out float4 clipPosition     : POSITION,
  33.               out float3 reflectDirection : TEXCOORD0) {
  34.  
  35.   // compute standard clip position
  36.   clipPosition = mul(position, worldViewProj);
  37.  
  38.   // In order to complete this exercise, you need to add some
  39.   // code to this vertex shader in order to compute
  40.   // the reflected direction of a ray from the viewing
  41.   // direction and normal vector, both expressed in the
  42.   // world coordinate system. Then, repeat the exercise, but this
  43.   // computing both the viewing direction and the normal in the
  44.   // camera coordinate system
  45.  
  46.   float3 worldSurfaceNormal = normalize( mul(normal, worldIT).xyz);
  47.   float3 worldPosition = mul(position, world).xyz;
  48.   float3 viewingDirection = normalize( worldPosition - viewI[3].xyz );
  49.  
  50.   reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
  51. }
  52.  
  53. void reflectionPS(float3 reflectDirection : TEXCOORD0,
  54.               out float4 color            : COLOR) {
  55.   color = texCUBE(environmentTexture, reflectDirection);
  56. }
  57.  
  58.  
  59. technique reflection {
  60.    pass p0 {       
  61.       VertexShader = compile vs_1_1 reflectionVS();    
  62.       PixelShader  = compile ps_2_0 reflectionPS();
  63.     }    
  64. }
  65.  
  66. void reflectionVS2(float4 position   : POSITION,
  67.                   float4 normal     : NORMAL,
  68.        
  69.               out float4 clipPosition     : POSITION,
  70.               out float3 normalOut : TEXCOORD0,
  71.               out float4 posOut : TEXCOORD1) {
  72.  
  73.   // compute standard clip position
  74.   clipPosition = mul(position, worldViewProj);
  75.  
  76.   // In order to complete this exercise, you need to add some
  77.   // code to this vertex shader in order to compute
  78.   // the reflected direction of a ray from the viewing
  79.   // direction and normal vector, both expressed in the
  80.   // world coordinate system. Then, repeat the exercise, but this
  81.   // computing both the viewing direction and the normal in the
  82.   // camera coordinate system
  83.  
  84.   normalOut = normal;
  85.   posOut = position;
  86.  
  87.  
  88.   //reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
  89. }
  90.  
  91. void reflectionPS2(float3 normal    : TEXCOORD0,
  92.                    float3 position  : TEXCOORD1,
  93.                out float4 color     : COLOR) {
  94.  
  95.   float3 worldSurfaceNormal = normalize( mul(normal, worldIT).xyz);
  96.   float3 worldPosition = mul(position, world).xyz;
  97.   float3 viewingDirection = normalize( worldPosition - viewI[3].xyz );
  98.   float3 reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
  99.   color = texCUBE(environmentTexture, reflectDirection);
  100. }
  101.  
  102.  
  103. technique reflection2 {
  104.    pass p0 {       
  105.       VertexShader = compile vs_1_1 reflectionVS2();    
  106.       PixelShader  = compile ps_2_0 reflectionPS2();
  107.     }    
  108. }
  109.  
  110.  
  111. void reflectionVS3(float4 position   : POSITION,
  112.                   float4 normal     : NORMAL,
  113.        
  114.               out float4 clipPosition     : POSITION,
  115.               out float3 normalOut : TEXCOORD0,
  116.               out float4 posOut : TEXCOORD1) {
  117.  
  118.   // compute standard clip position
  119.   clipPosition = mul(position, worldViewProj);
  120.  
  121.   // In order to complete this exercise, you need to add some
  122.   // code to this vertex shader in order to compute
  123.   // the reflected direction of a ray from the viewing
  124.   // direction and normal vector, both expressed in the
  125.   // world coordinate system. Then, repeat the exercise, but this
  126.   // computing both the viewing direction and the normal in the
  127.   // camera coordinate system
  128.  
  129.   normalOut = normal;
  130.   posOut = position;
  131.  
  132.  
  133.   //reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
  134. }
  135.  
  136. void reflectionPS3(float3 normal : TEXCOORD0,
  137.                   float3 position : TEXCOORD1,
  138.               out float4 color            : COLOR) {
  139.  
  140.   float3 worldSurfaceNormal = normalize( mul(normal, worldViewIT).xyz);
  141.   float3 worldPosition = mul(position, worldView).xyz;
  142.   float3 viewingDirection = normalize( worldPosition );
  143.   float3 reflectDirection = reflect(viewingDirection, worldSurfaceNormal);
  144.   color = texCUBE(environmentTexture, reflectDirection);
  145. }
  146.  
  147. technique reflection3 {
  148.    pass p0 {       
  149.       VertexShader = compile vs_1_1 reflectionVS3();    
  150.       PixelShader  = compile ps_2_0 reflectionPS3();
  151.     }    
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement