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.

108 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "BaseVSShader.h"
  8. #include "morphaccumulate_vs30.inc"
  9. #include "morphaccumulate_ps30.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( MorphAccumulate, MorphAccumulate_DX9 )
  13. BEGIN_VS_SHADER_FLAGS( MorphAccumulate_DX9, "Help for MorphAccumulate", SHADER_NOT_EDITABLE )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( DELTA, SHADER_PARAM_TYPE_TEXTURE, "", "position/normal deltas" )
  16. SHADER_PARAM( SIDESPEED, SHADER_PARAM_TYPE_TEXTURE, "", "side/speed map" )
  17. SHADER_PARAM( DIMENSIONS, SHADER_PARAM_TYPE_VEC3, "", "delta dimensions" )
  18. SHADER_PARAM( DELTASCALE, SHADER_PARAM_TYPE_FLOAT, "", "delta scale" )
  19. END_SHADER_PARAMS
  20. SHADER_INIT_PARAMS()
  21. {
  22. }
  23. SHADER_FALLBACK
  24. {
  25. return 0;
  26. }
  27. SHADER_INIT
  28. {
  29. LoadTexture( DELTA );
  30. LoadTexture( SIDESPEED );
  31. }
  32. SHADER_DRAW
  33. {
  34. bool bUseConstantBasedAccum = ( g_pHardwareConfig->NumVertexShaderConstants() >= VERTEX_SHADER_FLEX_WEIGHTS + VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT );
  35. SHADOW_STATE
  36. {
  37. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  38. pShaderShadow->EnableBlendingSeparateAlpha( true );
  39. pShaderShadow->BlendFuncSeparateAlpha( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  40. pShaderShadow->EnableDepthTest( false );
  41. pShaderShadow->EnableDepthWrites( false );
  42. pShaderShadow->EnableAlphaWrites( true );
  43. pShaderShadow->EnableCulling( false );
  44. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  45. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  46. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  47. pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED );
  48. DECLARE_STATIC_VERTEX_SHADER( morphaccumulate_vs30 );
  49. SET_STATIC_VERTEX_SHADER_COMBO( CONSTANTBASEDMORPH, bUseConstantBasedAccum );
  50. SET_STATIC_VERTEX_SHADER( morphaccumulate_vs30 );
  51. DECLARE_STATIC_PIXEL_SHADER( morphaccumulate_ps30 );
  52. SET_STATIC_PIXEL_SHADER_COMBO( CONSTANTBASEDMORPH, bUseConstantBasedAccum );
  53. SET_STATIC_PIXEL_SHADER( morphaccumulate_ps30 );
  54. // NOTE: Color indicates where in the morph accumulator to render into
  55. // Texcoord0 is the texcoord to read from in the source morph texture
  56. // Texcoord1 indicates the strength of the morph target
  57. int pTexCoord[2] = { 4, 1 };
  58. pShaderShadow->VertexShaderVertexFormat( VERTEX_FORMAT_USE_EXACT_FORMAT, 2, pTexCoord, 0 );
  59. }
  60. DYNAMIC_STATE
  61. {
  62. BindTexture( SHADER_SAMPLER0, DELTA );
  63. BindTexture( SHADER_SAMPLER1, SIDESPEED );
  64. if ( !bUseConstantBasedAccum )
  65. {
  66. pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_MORPH_WEIGHTS );
  67. int nXOffset = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_X_OFFSET );
  68. int nYOffset = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_Y_OFFSET );
  69. int nSubrectWidth = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_SUBRECT_WIDTH );
  70. int nSubrectHeight = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_SUBRECT_HEIGHT );
  71. float pMorphWeightSubrect[4] = { nXOffset, nYOffset, nSubrectWidth, nSubrectHeight };
  72. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, pMorphWeightSubrect );
  73. int nWidth, nHeight;
  74. pShaderAPI->GetStandardTextureDimensions( &nWidth, &nHeight, TEXTURE_MORPH_WEIGHTS );
  75. float pMorphWeightDim[4] = { nWidth, nHeight, 0, 0 };
  76. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, pMorphWeightDim );
  77. }
  78. SetPixelShaderConstant( 0, DELTASCALE );
  79. DECLARE_DYNAMIC_VERTEX_SHADER( morphaccumulate_vs30 );
  80. SET_DYNAMIC_VERTEX_SHADER( morphaccumulate_vs30 );
  81. DECLARE_DYNAMIC_PIXEL_SHADER( morphaccumulate_ps30 );
  82. SET_DYNAMIC_PIXEL_SHADER( morphaccumulate_ps30 );
  83. }
  84. Draw();
  85. }
  86. END_SHADER