Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.1 KiB

  1. vs.1.1
  2. #include "macros.vsh"
  3. # DYNAMIC: "DOWATERFOG" "0..1"
  4. ;------------------------------------------------------------------------------
  5. ; The cable equation is:
  6. ; [L dot N] * C * T
  7. ;
  8. ; where:
  9. ; C = directional light color
  10. ; T = baseTexture
  11. ; N = particle normal (stored in the normal map)
  12. ; L = directional light direction
  13. ;
  14. ; $SHADER_SPECIFIC_CONST_0 = Directional light direction
  15. ;------------------------------------------------------------------------------
  16. ;------------------------------------------------------------------------------
  17. ; Transform position from object to projection space
  18. ;------------------------------------------------------------------------------
  19. &AllocateRegister( \$projPos );
  20. dp4 $projPos.x, $vPos, $cModelViewProj0
  21. dp4 $projPos.y, $vPos, $cModelViewProj1
  22. dp4 $projPos.z, $vPos, $cModelViewProj2
  23. dp4 $projPos.w, $vPos, $cModelViewProj3
  24. mov oPos, $projPos
  25. ;------------------------------------------------------------------------------
  26. ; Fog
  27. ;------------------------------------------------------------------------------
  28. alloc $worldPos
  29. if( $DOWATERFOG == 1 )
  30. {
  31. ; Get the worldpos z component only since that's all we need for height fog
  32. dp4 $worldPos.z, $vPos, $cModel2
  33. }
  34. &CalcFog( $worldPos, $projPos );
  35. free $worldPos
  36. &FreeRegister( \$projPos );
  37. ;------------------------------------------------------------------------------
  38. ; Setup the tangent space
  39. ;------------------------------------------------------------------------------
  40. &AllocateRegister( \$tmp1 );
  41. &AllocateRegister( \$tmp2 );
  42. &AllocateRegister( \$tmp3 );
  43. &AllocateRegister( \$r );
  44. ; Get S crossed with T (call it R)
  45. mov $tmp1, $vTangentS
  46. mov $tmp2, $vTangentT
  47. mul $tmp3, $vTangentS.yzxw, $tmp2.zxyw
  48. mad $r, -$vTangentS.zxyw, $tmp2.yzxw, $tmp3
  49. &FreeRegister( \$tmp2 );
  50. &FreeRegister( \$tmp3 );
  51. &AllocateRegister( \$s );
  52. ; Normalize S (into $s)
  53. dp3 $s.w, $vTangentS, $vTangentS
  54. rsq $s.w, $s.w
  55. mul $s.xyz, $vTangentS, $s.w
  56. ; Normalize R (into $r)
  57. dp3 $r.w, $r, $r
  58. rsq $r.w, $r.w
  59. mul $r.xyz, $r, $r.w
  60. &AllocateRegister( \$t );
  61. ; Regenerate T (into $t)
  62. mul $t, $r.yzxw, $tmp1.zxyw
  63. mad $t, -$r.zxyw, $tmp1.yzxw, $t
  64. &FreeRegister( \$tmp1 );
  65. ;------------------------------------------------------------------------------
  66. ; Transform the light direction (into oD1)
  67. ;------------------------------------------------------------------------------
  68. &AllocateRegister( \$lightDirection );
  69. dp3 $lightDirection.x, $s, $SHADER_SPECIFIC_CONST_0
  70. dp3 $lightDirection.y, $t, $SHADER_SPECIFIC_CONST_0
  71. dp3 $lightDirection.z, $r, $SHADER_SPECIFIC_CONST_0
  72. &FreeRegister( \$r );
  73. &FreeRegister( \$s );
  74. &FreeRegister( \$t );
  75. ; Scale into 0-1 range (we're assuming light direction was normalized prior to here)
  76. add oT2, $lightDirection, $cHalf ; + 0.5
  77. &FreeRegister( \$lightDirection );
  78. ;------------------------------------------------------------------------------
  79. ; Copy texcoords for the normal map and base texture
  80. ;------------------------------------------------------------------------------
  81. mov oT0, $vTexCoord0
  82. mov oT1, $vTexCoord1
  83. ; Pass the dirlight color through
  84. mov oD0.xyzw, $vColor