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.

145 lines
4.1 KiB

  1. #include "macros.vsh"
  2. sub VertexLitGeneric
  3. {
  4. local( $detail ) = shift;
  5. local( $envmap ) = shift;
  6. local( $envmapcameraspace ) = shift;
  7. local( $envmapsphere ) = shift;
  8. local( $decal ) = shift;
  9. local( $worldPos, $worldNormal, $projPos );
  10. local( $reflectionVector );
  11. ;------------------------------------------------------------------------------
  12. ; Vertex blending
  13. ;------------------------------------------------------------------------------
  14. &AllocateRegister( \$worldPos );
  15. &AllocateRegister( \$worldNormal );
  16. &AllocateRegister( \$projPos );
  17. ; if( $g_staticLightType eq "static" && $g_ambientLightType eq "none" &&
  18. ; $g_localLightType1 eq "none" && $g_localLightType2 eq "none" && !$envmap )
  19. if( 0 )
  20. {
  21. ; NOTE: Don't do this optimization anymore since it would mean a gazillion combos
  22. ; of the flashlight shaders
  23. ; Special case for static prop lighting. We can go directly from
  24. ; world to proj space for position, with the exception of z, which
  25. ; is needed for fogging *if* height fog is enabled.
  26. ; NOTE: We don't use this path if $envmap is defined since we need
  27. ; worldpos for envmapping.
  28. dp4 $projPos.x, $vPos, $cModelViewProj0
  29. dp4 $projPos.y, $vPos, $cModelViewProj1
  30. dp4 $projPos.z, $vPos, $cModelViewProj2
  31. dp4 $projPos.w, $vPos, $cModelViewProj3
  32. ; normal
  33. dp3 $worldNormal.x, $vNormal, $cModel0
  34. dp3 $worldNormal.y, $vNormal, $cModel1
  35. dp3 $worldNormal.z, $vNormal, $cModel2
  36. ; Need this for height fog if it's enabled and for height clipping
  37. dp4 $worldPos.z, $vPos, $cModel2
  38. }
  39. else
  40. {
  41. &SkinPositionAndNormal( $worldPos, $worldNormal );
  42. if( $SKINNING == 1 )
  43. {
  44. &Normalize( $worldNormal );
  45. }
  46. ;------------------------------------------------------------------------------
  47. ; Transform the position from world to view space
  48. ;------------------------------------------------------------------------------
  49. dp4 $projPos.x, $worldPos, $cViewProj0
  50. dp4 $projPos.y, $worldPos, $cViewProj1
  51. dp4 $projPos.z, $worldPos, $cViewProj2
  52. dp4 $projPos.w, $worldPos, $cViewProj3
  53. }
  54. mov oPos, $projPos
  55. ;------------------------------------------------------------------------------
  56. ; Fog
  57. ;------------------------------------------------------------------------------
  58. &CalcFog( $worldPos, $projPos );
  59. &FreeRegister( \$projPos );
  60. ;------------------------------------------------------------------------------
  61. ; Lighting
  62. ;------------------------------------------------------------------------------
  63. &DoLighting( $worldPos, $worldNormal );
  64. if( !$envmap )
  65. {
  66. &FreeRegister( \$worldNormal );
  67. }
  68. ;------------------------------------------------------------------------------
  69. ; Texture coordinates
  70. ;------------------------------------------------------------------------------
  71. dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
  72. dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
  73. if( $envmap )
  74. {
  75. if( $envmapcameraspace )
  76. {
  77. &AllocateRegister( \$reflectionVector );
  78. &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
  79. ; transform reflection vector into view space
  80. dp3 oT1.x, $reflectionVector, $cViewModel0
  81. dp3 oT1.y, $reflectionVector, $cViewModel1
  82. dp3 oT1.z, $reflectionVector, $cViewModel2
  83. &FreeRegister( \$reflectionVector );
  84. }
  85. elsif( $envmapsphere )
  86. {
  87. &AllocateRegister( \$reflectionVector );
  88. &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
  89. &ComputeSphereMapTexCoords( $reflectionVector, "oT1" );
  90. &FreeRegister( \$reflectionVector );
  91. }
  92. else
  93. {
  94. &ComputeReflectionVector( $worldPos, $worldNormal, "oT1" );
  95. }
  96. ; envmap mask
  97. dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
  98. dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
  99. &FreeRegister( \$worldNormal );
  100. }
  101. else
  102. {
  103. if ( $decal )
  104. {
  105. &AllocateRegister( \$temp );
  106. mov $temp, $vTexCoord0
  107. sub oT1.xyz, $temp.xyz, $vTexCoord1.xyz
  108. sub oT2.xyz, $vTexCoord2.xyz, $temp.xyz
  109. &FreeRegister( \$temp );
  110. }
  111. else
  112. {
  113. ; YUCK! This is to make texcoords continuous for mat_softwaretl
  114. mov oT1, $cZero
  115. mov oT2, $cZero
  116. }
  117. }
  118. if( $detail )
  119. {
  120. dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
  121. dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
  122. }
  123. &FreeRegister( \$worldPos );
  124. }