home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / basic3d / fx / aniso / Aniso.fx next >
Encoding:
Text File  |  2004-09-22  |  2.3 KB  |  114 lines

  1. //
  2. // Aniso
  3. //
  4.  
  5. string Category = "Effects\\Lighting";
  6. string keywords = "aniso,dx8,assembler,fixed function,pointlight";
  7. string description = "Using a texture for BRDF in DX8. No pixel shader! Prog in vs1.1 assembler";
  8.  
  9. // un-tweakables
  10.  
  11. float4x4 worldITa : WorldIT;
  12. float4x4 wvp : WorldViewProjection;
  13. float4x4 worlda : World;
  14. float4x4 viewIT : ViewIT;
  15.  
  16. // tweakables
  17.  
  18. float4 lightPos : Position
  19. <
  20.     string Object = "PointLight";
  21.     string Space = "World";
  22. > = { 100.0f, 100.0f, 100.0f, 0.0f };
  23.  
  24. texture anisoTexture
  25. <
  26.      string File = "aniso2.dds";
  27.      string TextureType = "2D";
  28. >;
  29.  
  30. ///////////////////////
  31.  
  32. technique Aniso
  33. {
  34.     pass p0
  35.     {
  36.         VertexShaderConstant[0] = <wvp>;
  37.         VertexShaderConstant[4] = <worldITa>;
  38.         VertexShaderConstant[8] = <worlda>;
  39.         VertexShaderConstant[12] = <lightPos>;
  40.         VertexShaderConstant[16] = <viewIT>;
  41.  
  42.         VertexShader = 
  43.         asm
  44.         {
  45.             vs.1.1
  46.             // Transform pos to screen space.
  47.             m4x4 oPos, v0, c0
  48.             
  49.             // Normal to world space:
  50.             dp3 r0.x, v3, c8
  51.             dp3 r0.y, v3, c9
  52.             dp3 r0.z, v3, c10
  53.  
  54.             // normalize normal
  55.             dp3 r0.w, r0, r0
  56.             rsq r0.w, r0.w
  57.             mul r0, r0, r0.w            // r0 has normalized normal.
  58.             
  59.             // vpos to world space.
  60.             dp4 r1.x, v0, c8
  61.             dp4 r1.y, v0, c9
  62.             dp4 r1.z, v0, c10
  63.             dp4 r1.w, v0, c11            // r1 has position in world space.
  64.  
  65.             // eye vector, normalize.
  66.             add r2, c19, -r1
  67.             dp3 r2.w, r2, r2
  68.             rsq r2.w, r2.w
  69.             mul r2, r2, r2.w            // r2 has normalized eye vector in world space.
  70.             
  71.             // light vector, normalize
  72.             add r3, c12, -r1
  73.             dp3 r3.w, r3, r3
  74.             rsq r3.w, r3.w
  75.             mul r3, r3, r3.w            // r3 has normalized light vector in world space.
  76.  
  77.             // half-angle direction.
  78.             add r1, r2, r3
  79.  
  80.             // normalize h
  81.             dp3 r1.w, r1, r1
  82.             rsq r1.w, r1.w
  83.             mul r1, r1, r1.w
  84.  
  85.             // L dot N.
  86.             dp3 oT0.x, r3, r0
  87.  
  88.             // h dot N
  89.             dp3 oT0.y, r1, r0
  90.         };
  91.  
  92.         ZEnable = true;
  93.         ZWriteEnable = true;
  94.         AlphaBlendEnable = false;
  95.         CullMode = None;
  96.         Lighting = false;
  97.  
  98.         Texture[0] = <anisoTexture>;
  99.         TexCoordIndex[0] = 0;
  100.         Target[0] = Texture2D;
  101.  
  102.         MinFilter[0] = Linear;
  103.         MagFilter[0] = Linear;
  104.         MipFilter[0] = None;
  105.  
  106.         AddressU[0] = Clamp;
  107.         AddressV[0] = Clamp;
  108.  
  109.         ColorOp[0] = Modulate4x;
  110.         ColorArg1[0] = Texture;
  111.         ColorArg2[0] = Texture|AlphaReplicate;
  112.     }
  113. }
  114.