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.

116 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "BaseVSShader.h"
  7. #include "teeth.inc"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. DEFINE_FALLBACK_SHADER( Teeth, Teeth_DX8 )
  11. BEGIN_VS_SHADER( Teeth_DX8, "Help for Teeth_DX8" )
  12. BEGIN_SHADER_PARAMS
  13. SHADER_PARAM( ILLUMFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to darken or brighten the teeth" )
  14. SHADER_PARAM( FORWARD, SHADER_PARAM_TYPE_VEC3, "[1 0 0]", "Forward direction vector for teeth lighting" )
  15. SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is teeth in the ep1 intro" )
  16. SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" )
  17. SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT_PARAMS()
  20. {
  21. // FLASHLIGHTFIXME
  22. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  23. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  24. if( !params[INTRO]->IsDefined() )
  25. {
  26. params[INTRO]->SetIntValue( 0 );
  27. }
  28. }
  29. SHADER_FALLBACK
  30. {
  31. if ( IsPC() && ( g_pHardwareConfig->GetDXSupportLevel() < 80 || g_pConfig->bSoftwareLighting ) )
  32. {
  33. return "Teeth_dx6";
  34. }
  35. return 0;
  36. }
  37. SHADER_INIT
  38. {
  39. LoadTexture( FLASHLIGHTTEXTURE );
  40. LoadTexture( BASETEXTURE );
  41. }
  42. void DrawUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow )
  43. {
  44. SHADOW_STATE
  45. {
  46. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  47. pShaderShadow->VertexShaderVertexFormat(
  48. VERTEX_POSITION | VERTEX_NORMAL, 1, 0, 0 );
  49. teeth_Static_Index vshIndex;
  50. vshIndex.SetHALF_LAMBERT( IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) );
  51. vshIndex.SetINTRO( params[INTRO]->GetIntValue() != 0 );
  52. pShaderShadow->SetVertexShader( "Teeth", vshIndex.GetIndex() );
  53. pShaderShadow->SetPixelShader( "VertexLitTexture_Overbright2" );
  54. FogToFogColor();
  55. }
  56. DYNAMIC_STATE
  57. {
  58. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  59. SetAmbientCubeDynamicStateVertexShader();
  60. Vector4D lighting;
  61. params[FORWARD]->GetVecValue( lighting.Base(), 3 );
  62. lighting[3] = params[ILLUMFACTOR]->GetFloatValue();
  63. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lighting.Base() );
  64. teeth_Dynamic_Index vshIndex;
  65. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  66. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  67. vshIndex.SetLIGHT_COMBO( pShaderAPI->GetCurrentLightCombo() );
  68. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  69. if( params[INTRO]->GetIntValue() )
  70. {
  71. float curTime = params[WARPPARAM]->GetFloatValue();
  72. float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime };
  73. Assert( params[ENTITYORIGIN]->IsDefined() );
  74. params[ENTITYORIGIN]->GetVecValue( timeVec, 3 );
  75. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, timeVec, 1 );
  76. }
  77. }
  78. Draw();
  79. }
  80. SHADER_DRAW
  81. {
  82. SHADOW_STATE
  83. {
  84. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  85. }
  86. bool hasFlashlight = UsingFlashlight( params );
  87. if( hasFlashlight )
  88. {
  89. DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1,
  90. FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, false, false, 0, -1, -1,
  91. // Optional parameters, specific to teeth:
  92. true, FORWARD, ILLUMFACTOR );
  93. }
  94. else
  95. {
  96. DrawUsingVertexShader( params, pShaderAPI, pShaderShadow );
  97. }
  98. }
  99. END_SHADER