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

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A wet version of base * lightmap
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "particlesphere_vs20.inc"
  10. #include "particlesphere_ps20.inc"
  11. #include "particlesphere_ps20b.inc"
  12. #include "cpp_shader_constant_register_map.h"
  13. int GetDefaultDepthFeatheringValue( void ); //defined in spritecard.cpp
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. DEFINE_FALLBACK_SHADER( ParticleSphere, ParticleSphere_DX9 )
  17. BEGIN_VS_SHADER_FLAGS( ParticleSphere_DX9, "Help for BumpmappedEnvMap", SHADER_NOT_EDITABLE )
  18. BEGIN_SHADER_PARAMS
  19. SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" )
  20. SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." )
  21. SHADER_PARAM( USINGPIXELSHADER, SHADER_PARAM_TYPE_BOOL, "0", "Tells to client code whether the shader is using DX8 vertex/pixel shaders or not" )
  22. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bumpmap" )
  23. SHADER_PARAM( LIGHTS, SHADER_PARAM_TYPE_FOURCC, "", "array of lights" )
  24. SHADER_PARAM( LIGHT_POSITION, SHADER_PARAM_TYPE_VEC3, "0 0 0", "This is the directional light position." )
  25. SHADER_PARAM( LIGHT_COLOR, SHADER_PARAM_TYPE_VEC3, "1 1 1", "This is the directional light color." )
  26. END_SHADER_PARAMS
  27. SHADER_INIT_PARAMS()
  28. {
  29. if ( !params[DEPTHBLEND]->IsDefined() )
  30. {
  31. params[ DEPTHBLEND ]->SetIntValue( GetDefaultDepthFeatheringValue() );
  32. }
  33. if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() )
  34. {
  35. params[ DEPTHBLEND ]->SetIntValue( 0 );
  36. }
  37. if ( !params[DEPTHBLENDSCALE]->IsDefined() )
  38. {
  39. params[ DEPTHBLENDSCALE ]->SetFloatValue( 50.0f );
  40. }
  41. }
  42. bool UsePixelShaders( IMaterialVar **params ) const
  43. {
  44. return (!params || params[BUMPMAP]->IsDefined()) && g_pHardwareConfig->SupportsVertexAndPixelShaders();
  45. }
  46. SHADER_INIT
  47. {
  48. // If this would return false, then we should have fallen back to the DX6 one.
  49. Assert( UsePixelShaders( params ) );
  50. params[USINGPIXELSHADER]->SetIntValue( true );
  51. LoadBumpMap( BUMPMAP );
  52. }
  53. SHADER_FALLBACK
  54. {
  55. if ( !UsePixelShaders(params) )
  56. {
  57. return "UnlitGeneric_DX6";
  58. }
  59. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  60. {
  61. return "ParticleSphere_DX8";
  62. }
  63. return 0;
  64. }
  65. SHADER_DRAW
  66. {
  67. SHADOW_STATE
  68. {
  69. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  70. if ( params[DEPTHBLEND]->GetIntValue() )
  71. {
  72. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  73. }
  74. int tCoordDimensions[] = {2};
  75. pShaderShadow->VertexShaderVertexFormat(
  76. VERTEX_POSITION | VERTEX_COLOR, 1, tCoordDimensions, 0 );
  77. pShaderShadow->EnableBlending( true );
  78. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  79. pShaderShadow->EnableDepthWrites( false );
  80. DECLARE_STATIC_VERTEX_SHADER( particlesphere_vs20 );
  81. SET_STATIC_VERTEX_SHADER( particlesphere_vs20 );
  82. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  83. {
  84. DECLARE_STATIC_PIXEL_SHADER( particlesphere_ps20b );
  85. SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, params[DEPTHBLEND]->GetIntValue() );
  86. SET_STATIC_PIXEL_SHADER( particlesphere_ps20b );
  87. }
  88. else
  89. {
  90. DECLARE_STATIC_PIXEL_SHADER( particlesphere_ps20 );
  91. SET_STATIC_PIXEL_SHADER( particlesphere_ps20 );
  92. }
  93. FogToFogColor();
  94. }
  95. DYNAMIC_STATE
  96. {
  97. BindTexture( SHADER_SAMPLER0, BUMPMAP );
  98. if ( params[DEPTHBLEND]->GetIntValue() )
  99. {
  100. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_DEPTH );
  101. }
  102. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[LIGHT_POSITION]->GetVecValue() );
  103. // Separate the light color into something that has a max value of 1 and a scale
  104. // so the vertex shader can determine if it's going to overflow the color and scale back
  105. // if it needs to.
  106. //
  107. // (It does this by seeing if the intensity*1/distSqr is > 1. If so, then it scales it so
  108. // it is equal to 1).
  109. const float *f = params[LIGHT_COLOR]->GetVecValue();
  110. Vector vLightColor( f[0], f[1], f[2] );
  111. float flScale = max( vLightColor.x, max( vLightColor.y, vLightColor.z ) );
  112. if ( flScale < 0.01f )
  113. flScale = 0.01f;
  114. float vScaleVec[3] = { flScale, flScale, flScale };
  115. vLightColor /= flScale;
  116. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vLightColor.Base() );
  117. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec );
  118. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  119. float vEyePos_SpecExponent[4];
  120. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  121. vEyePos_SpecExponent[3] = 0.0f;
  122. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  123. pShaderAPI->SetDepthFeatheringPixelShaderConstant( 0, params[DEPTHBLENDSCALE]->GetFloatValue() );
  124. // Compute the vertex shader index.
  125. DECLARE_DYNAMIC_VERTEX_SHADER( particlesphere_vs20 );
  126. SET_DYNAMIC_VERTEX_SHADER_COMBO( FOGTYPE, s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  127. SET_DYNAMIC_VERTEX_SHADER( particlesphere_vs20 );
  128. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  129. {
  130. DECLARE_DYNAMIC_PIXEL_SHADER( particlesphere_ps20b );
  131. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  132. SET_DYNAMIC_PIXEL_SHADER( particlesphere_ps20b );
  133. }
  134. else
  135. {
  136. DECLARE_DYNAMIC_PIXEL_SHADER( particlesphere_ps20 );
  137. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  138. SET_DYNAMIC_PIXEL_SHADER( particlesphere_ps20 );
  139. }
  140. }
  141. Draw();
  142. }
  143. END_SHADER