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.

148 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "BaseVSShader.h"
  9. #define USE_NEW_SHADER //Updating assembly shaders to fxc, this is for A/B testing.
  10. #ifdef USE_NEW_SHADER
  11. #include "unlitgeneric_vs20.inc"
  12. #include "unlitgeneric_ps20.inc"
  13. #include "unlitgeneric_ps20b.inc"
  14. #endif
  15. #include "unlitgeneric_vs11.inc"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. BEGIN_VS_SHADER_FLAGS( DebugNormalMap, "Help for DebugNormalMap", SHADER_NOT_EDITABLE )
  19. BEGIN_SHADER_PARAMS
  20. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldDiffuseBumpMap_bump", "bump map" )
  21. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  22. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  23. END_SHADER_PARAMS
  24. SHADER_INIT_PARAMS()
  25. {
  26. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  27. }
  28. SHADER_INIT
  29. {
  30. }
  31. SHADER_FALLBACK
  32. {
  33. if( g_pHardwareConfig->GetDXSupportLevel() < 80 )
  34. {
  35. // Assert( 0 );
  36. return "Wireframe";
  37. }
  38. return 0;
  39. }
  40. SHADER_DRAW
  41. {
  42. SHADOW_STATE
  43. {
  44. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  45. // Set stream format (note that this shader supports compression)
  46. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  47. int nTexCoordCount = 1;
  48. int userDataSize = 0;
  49. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  50. #ifdef USE_NEW_SHADER
  51. if( g_pHardwareConfig->GetDXSupportLevel() >= 90 )
  52. {
  53. DECLARE_STATIC_VERTEX_SHADER( unlitgeneric_vs20 );
  54. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, 0 );
  55. SET_STATIC_VERTEX_SHADER( unlitgeneric_vs20 );
  56. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  57. {
  58. DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps20b );
  59. SET_STATIC_PIXEL_SHADER( unlitgeneric_ps20b );
  60. }
  61. else
  62. {
  63. DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps20 );
  64. SET_STATIC_PIXEL_SHADER( unlitgeneric_ps20 );
  65. }
  66. }
  67. else
  68. #endif
  69. {
  70. unlitgeneric_vs11_Static_Index vshIndex;
  71. vshIndex.SetDETAIL( false );
  72. vshIndex.SetENVMAP( false );
  73. vshIndex.SetENVMAPCAMERASPACE( false );
  74. vshIndex.SetENVMAPSPHERE( false );
  75. vshIndex.SetVERTEXCOLOR( false );
  76. vshIndex.SetSEPARATEDETAILUVS( false );
  77. pShaderShadow->SetVertexShader( "unlitgeneric_vs11", vshIndex.GetIndex() );
  78. pShaderShadow->SetPixelShader( "unlitgeneric" );
  79. }
  80. }
  81. DYNAMIC_STATE
  82. {
  83. if ( params[BUMPMAP]->IsTexture() )
  84. {
  85. BindTexture( SHADER_SAMPLER0, BUMPMAP, BUMPFRAME );
  86. }
  87. else
  88. {
  89. pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT );
  90. }
  91. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BUMPTRANSFORM );
  92. #ifdef USE_NEW_SHADER
  93. if( g_pHardwareConfig->GetDXSupportLevel() >= 90 )
  94. {
  95. float vVertexColor[4] = { 0, 0, 0, 0 };
  96. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, vVertexColor, 1 );
  97. DECLARE_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 );
  98. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  99. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  100. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  101. SET_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 );
  102. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  103. {
  104. DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20b );
  105. SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20b );
  106. }
  107. else
  108. {
  109. DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20 );
  110. SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20 );
  111. }
  112. }
  113. else
  114. #endif
  115. {
  116. unlitgeneric_vs11_Dynamic_Index vshIndex;
  117. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  118. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  119. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  120. }
  121. }
  122. Draw();
  123. }
  124. END_SHADER