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.

102 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "treeleaf_ps20.inc"
  10. #include "treeleaf_ps20b.inc"
  11. #include "treeleaf_vs20.inc"
  12. BEGIN_VS_SHADER_FLAGS( TreeLeaf, "Help for TreeLeaf", SHADER_NOT_EDITABLE )
  13. BEGIN_SHADER_PARAMS
  14. SHADER_PARAM( LEAFCENTER, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "Center of leaf cluster for lighting" )
  15. END_SHADER_PARAMS
  16. SHADER_INIT_PARAMS()
  17. {
  18. }
  19. SHADER_FALLBACK
  20. {
  21. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  22. {
  23. return "Wireframe";
  24. }
  25. return 0;
  26. }
  27. SHADER_INIT
  28. {
  29. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  30. if ( params[BASETEXTURE]->IsDefined() )
  31. {
  32. LoadTexture( BASETEXTURE );
  33. }
  34. }
  35. SHADER_DRAW
  36. {
  37. SHADOW_STATE
  38. {
  39. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  40. pShaderShadow->EnableAlphaTest( true );
  41. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.5f );
  42. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL;
  43. int numTexCoords = 1;
  44. pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 );
  45. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  46. DECLARE_STATIC_VERTEX_SHADER( treeleaf_vs20 );
  47. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, true );
  48. SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow );
  49. SET_STATIC_VERTEX_SHADER( treeleaf_vs20 );
  50. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  51. {
  52. DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20b );
  53. SET_STATIC_PIXEL_SHADER( treeleaf_ps20b );
  54. }
  55. else
  56. {
  57. DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20 );
  58. SET_STATIC_PIXEL_SHADER( treeleaf_ps20 );
  59. }
  60. // we are writing linear values from this shader.
  61. // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below.
  62. // The COLOR really decides if we are gamma or linear.
  63. pShaderShadow->EnableSRGBWrite( false );
  64. }
  65. DYNAMIC_STATE
  66. {
  67. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  68. // We need the view matrix
  69. LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL );
  70. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[ LEAFCENTER ]->GetVecValue() );
  71. LightState_t lightState;
  72. pShaderAPI->GetDX9LightState( &lightState );
  73. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  74. DECLARE_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 );
  75. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  76. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 );
  77. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  78. SET_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 );
  79. }
  80. Draw( );
  81. }
  82. END_SHADER