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.

175 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "lightmappedgeneric_vs11.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( WorldTwoTextureBlend, WorldTwoTextureBlend_DX8 )
  13. BEGIN_VS_SHADER( WorldTwoTextureBlend_DX8,
  14. "Help for WorldTwoTextureBlend_DX8" )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "iris texture", 0 )
  17. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  18. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend_detail", "detail texture" )
  19. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "scale of the detail texture" )
  20. SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0",
  21. "If this is 1, then when detail alpha=0, no base texture is blended and when "
  22. "detail alpha=1, you get detail*base*lightmap" )
  23. END_SHADER_PARAMS
  24. SHADER_FALLBACK
  25. {
  26. if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 )
  27. return "WorldTwoTextureBlend_DX6";
  28. return 0;
  29. }
  30. SHADER_INIT
  31. {
  32. LoadTexture( FLASHLIGHTTEXTURE );
  33. if (params[BASETEXTURE]->IsDefined())
  34. {
  35. LoadTexture( BASETEXTURE );
  36. }
  37. if (params[DETAIL]->IsDefined())
  38. {
  39. LoadTexture( DETAIL );
  40. }
  41. }
  42. SHADER_INIT_PARAMS()
  43. {
  44. // FLASHLIGHTFIXME
  45. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  46. if( !params[SELFILLUMTINT]->IsDefined() )
  47. {
  48. params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  49. }
  50. if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() )
  51. {
  52. params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 );
  53. }
  54. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP );
  55. }
  56. const char *GetPixelShaderName( IMaterialVar** params, bool bHasBaseTexture, bool bHasDetailTexture )
  57. {
  58. bool bSelfIllum = IS_FLAG_SET(MATERIAL_VAR_SELFILLUM);
  59. if ( !bHasBaseTexture )
  60. {
  61. if ( !bHasDetailTexture )
  62. return "LightmappedGeneric_NoTexture";
  63. return "LightmappedGeneric_DetailNoTexture";
  64. }
  65. if ( !bHasDetailTexture )
  66. {
  67. if ( bSelfIllum )
  68. return "LightmappedGeneric_SelfIlluminated";
  69. return "LightmappedGeneric";
  70. }
  71. if ( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->GetIntValue() )
  72. {
  73. if ( bSelfIllum )
  74. return "WorldTwoTextureBlend_SelfIlluminated";
  75. return "WorldTwoTextureBlend";
  76. }
  77. return "WorldTwoTextureBlend_DetailAlpha";
  78. }
  79. SHADER_DRAW
  80. {
  81. bool hasFlashlight = UsingFlashlight( params );
  82. if( hasFlashlight )
  83. {
  84. DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1,
  85. FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 );
  86. return;
  87. }
  88. bool bHasBaseTexture = params[BASETEXTURE]->IsTexture();
  89. bool bHasDetailTexture = params[DETAIL]->IsTexture();
  90. bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  91. SHADOW_STATE
  92. {
  93. if ( bHasBaseTexture )
  94. {
  95. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  96. }
  97. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  98. if ( bHasDetailTexture )
  99. {
  100. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  101. }
  102. pShaderShadow->EnableBlending( false );
  103. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 );
  104. // Let the shaders do the fun stuff.
  105. lightmappedgeneric_vs11_Static_Index vshIndex;
  106. vshIndex.SetDETAIL( bHasDetailTexture );
  107. vshIndex.SetENVMAP( false );
  108. vshIndex.SetENVMAPCAMERASPACE( false );
  109. vshIndex.SetENVMAPSPHERE( false );
  110. vshIndex.SetVERTEXCOLOR( bHasVertexColor );
  111. pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() );
  112. const char *pPixelShaderName = GetPixelShaderName( params, bHasBaseTexture, bHasDetailTexture );
  113. pShaderShadow->SetPixelShader( pPixelShaderName );
  114. FogToFogColor();
  115. }
  116. DYNAMIC_STATE
  117. {
  118. if ( bHasBaseTexture )
  119. {
  120. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  121. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  122. }
  123. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  124. if ( bHasDetailTexture )
  125. {
  126. BindTexture( SHADER_SAMPLER2, DETAIL );
  127. SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURETRANSFORM, DETAILSCALE );
  128. }
  129. SetModulationVertexShaderDynamicState();
  130. // Dynamic vertex shader index.
  131. lightmappedgeneric_vs11_Dynamic_Index vshIndex;
  132. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  133. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  134. EnablePixelShaderOverbright( 0, true, true );
  135. SetPixelShaderConstant( 1, SELFILLUMTINT );
  136. }
  137. Draw();
  138. }
  139. END_SHADER