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.

101 lines
3.5 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_vs11.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( ParticleSphere, ParticleSphere_DX8 )
  13. BEGIN_VS_SHADER_FLAGS( ParticleSphere_DX8, "Help for BumpmappedEnvMap", SHADER_NOT_EDITABLE )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( USINGPIXELSHADER, SHADER_PARAM_TYPE_BOOL, "0", "Tells to client code whether the shader is using DX8 vertex/pixel shaders or not" )
  16. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bumpmap" )
  17. SHADER_PARAM( LIGHTS, SHADER_PARAM_TYPE_FOURCC, "", "array of lights" )
  18. SHADER_PARAM( LIGHT_POSITION, SHADER_PARAM_TYPE_VEC3, "0 0 0", "This is the directional light position." )
  19. SHADER_PARAM( LIGHT_COLOR, SHADER_PARAM_TYPE_VEC3, "1 1 1", "This is the directional light color." )
  20. END_SHADER_PARAMS
  21. bool UsePixelShaders( IMaterialVar **params ) const
  22. {
  23. return (!params || params[BUMPMAP]->IsDefined()) && g_pHardwareConfig->SupportsVertexAndPixelShaders();
  24. }
  25. SHADER_INIT
  26. {
  27. // If this would return false, then we should have fallen back to the DX6 one.
  28. Assert( UsePixelShaders( params ) );
  29. params[USINGPIXELSHADER]->SetIntValue( true );
  30. LoadBumpMap( BUMPMAP );
  31. }
  32. SHADER_FALLBACK
  33. {
  34. if ( IsPC() && !UsePixelShaders(params) )
  35. {
  36. return "UnlitGeneric_DX6";
  37. }
  38. return 0;
  39. }
  40. SHADER_DRAW
  41. {
  42. SHADOW_STATE
  43. {
  44. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  45. int tCoordDimensions[] = {2};
  46. pShaderShadow->VertexShaderVertexFormat(
  47. VERTEX_POSITION | VERTEX_COLOR, 1, tCoordDimensions, 0 );
  48. pShaderShadow->EnableBlending( true );
  49. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  50. pShaderShadow->EnableDepthWrites( false );
  51. particlesphere_vs11_Static_Index vshIndex;
  52. pShaderShadow->SetVertexShader( "ParticleSphere_vs11", vshIndex.GetIndex() );
  53. pShaderShadow->SetPixelShader( "ParticleSphere_ps11" );
  54. FogToFogColor();
  55. }
  56. DYNAMIC_STATE
  57. {
  58. BindTexture( SHADER_SAMPLER0, BUMPMAP );
  59. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[LIGHT_POSITION]->GetVecValue() );
  60. // Separate the light color into something that has a max value of 1 and a scale
  61. // so the vertex shader can determine if it's going to overflow the color and scale back
  62. // if it needs to.
  63. //
  64. // (It does this by seeing if the intensity*1/distSqr is > 1. If so, then it scales it so
  65. // it is equal to 1).
  66. const float *f = params[LIGHT_COLOR]->GetVecValue();
  67. Vector vLightColor( f[0], f[1], f[2] );
  68. float flScale = max( vLightColor.x, max( vLightColor.y, vLightColor.z ) );
  69. if ( flScale < 0.01f )
  70. flScale = 0.01f;
  71. float vScaleVec[3] = { flScale, flScale, flScale };
  72. vLightColor /= flScale;
  73. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vLightColor.Base() );
  74. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec );
  75. // Compute the vertex shader index.
  76. particlesphere_vs11_Dynamic_Index vshIndex;
  77. vshIndex.SetFOGTYPE( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  78. s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  79. }
  80. Draw();
  81. }
  82. END_SHADER