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.

142 lines
3.7 KiB

  1. #include "macros.vsh"
  2. ;------------------------------------------------------------------------------
  3. ; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform
  4. ; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform
  5. ; $SHADER_SPECIFIC_CONST_4-$SHADER_SPECIFIC_CONST_5 = Detail texture transform
  6. ;------------------------------------------------------------------------------
  7. sub UnlitGeneric
  8. {
  9. local( $detail ) = shift;
  10. local( $envmap ) = shift;
  11. local( $envmapcameraspace ) = shift;
  12. local( $envmapsphere ) = shift;
  13. local( $vertexcolor ) = shift;
  14. local( $separatedetailuvs ) = shift;
  15. local( $worldPos, $worldNormal, $projPos, $reflectionVector );
  16. ;------------------------------------------------------------------------------
  17. ; Vertex blending
  18. ;------------------------------------------------------------------------------
  19. &AllocateRegister( \$worldPos );
  20. if( $envmap )
  21. {
  22. &AllocateRegister( \$worldNormal );
  23. &SkinPositionAndNormal( $worldPos, $worldNormal );
  24. }
  25. else
  26. {
  27. &SkinPosition( $worldPos );
  28. }
  29. ;------------------------------------------------------------------------------
  30. ; Transform the position from world to proj space
  31. ;------------------------------------------------------------------------------
  32. &AllocateRegister( \$projPos );
  33. dp4 $projPos.x, $worldPos, $cViewProj0
  34. dp4 $projPos.y, $worldPos, $cViewProj1
  35. dp4 $projPos.z, $worldPos, $cViewProj2
  36. dp4 $projPos.w, $worldPos, $cViewProj3
  37. mov oPos, $projPos
  38. ;------------------------------------------------------------------------------
  39. ; Fog
  40. ;------------------------------------------------------------------------------
  41. &CalcFog( $worldPos, $projPos );
  42. &FreeRegister( \$projPos );
  43. if( !$envmap )
  44. {
  45. &FreeRegister( \$worldPos );
  46. }
  47. ;------------------------------------------------------------------------------
  48. ; Texture coordinates (use world-space normal for envmap, tex transform for mask)
  49. ;------------------------------------------------------------------------------
  50. dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
  51. dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
  52. if ( $g_x360 )
  53. {
  54. ; must write xyzw to match read in pixelshader
  55. mov oT0.zw, $cZero
  56. }
  57. if( $envmap )
  58. {
  59. if( $envmapcameraspace )
  60. {
  61. &AllocateRegister( \$reflectionVector );
  62. &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
  63. ; transform reflection vector into view space
  64. dp3 oT1.x, $reflectionVector, $cViewModel0
  65. dp3 oT1.y, $reflectionVector, $cViewModel1
  66. dp3 oT1.z, $reflectionVector, $cViewModel2
  67. if ( $g_x360 )
  68. {
  69. ; must write xyzw to match read in pixelshader
  70. mov oT1.w, $cZero
  71. }
  72. &FreeRegister( \$reflectionVector );
  73. }
  74. elsif( $envmapsphere )
  75. {
  76. &AllocateRegister( \$reflectionVector );
  77. &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
  78. &ComputeSphereMapTexCoords( $reflectionVector, "oT1" );
  79. &FreeRegister( \$reflectionVector );
  80. }
  81. else
  82. {
  83. &ComputeReflectionVector( $worldPos, $worldNormal, "oT1" );
  84. }
  85. ; envmap mask
  86. dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2
  87. dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3
  88. if ( $g_x360 )
  89. {
  90. ; must write xyzw to match read in pixelshader
  91. mov oT2.zw, $cZero
  92. }
  93. &FreeRegister( \$worldPos );
  94. &FreeRegister( \$worldNormal );
  95. }
  96. if( $detail )
  97. {
  98. if ( $separatedetailuvs )
  99. {
  100. mov oT3, $vTexCoord1
  101. }
  102. else
  103. {
  104. dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4
  105. dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5
  106. }
  107. if ( $g_x360 )
  108. {
  109. ; must write xyzw to match read in pixelshader
  110. mov oT3.zw, $cZero
  111. }
  112. }
  113. if( $vertexcolor )
  114. {
  115. ; Modulation color
  116. mul oD0, $vColor, $cModulationColor
  117. }
  118. else
  119. {
  120. ; Modulation color
  121. mov oD0, $cModulationColor
  122. }
  123. }