Counter Strike : Global Offensive Source Code
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 � 1996-2005, 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. // NOTE: This has to be the last file included!
  13. #include "tier0/memdbgon.h"
  14. BEGIN_VS_SHADER_FLAGS( TreeLeaf, "Help for TreeLeaf", SHADER_NOT_EDITABLE )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( LEAFCENTER, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "Center of leaf cluster for lighting" )
  17. END_SHADER_PARAMS
  18. SHADER_INIT_PARAMS()
  19. {
  20. }
  21. SHADER_FALLBACK
  22. {
  23. return 0;
  24. }
  25. SHADER_INIT
  26. {
  27. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  28. if ( params[BASETEXTURE]->IsDefined() )
  29. {
  30. LoadTexture( BASETEXTURE );
  31. }
  32. }
  33. SHADER_DRAW
  34. {
  35. SHADOW_STATE
  36. {
  37. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  38. pShaderShadow->EnableAlphaTest( true );
  39. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.5f );
  40. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL;
  41. int numTexCoords = 1;
  42. pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 );
  43. bool bFlattenStaticControlFlow = !g_pHardwareConfig->SupportsStaticControlFlow();
  44. DECLARE_STATIC_VERTEX_SHADER( treeleaf_vs20 );
  45. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, true );
  46. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, bFlattenStaticControlFlow );
  47. SET_STATIC_VERTEX_SHADER( treeleaf_vs20 );
  48. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  49. {
  50. DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20b );
  51. SET_STATIC_PIXEL_SHADER( treeleaf_ps20b );
  52. }
  53. else
  54. {
  55. DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20 );
  56. SET_STATIC_PIXEL_SHADER( treeleaf_ps20 );
  57. }
  58. // we are writing linear values from this shader.
  59. // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below.
  60. // The COLOR really decides if we are gamma or linear.
  61. pShaderShadow->EnableSRGBWrite( false );
  62. }
  63. DYNAMIC_STATE
  64. {
  65. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BASETEXTURE, FRAME );
  66. // We need the view matrix
  67. LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL );
  68. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[ LEAFCENTER ]->GetVecValue() );
  69. LightState_t lightState = {0, false, false};
  70. pShaderAPI->GetDX9LightState( &lightState );
  71. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  72. DECLARE_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 );
  73. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  74. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  75. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  76. SET_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 );
  77. }
  78. Draw( );
  79. }
  80. END_SHADER