home *** CD-ROM | disk | FTP | other *** search
/ Level 2005 Christmas (DVD) / Level_2005-XMAS_134_DVD_Knightshift.iso / Install / WDFiles / Shaders.wd / Shaders_hier_spec_pp.sha < prev    next >
Encoding:
Text File  |  2005-12-07  |  4.7 KB  |  216 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. vector vViewerPosition;
  11.  
  12. vector vLocalSpaceLightVector;
  13.  
  14. vertexshader vsDAS = 
  15.  
  16.                 decl
  17.                 {
  18.                     stream 0;
  19.                     float         v0[3];    // position
  20.                     float         v1[3];    // normalized normal    -    not used in PPLighting!!!
  21.                     D3DCOLOR    v2[1];    // color 1    - not used yet
  22.                     D3DCOLOR    v3[1];    // color 2    - not used yet
  23.                     float         v4[2];    // uv coordinates
  24.                     float        v5[3];    // S-tangent
  25.                 }
  26.  
  27.                 asm
  28.                 {
  29.                     vs.1.1
  30.  
  31.                     m4x4 oPos, v0, c[0]        // transform vertex clip space
  32.     
  33.                     // * - diffuse bump computations - *
  34.  
  35.                     // cross product normal with tangent to get binormal
  36.                     mov r2, v5
  37.                     mul r0, v1.yzxw, r2.zxyw
  38.                     mad r0,-r2.yzxw, v1.zxyw, r0
  39.  
  40.                     // transform light by basis vectors
  41.                     dp3  r1.x, v5.xyz, c[92]
  42.                     dp3  r1.y, r0.xyz, c[92]
  43.                     dp3  r1.z, v1.xyz, c[92]
  44.  
  45.                     // normalize light vector in tangent space
  46.                     dp3  r1.w, r1, r1
  47.                     rsq  r1.w, r1.w
  48.                     mul  r1,   r1, r1.w
  49.                     // emit light vector
  50.                     add  r1, r1, c[91].y
  51.                     mul  r1,r1,c[91].w
  52.                     mov     oD0, r1
  53.  
  54.  
  55.                     // * - specular bump computations - *
  56.  
  57.                     add  r2, c[90],-v0    // wector pointing from vertex to viewer                    
  58.  
  59.                     dp3  r2.w, r2, r2        // normalize pointing
  60.                     rsq  r2.w, r2.w            // wector.
  61.                     mul  r2,   r2, r2.w
  62.  
  63.                     add  r3, r2, c[92]    // now, H = Light + pointingVector
  64.                     
  65.                     // transform H-vector by basis vectors
  66.  
  67.                     dp3  r1.x, v5.xyz, r3
  68.                     dp3  r1.y, r0.xyz, r3
  69.                     dp3  r1.z, v1.xyz, r3
  70.  
  71.                     dp3  r1.w, r1, r1    // we must
  72.                     rsq  r1.w, r1.w        // also normalize
  73.                     mul  r1,   r1, r1.w    // H vector
  74.  
  75.                     // emit H vector                    
  76.                     add  r1, r1, c[91].y
  77.                     mul  r1,r1,c[91].w
  78.                     mov     oD1, r1
  79.                     
  80.                     // * - emit coordinates for textures - *
  81.  
  82.                     mov  oT0, v4                // emit uv mapping
  83.                     mov  oT1, v4                // emit coordinates for bump map
  84.                 };
  85.  
  86. pixelshader psDAFS64Mpass0 = 
  87.         asm
  88.         {
  89.             ps.1.1
  90.             
  91.             tex t0                        // normal map
  92.  
  93.             // specular component
  94.             dp3_sat    t0,t0_bx2,v1_bx2;        // t0=Dot(normal,interp_H)
  95.             mul t0,t0,t0                // power2
  96.             mul t0,t0,t0                // power4
  97.             mul t0,t0,t0                // power8
  98.             mul t0,t0,t0                // power16
  99.             mul t0,t0,t0                // power32
  100.             mul t0,t0,c3                // modulate brightness
  101.             mul r0,c4.a,t0
  102.         };
  103.  
  104. pixelshader psDAFS64Mpass1 = 
  105.         asm
  106.         {
  107.             ps.1.1
  108.             
  109.             tex t0                        // normal map
  110.             tex t1                        // base texture
  111.  
  112.             // diffuse component
  113.             dp3_sat    r1,t0_bx2,v0_bx2    // r1=Dot(normal,interp_light)
  114.  
  115.             mad r1,r1,c2,c1                // r1 = r1*diffColor+averagedAmbient
  116.             add r1.rgb,r1,c4
  117.             mul r0,r1,t1                // modulate with base texture            
  118.             mov r1,c4
  119.             lrp r0,r1.a,r0,c0
  120.             
  121.         };
  122.  
  123.  
  124.  
  125.  
  126. technique tDAFS64M
  127. {
  128.     pass p0
  129.     {    
  130.         AlphaBlendEnable = False;
  131.         FogEnable = False;
  132.         CullMode = CW;
  133.         PixelShaderConstant[0]    =    <vFogColor>;
  134.         PixelShaderConstant[1]    =    <vAmbientLightColor>;
  135.         PixelShaderConstant[2]    =    <vDiffuseLightColor>;
  136.         PixelShaderConstant[3]    =   <vSpecularColorAndPower>;
  137.         PixelShaderConstant[4]    =   <vLocalAmbientAndFogFactor>;
  138.         
  139.         VertexShaderConstant[92] = <vDiffuseDirection>;
  140.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0039 , 0.5 };
  141.         VertexShaderConstant[90] = <vViewerPosition>;
  142.  
  143.  
  144.         VertexShader    =    <vsDAS>;
  145.         PixelShader        =    <psDAFS64Mpass0>;
  146.     }
  147.  
  148.     pass p1
  149.     {    
  150.  
  151.         AlphaBlendEnable = TRUE;
  152.         FogEnable         = False;
  153.         SrcBlend         = One;
  154.         DestBlend         = One;
  155.         CullMode = CW;
  156.  
  157.         PixelShaderConstant[0]    =    <vFogColor>;
  158.         PixelShaderConstant[1]    =    <vAmbientLightColor>;
  159.         PixelShaderConstant[2]    =    <vDiffuseLightColor>;
  160.         PixelShaderConstant[3]    =   <vSpecularColorAndPower>;
  161.         PixelShaderConstant[4]    =   <vLocalAmbientAndFogFactor>;
  162.  
  163.         VertexShaderConstant[92] = <vDiffuseDirection>;
  164.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0039 , 0.5 };
  165.         VertexShaderConstant[90] = <vViewerPosition>;
  166.  
  167.         VertexShader    =    <vsDAS>;
  168.         PixelShader        =    <psDAFS64Mpass1>;
  169.     }
  170. }
  171.  
  172. technique test
  173. {
  174.     pass p0
  175.     {    
  176.         AlphaBlendEnable = False;
  177.         FogEnable = False;
  178.         CullMode = CW;
  179.         PixelShaderConstant[0]    =    <vFogColor>;
  180.         PixelShaderConstant[1]    =    <vAmbientLightColor>;
  181.         PixelShaderConstant[2]    =    <vDiffuseLightColor>;
  182.         PixelShaderConstant[3]    =   <vSpecularColorAndPower>;
  183.         PixelShaderConstant[4]    =   <vLocalAmbientAndFogFactor>;
  184.         
  185.         VertexShaderConstant[92] = <vDiffuseDirection>;
  186.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0039 , 0.0 };
  187.         VertexShaderConstant[90] = <vViewerPosition>;
  188.  
  189.  
  190.         VertexShader    =    <vsDAS>;
  191.         PixelShader        =    <psDAFS64Mpass0>;
  192.     }
  193. }
  194.  
  195. technique tHierSpecPP_5th
  196. {
  197.     pass p0
  198.     {    
  199.         AlphaBlendEnable = False;
  200.         FogEnable = False;
  201.         CullMode = CW;
  202.         
  203.         VertexShaderConstant[92] = <vLocalSpaceLightVector>;
  204.         VertexShaderConstant[91] = { 0.0 , 1.0 , 0.0039 , 0.0 };
  205.  
  206.         VertexShader    =    <vsDAS>;
  207.  
  208.     }
  209. }
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.