home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 January / Gamestar_69_2005-01_dvd.iso / Dema / mortyr2_demo.exe / {app} / effects / bumped_specular.fx < prev    next >
Encoding:
Text File  |  2004-09-08  |  3.5 KB  |  181 lines

  1.  
  2. vector lhtR;    // kierunek swiatla, dla zgodnosci (tu nie uzywam)
  3. vector lPos;    // pozycja swiatla (we wspolrzednych mesha!)
  4. vector vCPS;    // pozycja kamery (w swiecie)
  5. vector lCol;    // kolor swiatla odbicia (dla dot3s)
  6.  
  7. matrix mWld;    // World
  8. matrix mTot;    // Total
  9.  
  10. texture tDif;   // Tekstura glowna
  11. texture tDf3;   // Normal map
  12.  
  13. vector lAmb;    // kolor ambientu
  14.  
  15. vector sDir; // sky dir
  16. vector sCol; // sky col
  17.  
  18.  
  19.  
  20. technique tec0
  21.  pass p0
  22.  {
  23.   ZBias=0;
  24.   CullMode=ccw;
  25.  
  26.   Texture[0] = <tDif>;
  27.  
  28.   ColorOp[0] = Modulate;
  29.         
  30.   ColorArg1[0] = Diffuse;
  31.   ColorArg2[0] = Texture;
  32.  
  33.   AlphaOp[0]=Disable;
  34.  
  35.   ColorOp[1]=Disable;
  36.   AlphaOp[1]=Disable;
  37.  
  38.   PixelShader  = NULL;
  39.   VertexShader = XYZ | Normal | Tex3;
  40.  }
  41.  
  42.  
  43.  pass p1
  44.  {
  45.   AlphaBlendEnable = true;
  46.   SrcBlend = One;
  47.   DestBlend = One;
  48.   BlendOp=Add;
  49.   ZBias=1;
  50.  
  51.  
  52.   VertexShaderConstant[0] = <mWld>;     // World Matrix
  53.   VertexShaderConstant[4] = <mTot>;    // World*View*Proj Matrix
  54.   VertexShaderConstant[9] = (1.0f, 1.0f, 1.0f, 1.0f);    // diffuse
  55.   VertexShaderConstant[10] = (1.0f, 1.0f, 1.0f, 1.0f);    // specular
  56.   VertexShaderConstant[11] = (0.0f, 0.0f, 0.0f, 0.0f);    // zero
  57.   VertexShaderConstant[12] = (1.0f, 1.0f, 1.0f, 1.0f);    // jeden
  58.   VertexShaderConstant[16] = <sDir>;    // Light direction
  59.   vertexShaderConstant[15] = (740.0f, 740.0f, 740.0f, 740.0f);
  60.   VertexShaderConstant[17] = <sCol>;    // light color
  61.   VertexShaderConstant[18] = <lAmb>;
  62.   vertexShaderConstant[19] = (1024.0f, 1024.0f, 1024.0f, 1024.0f);
  63.   vertexShaderConstant[20] = (.5f,.5f,.5f,.5f);
  64.   VertexShaderConstant[21] = <lhtR>;    // sky dir
  65.   VertexShaderConstant[22] = <lCol>;    // sky col
  66. //  VertexShaderConstant[23] = <lPos>;    // light position
  67.   VertexShaderConstant[24] = <vCPS>;    // camera position
  68.  
  69.   Texture[0]   = <tDif>;
  70.   Texture[1]   = <tDf3>;
  71.  
  72.   VertexShader = 
  73.   decl
  74.   {
  75.    stream 0;
  76.    float v0[3]; //Position
  77.    float v3[3]; //Normal
  78.    float v7[2]; //Texture Coord1
  79.    float v8[2]; //Tangent
  80.    float v9[2]; //Tangent
  81.   }   
  82.   asm 
  83.   {
  84.    vs.1.1              
  85.    m4x4 oPos, v0, c4  
  86.    m4x4 r0,v0,c0      
  87.  
  88.    // chce odleglosc od kamery
  89.    add r5, -r0, c24
  90.    dp3 r10.x, r5.xyz, r5.xyz // kwadrat odleglosci
  91.  
  92.    // odwrotnosc
  93.    rsq r10.x, r10.x
  94.    mul r10.x, r10.x, c15.x
  95.  
  96.            
  97.    // puszczam dalej
  98.    add r0,-r0,c24     
  99.  
  100.    dp3 r11.x,r0.xyz,r0.xyz   
  101.    rsq r11.xyz,r11.x         
  102.    mul r0.xyz,r0.xyz,r11.xyz 
  103.  
  104.    add r2.xyz,r0.xyz,-c16    
  105.     
  106.    // Normalize
  107.    dp3 r11.x,r2.xyz,r2.xyz   
  108.    rsq r11.xyz,r11.x         
  109.    mul r2.xyz,r2.xyz,r11.xyz 
  110.  
  111.    m3x3 r1,v3,c0             
  112.         
  113.    dp3  r3.xyzw,r1,r2
  114.  
  115.    mul r3,r3,r3 //  2nd
  116.    mul r3,r3,r3 //  4th
  117.    mul r3,r3,r3 //  8th
  118.    mul r3,r3,r3 // 16th
  119.  
  120.    dp3 r4,r1,-c16
  121.       
  122.  
  123.    mul r4,r4,c10   // Specular
  124.    mad r4,r3,c20,r4 // Diffuse
  125.  
  126.  
  127.    mov oD0, r4      
  128.  
  129.    mov oD1, r10.x
  130.  
  131.  
  132.    //
  133.    // wspolrzedne tekstur
  134.    //
  135.    mov oT0.xy,v7.xy
  136.    mov oT1.xy,v7.xy
  137.   };
  138.  
  139.   PixelShader = 
  140.   asm
  141.   {
  142.    ps.1.1
  143.    tex t0 // tekstura podstawowa
  144.    tex t1 // normal map
  145.  
  146.    dp3 r0,t1_bx2,v0_bx2; // bump ze specularem
  147.  
  148.    mul r0, r0, t0.a // i na maske! (tekstura z diffuse w 1 pasie)
  149.    mul r0, r0, v1
  150.  
  151.   };     
  152.  }
  153. }
  154.  
  155.  
  156. technique tec1
  157.  pass p0
  158.  {
  159.   ZBias=0;
  160.  
  161.   Texture[0] = <tDif>;
  162.  
  163.   ColorOp[0] = Modulate;
  164.         
  165.   ColorArg1[0] = Diffuse;
  166.   ColorArg2[0] = Texture;
  167.  
  168.   AlphaOp[0]=Disable;
  169.  
  170.   ColorOp[1]=Disable;
  171.   AlphaOp[1]=Disable;
  172.  
  173.   PixelShader  = NULL;
  174.   VertexShader = XYZ | Normal | Tex3;
  175.  }
  176.  
  177. }
  178.  
  179.