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.

135 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Lightmap only shader
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "lightmappedgeneric_decal.inc"
  10. #include "mathlib/bumpvects.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. BEGIN_VS_SHADER( LightmappedGeneric_Decal,
  14. "Help for LightmappedGeneric_Decal" )
  15. BEGIN_SHADER_PARAMS
  16. END_SHADER_PARAMS
  17. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  18. SHADER_INIT_PARAMS()
  19. {
  20. if ( g_pHardwareConfig->SupportsBorderColor() )
  21. {
  22. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
  23. }
  24. else
  25. {
  26. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  27. }
  28. // No texture means no self-illum or env mask in base alpha
  29. if ( !params[BASETEXTURE]->IsDefined() )
  30. {
  31. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  32. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  33. }
  34. SET_FLAGS( MATERIAL_VAR_DECAL );
  35. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  36. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  37. }
  38. SHADER_FALLBACK
  39. {
  40. return 0;
  41. }
  42. SHADER_INIT
  43. {
  44. LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB );
  45. if (params[BASETEXTURE]->IsDefined())
  46. {
  47. LoadTexture( BASETEXTURE );
  48. if ( !params[BASETEXTURE]->GetTextureValue()->IsTranslucent() )
  49. {
  50. CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM );
  51. CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK );
  52. }
  53. }
  54. // Don't alpha test if the alpha channel is used for other purposes
  55. if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) )
  56. {
  57. CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST );
  58. }
  59. }
  60. void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow )
  61. {
  62. if( IsSnapshotting() )
  63. {
  64. // Be sure not to write to dest alpha
  65. pShaderShadow->EnableAlphaWrites( false );
  66. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  67. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  68. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  69. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  70. SetNormalBlendingShadowState( BASETEXTURE, true );
  71. int pTexCoords[3] = { 2, 2, 1 };
  72. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 );
  73. lightmappedgeneric_decal_Static_Index vshIndex;
  74. pShaderShadow->SetVertexShader( "LightmappedGeneric_Decal", vshIndex.GetIndex() );
  75. pShaderShadow->SetPixelShader( "LightmappedGeneric_Decal" );
  76. FogToFogColor();
  77. }
  78. else
  79. {
  80. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  81. // Load the z^2 components of the lightmap coordinate axes only
  82. // This is (N dot basis)^2
  83. Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z );
  84. vecZValues *= vecZValues;
  85. Vector4D basis[3];
  86. basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f );
  87. basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f );
  88. basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f );
  89. pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 );
  90. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED );
  91. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  92. SetModulationPixelShaderDynamicState( 3 );
  93. lightmappedgeneric_decal_Dynamic_Index vshIndex;
  94. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  95. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  96. }
  97. Draw();
  98. }
  99. SHADER_DRAW
  100. {
  101. if( UsingFlashlight( params ) )
  102. {
  103. DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1,
  104. FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 );
  105. }
  106. else
  107. {
  108. DrawDecal( params, pShaderAPI, pShaderShadow );
  109. }
  110. }
  111. END_SHADER