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
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "BaseVSShader.h"
  7. #include "lightmappedgeneric_vs11.inc"
  8. #include "lightmappedgeneric_decal.inc"
  9. #include "mathlib/bumpvects.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8 )
  13. BEGIN_VS_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8, "" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 )
  16. SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" )
  17. SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT_PARAMS()
  20. {
  21. // FLASHLIGHTFIXME
  22. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  23. SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE );
  24. SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
  25. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  26. }
  27. SHADER_FALLBACK
  28. {
  29. if ( IsPC() && ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) )
  30. {
  31. return "DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6";
  32. }
  33. return 0;
  34. }
  35. SHADER_INIT
  36. {
  37. LoadTexture( FLASHLIGHTTEXTURE );
  38. LoadTexture( BASETEXTURE );
  39. LoadTexture( SELFILLUMTEXTURE );
  40. }
  41. void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow )
  42. {
  43. if( IsSnapshotting() )
  44. {
  45. pShaderShadow->EnableDepthWrites( false );
  46. pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
  47. pShaderShadow->EnableBlending( true );
  48. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  49. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  50. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  51. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  53. int pTexCoords[3] = { 2, 2, 1 };
  54. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 );
  55. lightmappedgeneric_decal_Static_Index vshIndex;
  56. pShaderShadow->SetVertexShader( "LightmappedGeneric_Decal", vshIndex.GetIndex() );
  57. pShaderShadow->SetPixelShader( "LightmappedGeneric_Decal" );
  58. FogToFogColor();
  59. }
  60. else
  61. {
  62. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  63. // Load the z^2 components of the lightmap coordinate axes only
  64. // This is (N dot basis)^2
  65. Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z );
  66. vecZValues *= vecZValues;
  67. Vector4D basis[3];
  68. basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f );
  69. basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f );
  70. basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f );
  71. pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 );
  72. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED );
  73. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  74. SetModulationPixelShaderDynamicState( 3 );
  75. lightmappedgeneric_decal_Dynamic_Index vshIndex;
  76. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  77. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  78. }
  79. Draw();
  80. if( IsSnapshotting() )
  81. {
  82. SetInitialShadowState( );
  83. pShaderShadow->EnableDepthWrites( false );
  84. pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL );
  85. pShaderShadow->EnableBlending( true );
  86. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  87. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  88. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 );
  89. lightmappedgeneric_vs11_Static_Index vshIndex;
  90. vshIndex.SetDETAIL( false );
  91. vshIndex.SetENVMAP( false );
  92. vshIndex.SetENVMAPCAMERASPACE( false );
  93. vshIndex.SetENVMAPSPHERE( false );
  94. vshIndex.SetVERTEXCOLOR( false );
  95. pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() );
  96. pShaderShadow->SetPixelShader( "DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11" );
  97. FogToFogColor();
  98. }
  99. else
  100. {
  101. BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME );
  102. lightmappedgeneric_vs11_Dynamic_Index vshIndex;
  103. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  104. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  105. }
  106. Draw();
  107. }
  108. SHADER_DRAW
  109. {
  110. if( UsingFlashlight( params ) )
  111. {
  112. DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1,
  113. FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 );
  114. }
  115. else
  116. {
  117. DrawDecal( params, pShaderAPI, pShaderShadow );
  118. }
  119. }
  120. END_SHADER