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

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "vortwarp_vs11.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( VortWarp, VortWarp_dx8 )
  13. float QuadraticBezier( float t, float A, float B, float C )
  14. {
  15. return Lerp( t, Lerp( t, A, B ), Lerp( t, B, C ) );
  16. }
  17. float CubicBezier( float t, float A, float B, float C, float D )
  18. {
  19. return QuadraticBezier( t, Lerp( t, A, B ), Lerp( t, B, C ), Lerp( t, C, D ) );
  20. }
  21. BEGIN_VS_SHADER( VortWarp_dx8,
  22. "Help for VortWarp_dx8" )
  23. BEGIN_SHADER_PARAMS
  24. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  25. SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" )
  26. SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" )
  27. SHADER_PARAM( SELFILLUMMAP, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" )
  28. SHADER_PARAM( UNLIT, SHADER_PARAM_TYPE_BOOL, "", "" )
  29. END_SHADER_PARAMS
  30. SHADER_INIT_PARAMS()
  31. {
  32. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  33. if( !params[SELFILLUMTINT]->IsDefined() )
  34. params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  35. if( !params[UNLIT]->IsDefined() )
  36. {
  37. params[UNLIT]->SetIntValue( 0 );
  38. }
  39. if( !params[SELFILLUMTINT]->IsDefined() )
  40. {
  41. params[SELFILLUMTINT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
  42. }
  43. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  44. }
  45. SHADER_FALLBACK
  46. {
  47. if ( g_pHardwareConfig->GetDXSupportLevel() < 80)
  48. return "Vortwarp_dx7";
  49. return 0;
  50. }
  51. SHADER_INIT
  52. {
  53. if (params[BASETEXTURE]->IsDefined())
  54. {
  55. LoadTexture( BASETEXTURE );
  56. }
  57. if( params[SELFILLUMMAP]->IsDefined() )
  58. {
  59. LoadTexture( SELFILLUMMAP );
  60. }
  61. }
  62. SHADER_DRAW
  63. {
  64. BlendType_t blendType = BT_BLEND;
  65. if ( params[BASETEXTURE]->IsTexture() )
  66. {
  67. blendType = EvaluateBlendRequirements( BASETEXTURE, true );
  68. }
  69. SHADOW_STATE
  70. {
  71. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  72. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  73. int fmt = VERTEX_POSITION | VERTEX_NORMAL;
  74. if (params[BASETEXTURE]->IsTexture())
  75. {
  76. SetDefaultBlendingShadowState( BASETEXTURE, true );
  77. }
  78. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  79. // Set up the vertex shader index.
  80. vortwarp_vs11_Static_Index vshIndex;
  81. vshIndex.SetUNLIT( params[UNLIT]->GetIntValue() != 0 );
  82. vshIndex.SetHALF_LAMBERT( IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) );
  83. pShaderShadow->SetVertexShader( "vortwarp_vs11", vshIndex.GetIndex() );
  84. int pshIndex;
  85. if( blendType == BT_BLEND )
  86. {
  87. pShaderShadow->EnableBlending( true );
  88. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  89. pShaderShadow->EnableAlphaWrites( false );
  90. pshIndex = 1;
  91. }
  92. else
  93. {
  94. pShaderShadow->EnableAlphaWrites( true );
  95. pshIndex = 0;
  96. }
  97. if( params[UNLIT]->GetIntValue() != 0 )
  98. {
  99. pshIndex |= 0x2;
  100. }
  101. pShaderShadow->SetPixelShader( "vortwarp_ps11", pshIndex );
  102. DefaultFog();
  103. }
  104. DYNAMIC_STATE
  105. {
  106. if (params[BASETEXTURE]->IsTexture())
  107. {
  108. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  109. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  110. }
  111. if( params[SELFILLUMMAP]->IsTexture() )
  112. {
  113. BindTexture( SHADER_SAMPLER1, SELFILLUMMAP, -1 );
  114. }
  115. float warp = params[WARPPARAM]->GetFloatValue();
  116. float t = warp;
  117. warp = CubicBezier( warp, 0.0f, 1.0f, 0.0f, 0.0f );
  118. warp = Lerp( t, warp, 1.0f );
  119. float warpVec[4] = { warp, warp, warp, warp };
  120. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, warpVec, 1 );
  121. SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, ENTITYORIGIN );
  122. SetAmbientCubeDynamicStateVertexShader();
  123. SetModulationPixelShaderDynamicState( 3 );
  124. EnablePixelShaderOverbright( 0, true, true );
  125. SetPixelShaderConstant( 1, SELFILLUMTINT );
  126. float c4[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
  127. if( warp > 0.0f && warp < 1.0f )
  128. {
  129. c4[3] = 0.0f;
  130. }
  131. pShaderAPI->SetPixelShaderConstant( 4, c4, 1 );
  132. float c5[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  133. pShaderAPI->SetPixelShaderConstant( 5, c5, 1 );
  134. float curTime = pShaderAPI->CurrentTime();
  135. float selfIllumScroll[4] = { .11f * curTime, .124 * curTime, 0.0f, 0.0f };
  136. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, selfIllumScroll, 1 );
  137. vortwarp_vs11_Dynamic_Index vshIndex;
  138. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  139. vshIndex.SetLIGHT_COMBO( 0 );
  140. vshIndex.SetLIGHT_COMBO( pShaderAPI->GetCurrentLightCombo() );
  141. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  142. }
  143. Draw();
  144. }
  145. END_SHADER