home *** CD-ROM | disk | FTP | other *** search
/ Level 2005 Christmas (DVD) / Level_2005-XMAS_134_DVD_Knightshift.iso / Install / WDFiles / Shaders.wd / Shaders_hier_diff_pp.sha < prev    next >
Encoding:
Text File  |  2005-12-07  |  4.5 KB  |  206 lines

  1.  
  2. vector vLocalAmbientAndFogFactor;
  3. vector vAmbientLightColor;
  4. vector vDiffuseLightColor;
  5. vector vFogColor;
  6. vector vHelpers1;
  7. vector vHelpers2;
  8. vector vSpecularColorAndPower;
  9. vector vDiffuseDirection;
  10.  
  11. vector vLocalSpaceLightVector;
  12.  
  13. vertexshader vsDAS = 
  14.  
  15.                 decl
  16.                 {
  17.                     stream 0;
  18.                     float         v0[3];    // position
  19.                     float         v1[3];    // normalized normal    -    not used in PPLighting!!!
  20.                     D3DCOLOR    v2[1];    // color 1    - not used yet
  21.                     D3DCOLOR    v3[1];    // color 2    - not used yet
  22.                     float         v4[2];    // uv coordinates
  23.                     float        v5[3];    // S-tangent
  24.                 }
  25.  
  26.                 asm
  27.                 {
  28.                     vs.1.1
  29.  
  30.                     m4x4 oPos, v0, c[0]        // transform vertex clip space
  31.     
  32.                     // - diffuse bump computations -
  33.                     // cross product normal with tangent to get binormal
  34.                     mov r2, v5
  35.                     mul r0, v1.yzxw, r2.zxyw
  36.                     mad r0,-r2.yzxw, v1.zxyw, r0
  37.  
  38.                     // transform light by basis vectors
  39.                     //dp3  r1.x, v5.xyz, c[92]    // form vertex format
  40.                     //dp3  r1.y, r0.xyz, c[92]    // calculated
  41.                     //dp3  r1.z, v1.xyz, c[92]    // SxT ~ N
  42.                     dp3  r1.x, v5, c[92]    // form vertex format
  43.                     dp3  r1.y, r0, c[92]    // calculated
  44.                     dp3  r1.z, v1, c[92]    // SxT ~ N
  45.  
  46.                     // normalize light vector in tangent space
  47.                     dp3  r1.w, r1, r1            // seams 
  48.                     rsq  r1.w, r1.w                // it isn't
  49.                     mul  r1,   r1, r1.w            // necessary
  50.  
  51.                     // emit light vector
  52.                     add  r1, r1, c[91].y
  53.                     mul  r1,r1,c[91].w
  54.                     mov     oD0, r1
  55.                     
  56.                     // emit coordinates for textures
  57.                     mov  oT0, v4                // emit uv mapping
  58.                     mov  oT1, v4                // emit coordinates for bump map
  59.                     };
  60.  
  61.  
  62. pixelshader psDAF = 
  63.         asm
  64.         {
  65.             ps.1.1
  66.                         
  67.             tex t0                        // normal map
  68.             tex t1                        // base texture
  69.             
  70.             // diffuse component
  71.             dp3_sat    r1,t0_bx2,v0_bx2;    // r1=Dot(normal,interp_light)
  72.             
  73.             mul r1,r1,c2            
  74.             add r1,r1,c1
  75.             add r1,r1,c3
  76.             mul r0,r1,t1                // modulate with base texture
  77.  
  78.             mov r1,c3            
  79.             lrp r0,r1.a,r0,c0            //fake fog                        
  80.         };
  81.  
  82.  
  83.  
  84. technique tGF3_DiffusePerPixel
  85. {
  86.     pass p0
  87.     {            
  88.         PixelShaderConstant[0]    =    <vFogColor>;
  89.         PixelShaderConstant[1]    =    <vAmbientLightColor>;
  90.         PixelShaderConstant[2]    =    <vDiffuseLightColor>;
  91.         PixelShaderConstant[3]    =    <vLocalAmbientAndFogFactor>;
  92.         
  93.         VertexShaderConstant[92] = <vDiffuseDirection>;
  94.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0 , 0.5 };
  95.  
  96.         FogEnable        =    False;
  97.         CullMode = cw;
  98.  
  99.         VertexShader    =    <vsDAS>;
  100.         PixelShader        =    <psDAF>;
  101.     }
  102. }
  103.  
  104.  
  105. vertexshader vsTest = 
  106.  
  107.                 decl
  108.                 {
  109.                     stream 0;
  110.                     float         v0[3];    // position
  111.                     float         v1[3];    // normalized normal    -    not used in PPLighting!!!
  112.                     D3DCOLOR    v2[1];    // color 1    - not used yet
  113.                     D3DCOLOR    v3[1];    // color 2    - not used yet
  114.                     float         v4[2];    // uv coordinates
  115.                     float        v5[3];    // S-tangent
  116.                 }
  117.  
  118.                 asm
  119.                 {
  120.                     vs.1.1
  121.  
  122.                     m4x4 oPos, v0, c[0]        // transform vertex clip space
  123.     
  124.                     // - diffuse bump computations -
  125.                     // cross product normal with tangent to get binormal
  126.                     mov r2, v5
  127.                     mul r0, v1.yzxw, r2.zxyw
  128.                     mad r0,-r2.yzxw, v1.zxyw, r0
  129.  
  130.                     // transform light by basis vectors
  131.                     dp3  r1.x, v5.xyz, c[92]    // form vertex format
  132.                     dp3  r1.y, r0.xyz, c[92]    // calculated
  133.                     dp3  r1.z, v1.xyz, c[92]    // SxT ~ N
  134.  
  135.                     // normalize light vector in tangent space
  136.                     dp3  r1.w, r1, r1            // seams 
  137.                     rsq  r1.w, r1.w                // it isnt
  138.                     mul  r1,   r1, r1.w            // necessary
  139.  
  140.                     // emit light vector
  141.                     //mad  r1.xyz, r1.xyz, c[91].w,c[91].w
  142.                     add  r1, r1, c[91].y
  143.                     mul  r1,r1,c[91].w
  144.                     mov     oD0, r1
  145.                     
  146.                     // emit coordinates for textures
  147.                     mov  oT0, v4                // emit uv mapping
  148.                     mov  oT1, v4                // emit coordinates for bump map
  149.                     };
  150.  
  151.  
  152. pixelshader psTest = 
  153.         asm
  154.         {
  155.             ps.1.1
  156.                         
  157.             tex t0                        // normal map
  158.             tex t1                        // base texture
  159.             // diffuse component
  160.             dp3_sat    r1,t0_bx2,v0_bx2;    // r1=Dot(normal,interp_light)
  161.             mov r0,r1
  162.  
  163.             //mul_x2 r1,r1,c2
  164.             //add r1,r1,c1
  165.             //add r1,r1,c3
  166.             //mul r0,r1,t1                // modulate with base texture
  167.             //
  168.             //lrp r0,c3.a,r0,c0            //fake fog
  169.             
  170.         };
  171.  
  172. // test
  173. technique tGF3_Test
  174. {
  175.     pass p0
  176.     {            
  177.         PixelShaderConstant[0]    =    <vFogColor>;
  178.         PixelShaderConstant[1]    =    <vAmbientLightColor>;
  179.         PixelShaderConstant[2]    =    <vDiffuseLightColor>;
  180.         PixelShaderConstant[3]    =    <vLocalAmbientAndFogFactor>;
  181.         
  182.         VertexShaderConstant[92] = <vLocalSpaceLightVector>;
  183.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0039 , 0.5 };
  184.  
  185.         FogEnable        =    False;
  186.  
  187.         VertexShader    =    <vsTest>;
  188.         PixelShader        =    <psTest>;
  189.     }
  190. }
  191.  
  192. technique t5th_hierdiffPP
  193. {
  194.     pass p0
  195.     {            
  196.  
  197.         
  198.         VertexShaderConstant[92] = <vLocalSpaceLightVector>;
  199.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0039 , 0.5 };
  200.  
  201.         FogEnable        =    False;
  202.  
  203.         VertexShader    =    <vsTest>;
  204.     }
  205. }
  206.