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.

168 lines
4.7 KiB

  1. vs.1.1
  2. # DYNAMIC: "DOWATERFOG" "0..1"
  3. ;------------------------------------------------------------------------------
  4. ; Constants specified by the app
  5. ; c0 = (0, 1, 2, 0.5)
  6. ; c1 = (1/2.2, 0, 0, 0)
  7. ; c2 = camera position *in world space*
  8. ; c4-c7 = modelViewProj matrix (transpose)
  9. ; c8-c11 = ViewProj matrix (transpose)
  10. ; c12-c15 = model->view matrix (transpose)
  11. ; c16 = [fogStart, fogEnd, fogRange, undefined]
  12. ;
  13. ; Vertex components (as specified in the vertex DECL)
  14. ; $vPos = Position
  15. ; $vTexCoord0.xy = TexCoord0
  16. ;------------------------------------------------------------------------------
  17. #include "macros.vsh"
  18. ; Vertex components
  19. ; $vPos = Position
  20. ; $vNormal = normal
  21. ; $vTexCoord0.xy = TexCoord0
  22. ; $vTangentS = S axis of Texture space
  23. ; $vTangentT = T axis of Texture space
  24. ;------------------------------------------------------------------------------
  25. ; Transform the position from world to view space
  26. ;------------------------------------------------------------------------------
  27. alloc $worldPos
  28. alloc $worldNormal
  29. alloc $worldTangentS
  30. alloc $worldTangentT
  31. alloc $projPos
  32. dp4 $projPos.x, $vPos, $cModelViewProj0
  33. dp4 $projPos.y, $vPos, $cModelViewProj1
  34. dp4 $projPos.z, $vPos, $cModelViewProj2
  35. dp4 $projPos.w, $vPos, $cModelViewProj3
  36. mov oPos, $projPos
  37. dp3 $worldPos.x, $vPos, $cModel0
  38. dp3 $worldPos.y, $vPos, $cModel1
  39. dp3 $worldPos.z, $vPos, $cModel2
  40. dp3 $worldNormal.x, $vNormal, $cModel0
  41. dp3 $worldNormal.y, $vNormal, $cModel1
  42. dp3 $worldNormal.z, $vNormal, $cModel2
  43. dp3 $worldTangentS.x, $vTangentS, $cModel0
  44. dp3 $worldTangentS.y, $vTangentS, $cModel1
  45. dp3 $worldTangentS.z, $vTangentS, $cModel2
  46. dp3 $worldTangentT.x, $vTangentT, $cModel0
  47. dp3 $worldTangentT.y, $vTangentT, $cModel1
  48. dp3 $worldTangentT.z, $vTangentT, $cModel2
  49. &CalcFog( $worldPos, $projPos );
  50. alloc $worldEyeVect
  51. ; Get the eye vector in world space
  52. add $worldEyeVect.xyz, -$worldPos, $cEyePos
  53. alloc $tangentEyeVect
  54. alloc $bumpTexCoord
  55. ; transform the eye vector to tangent space
  56. dp3 $tangentEyeVect.x, $worldEyeVect, $worldTangentS
  57. dp3 $tangentEyeVect.y, $worldEyeVect, $worldTangentT
  58. dp3 $tangentEyeVect.z, $worldEyeVect, $worldNormal
  59. &Normalize( $tangentEyeVect );
  60. ; stick the tangent space eye vector into oD0
  61. mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf
  62. dp4 $bumpTexCoord.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
  63. dp4 $bumpTexCoord.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
  64. ; dudv map
  65. mov oT0.xy, $bumpTexCoord
  66. ; refract tint
  67. mov oT3.xy, $bumpTexCoord
  68. free $bumpTexCoord
  69. alloc $newProjPos
  70. alloc $w
  71. mov oPos, $projPos
  72. ; special case perspective correct texture projection so that the texture fits exactly on the screen
  73. mul $projPos.y, $projPos.y, $SHADER_SPECIFIC_CONST_4.w
  74. add $projPos.xy, $projPos.xy, $projPos.w
  75. mul $projPos.xy, $projPos.xy, $cHalf
  76. ; Do the perspective divide here. .yuck . . we aren't going to be perspective correct
  77. rcp $w.w, $projPos.w
  78. mul $projPos, $projPos, $w.w
  79. #max $projPos.x, $projPos.x, -$cOne
  80. #min $projPos.x, $projPos.x, $cOne
  81. #max $projPos.z, $projPos.z, $cZero
  82. #min $projPos.z, $projPos.z, $cOne
  83. ;------------------------------------------------------------------------------
  84. ; Transform the tangentS from world to view space
  85. ;------------------------------------------------------------------------------
  86. alloc $projTangentS
  87. ; we only care about x and y
  88. dp3 $projTangentS.x, $worldTangentS, $cViewProj0
  89. dp3 $projTangentS.y, $worldTangentS, $cViewProj1
  90. ; project tangentS
  91. mul $projTangentS.xy, $projTangentS.xy, $w.w
  92. ;max $projTangentS.xy, $projTangentS.xy, $cOne
  93. ;min $projTangentS.xy, $projTangentS.xy, -$cOne
  94. ;------------------------------------------------------------------------------
  95. ; Transform the tangentT from world to view space
  96. ;------------------------------------------------------------------------------
  97. alloc $projTangentT
  98. alloc $texCoord
  99. ; we only care about x and y
  100. dp3 $projTangentT.x, $worldTangentT, $cViewProj0
  101. dp3 $projTangentT.y, $worldTangentT, $cViewProj1
  102. ; project tangentT
  103. mul $projTangentT.xy, $projTangentT.xy, $w.w
  104. ;max $projTangentT.xy, $projTangentT.xy, $cOne
  105. ;min $projTangentT.xy, $projTangentT.xy, -$cOne
  106. ;max $projPos.xy, $projPos.xy, $cOne
  107. ;min $projPos.xy, $projPos.xy, -$cOne
  108. mul oT1.x, $projTangentS.x, $SHADER_SPECIFIC_CONST_3.x
  109. mul oT1.y, $projTangentT.x, $SHADER_SPECIFIC_CONST_3.x
  110. mov oT1.z, $projPos.x ; huh?
  111. mul $texCoord.x, $projTangentS.y, -$SHADER_SPECIFIC_CONST_3.x
  112. mul $texCoord.y, $projTangentT.y, -$SHADER_SPECIFIC_CONST_3.x
  113. mov $texCoord.z, $projPos.y
  114. mov oT2.xyz, $texCoord
  115. mov oT3.xyz, $texCoord
  116. free $texCoord
  117. free $projPos
  118. free $worldPos
  119. free $worldEyeVect
  120. free $tangentEyeVect
  121. free $w
  122. free $projTangentS
  123. free $projTangentT
  124. free $newProjPos
  125. free $worldNormal
  126. free $worldTangentS
  127. free $worldTangentT