home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2006 January / PCA126_DVD.iso / TRIAL / FPSCreator / Files / effectbank / fastbone / fastbone.fx
Encoding:
Text File  |  2005-07-01  |  2.9 KB  |  125 lines

  1. //
  2. // Fast Bone
  3. //
  4.  
  5. /************* UNTWEAKABLES **************/
  6.  
  7. float4x4 WorldIT : WorldInverseTranspose;
  8. float4x4 WorldViewProj : WorldViewProjection;
  9. float4x4 World : World;
  10. float4x4 ViewInv : ViewInverse;
  11.  
  12. /*********** DBPRO UNTWEAKABLES **********/
  13. float4x4 boneMatrix[32] : BoneMatrixPalette;
  14.  
  15. /************* SURFACE **************/
  16.  
  17. float4 lhtDir < string UIDirectional = "Light Direction"; >; 
  18.  
  19. float4 LightPos : Position
  20. <
  21.     string UIObject = "PointLight";
  22.     string Space = "World";
  23. > = {100.0f, 100.0f, -100.0f, 0.0f};
  24.  
  25. float4 LightColor
  26. <
  27.     string UIType = "Color";
  28. > = {0.75f, 0.75f, 0.75f, 1.0f};
  29.  
  30. float4 AmbiColor : Ambient
  31. <
  32.     string UIName =  "Ambient Light Color";
  33. > = {0.01f, 0.01f, 0.01f, 1.0f};
  34.  
  35. float4 SurfColor : Diffuse
  36. <
  37.     string UIName =  "Surface Color";
  38.     string UIType = "Color";
  39. > = {1.0f, 1.0f, 1.0f, 1.0f};
  40.  
  41. /************* TEXTURES **************/
  42.  
  43. texture colorTexture : DiffuseMap
  44. <
  45.     string Name = "default_color.dds";
  46.     string type = "2D";
  47. >;
  48.  
  49. sampler2D colorSampler = sampler_state
  50. {
  51.     Texture = <colorTexture>;
  52.     MinFilter = Linear;
  53.     MagFilter = Linear;
  54.     MipFilter = Linear;
  55. };
  56.  
  57. /************* DATA STRUCTS **************/
  58.  
  59. struct appdata {
  60.     float3 Position    : POSITION;
  61.     float4 UV        : TEXCOORD0;
  62.     float4 Normal    : NORMAL;
  63.     float4 Blendweight    : TEXCOORD1;
  64.     float4 Blendindices    : TEXCOORD2;
  65. };
  66.  
  67. /* data passed from vertex shader to pixel shader */
  68. struct vertexOutput {
  69.     float4 HPosition    : POSITION;
  70.     float4 TexCoord    : TEXCOORD0;
  71.     float4 Col        : COLOR;
  72. };
  73.  
  74. /*********** vertex shader ******/
  75.  
  76. vertexOutput mainVS(appdata IN)
  77. {
  78.     vertexOutput OUT;
  79.     float3 netPosition = 0, netNormal = 0;
  80.     for (int i = 0; i < 4; i++)
  81.     {
  82.      float index = IN.Blendindices[i];
  83.      float3x4 model = float3x4(boneMatrix[index][0], boneMatrix[index][1], boneMatrix[index][2]);
  84.      float3 vec3 = mul(model, float4(IN.Position, 1));
  85.      vec3 = vec3 + boneMatrix[index][3].xyz;
  86.      float3x3 rotate = float3x3(model[0].xyz, model[1].xyz, model[2].xyz); 
  87.      float3 norm3 = mul(rotate, IN.Normal);
  88.      netPosition += vec3.xyz * IN.Blendweight[i];
  89.      netNormal += norm3.xyz * IN.Blendweight[i];
  90.     }
  91.     float4 tempPos = float4(netPosition,1.0);
  92.     netNormal = normalize(netNormal);
  93.  
  94.     float3 worldSpacePos = mul(tempPos, World).xyz;
  95.     OUT.TexCoord = IN.UV;
  96.     OUT.HPosition = mul(tempPos, WorldViewProj);
  97.  
  98.     float3 L = -lhtDir;
  99.     float4 gogo;
  100.     gogo = (max(0, dot(netNormal, L))*SurfColor*0.25) + (SurfColor*0.75) + AmbiColor;
  101.     gogo.w=1;
  102.     OUT.Col = gogo;
  103.  
  104.     return OUT;
  105. }
  106.  
  107. float4 PS(
  108.     float4 Diff : COLOR0,
  109.     float2 Tex  : TEXCOORD0) : COLOR
  110. {
  111.     return tex2D(colorSampler, Tex) * Diff;
  112. }
  113.  
  114. /****** technique *******/
  115.  
  116. technique dx9textured
  117. {
  118.     pass p0 
  119.     {        
  120.             Sampler[0] = (colorSampler);
  121.         VertexShader = compile vs_2_0 mainVS();
  122.             PixelShader  = compile ps_1_0 PS();
  123.     }
  124. }
  125.