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.

110 lines
3.0 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 = Modulation color
  6. ;------------------------------------------------------------------------------
  7. sub LightmappedGeneric
  8. {
  9. local( $detail ) = shift;
  10. local( $envmap ) = shift;
  11. local( $envmapcameraspace ) = shift;
  12. local( $envmapsphere ) = shift;
  13. local( $vertexcolor ) = shift;
  14. local( $worldPos, $worldNormal, $projPos, $reflectionVector );
  15. &AllocateRegister( \$projPos );
  16. dp4 $projPos.x, $vPos, $cModelViewProj0
  17. dp4 $projPos.y, $vPos, $cModelViewProj1
  18. dp4 $projPos.z, $vPos, $cModelViewProj2
  19. dp4 $projPos.w, $vPos, $cModelViewProj3
  20. mov oPos, $projPos
  21. &AllocateRegister( \$worldPos );
  22. if( $DOWATERFOG == 1 )
  23. {
  24. ; Get the worldpos z component only since that's all we need for height fog
  25. dp4 $worldPos.z, $vPos, $cModel2
  26. }
  27. &CalcFog( $worldPos, $projPos );
  28. &FreeRegister( \$projPos );
  29. ;------------------------------------------------------------------------------
  30. ; Texture coordinates
  31. ;------------------------------------------------------------------------------
  32. ; base texcoords
  33. dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0
  34. dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1
  35. ; lightmap texcoords
  36. mov oT1, $vTexCoord1
  37. if( $envmap )
  38. {
  39. &AllocateRegister( \$worldNormal );
  40. ; Transform the position + normal to world space
  41. dp4 $worldPos.x, $vPos, $cModel0
  42. dp4 $worldPos.y, $vPos, $cModel1
  43. if( $DOWATERFOG ne 1 )
  44. {
  45. dp4 $worldPos.z, $vPos, $cModel2
  46. }
  47. dp3 $worldNormal.x, $vNormal, $cModel0
  48. dp3 $worldNormal.y, $vNormal, $cModel1
  49. dp3 $worldNormal.z, $vNormal, $cModel2
  50. if( $envmapcameraspace )
  51. {
  52. &AllocateRegister( \$reflectionVector );
  53. &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
  54. ; transform reflection vector into view space
  55. dp3 oT2.x, $reflectionVector, $cViewModel0
  56. dp3 oT2.y, $reflectionVector, $cViewModel1
  57. dp3 oT2.z, $reflectionVector, $cViewModel2
  58. &FreeRegister( \$reflectionVector );
  59. }
  60. elsif( $envmapsphere )
  61. {
  62. &AllocateRegister( \$reflectionVector );
  63. &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector );
  64. &ComputeSphereMapTexCoords( $reflectionVector, "oT2" );
  65. &FreeRegister( \$reflectionVector );
  66. }
  67. else
  68. {
  69. &ComputeReflectionVector( $worldPos, $worldNormal, "oT2" );
  70. }
  71. ; envmap mask
  72. dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 ; FIXME
  73. dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 ; FIXME
  74. # &FreeRegister( \$worldPos );
  75. &FreeRegister( \$worldNormal );
  76. }
  77. &FreeRegister( \$worldPos ); # garymcthack
  78. if( $detail )
  79. {
  80. dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 ; FIXME
  81. dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 ; FIXME
  82. }
  83. if( $vertexcolor )
  84. {
  85. ; Modulation color
  86. mul oD0, $vColor, $cModulationColor
  87. }
  88. else
  89. {
  90. ; Modulation color
  91. mov oD0, $cModulationColor
  92. }
  93. }