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.

186 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: eye renderer
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "eyes_dx8_dx9_helper.h"
  10. #include "cloak_blended_pass_helper.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. DEFINE_FALLBACK_SHADER( eyes, Eyes_dx8 )
  14. BEGIN_VS_SHADER( Eyes_dx8,
  15. "Help for Eyes" )
  16. BEGIN_SHADER_PARAMS
  17. SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/alyx/eyeball_l", "iris texture", 0 )
  18. SHADER_PARAM( IRIS, SHADER_PARAM_TYPE_TEXTURE, "models/alyx/pupil_l", "iris texture" )
  19. SHADER_PARAM( IRISFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame for the iris texture" )
  20. SHADER_PARAM( GLINT, SHADER_PARAM_TYPE_TEXTURE, "models/humans/male/glint", "glint texture" )
  21. SHADER_PARAM( EYEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "origin for the eyes" )
  22. SHADER_PARAM( EYEUP, SHADER_PARAM_TYPE_VEC3, "[0 0 1]", "up vector for the eyes" )
  23. SHADER_PARAM( IRISU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "U projection vector for the iris" )
  24. SHADER_PARAM( IRISV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the iris" )
  25. SHADER_PARAM( GLINTU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "U projection vector for the glint" )
  26. SHADER_PARAM( GLINTV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the glint" )
  27. SHADER_PARAM( DILATION, SHADER_PARAM_TYPE_FLOAT, "0", "Iris dilation" )
  28. SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is eyes in the ep1 intro" )
  29. SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" )
  30. SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" )
  31. // Cloak Pass
  32. SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" )
  33. SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  34. SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" )
  35. SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" )
  36. END_SHADER_PARAMS
  37. void SetupVars( Eyes_DX8_DX9_Vars_t &info )
  38. {
  39. info.m_nBaseTexture = BASETEXTURE;
  40. info.m_nFrame = FRAME;
  41. info.m_nIris = IRIS;
  42. info.m_nIrisFrame = IRISFRAME;
  43. info.m_nGlint = GLINT;
  44. info.m_nEyeOrigin = EYEORIGIN;
  45. info.m_nEyeUp = EYEUP;
  46. info.m_nIrisU = IRISU;
  47. info.m_nIrisV = IRISV;
  48. info.m_nGlintU = GLINTU;
  49. info.m_nGlintV = GLINTV;
  50. info.m_nDilation = DILATION;
  51. info.m_nIntro = INTRO;
  52. info.m_nEntityOrigin = ENTITYORIGIN;
  53. info.m_nWarpParam = WARPPARAM;
  54. }
  55. // Cloak Pass
  56. void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info )
  57. {
  58. info.m_nCloakFactor = CLOAKFACTOR;
  59. info.m_nCloakColorTint = CLOAKCOLORTINT;
  60. info.m_nRefractAmount = REFRACTAMOUNT;
  61. }
  62. bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
  63. {
  64. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  65. {
  66. if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time
  67. return true;
  68. else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  69. return true;
  70. // else, not cloaking this frame, so check flag2 in case the base material still needs it
  71. }
  72. // Check flag2 if not drawing cloak pass
  73. return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE );
  74. }
  75. bool IsTranslucent( IMaterialVar **params ) const
  76. {
  77. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  78. {
  79. if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  80. return true;
  81. // else, not cloaking this frame, so check flag in case the base material still needs it
  82. }
  83. // Check flag if not drawing cloak pass
  84. return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
  85. }
  86. SHADER_INIT_PARAMS()
  87. {
  88. Eyes_DX8_DX9_Vars_t info;
  89. SetupVars( info );
  90. InitParamsEyes_DX8_DX9( this, params, pMaterialName, info );
  91. // Cloak Pass
  92. if ( !params[CLOAKPASSENABLED]->IsDefined() )
  93. {
  94. params[CLOAKPASSENABLED]->SetIntValue( 0 );
  95. }
  96. else if ( params[CLOAKPASSENABLED]->GetIntValue() )
  97. {
  98. CloakBlendedPassVars_t info;
  99. SetupVarsCloakBlendedPass( info );
  100. InitParamsCloakBlendedPass( this, params, pMaterialName, info );
  101. }
  102. }
  103. SHADER_FALLBACK
  104. {
  105. if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 )
  106. return "Eyes_dx6";
  107. return 0;
  108. }
  109. SHADER_INIT
  110. {
  111. Eyes_DX8_DX9_Vars_t info;
  112. SetupVars( info );
  113. InitEyes_DX8_DX9( this, params, info );
  114. // Cloak Pass
  115. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  116. {
  117. CloakBlendedPassVars_t info;
  118. SetupVarsCloakBlendedPass( info );
  119. InitCloakBlendedPass( this, params, info );
  120. }
  121. }
  122. SHADER_DRAW
  123. {
  124. // Skip the standard rendering if cloak pass is fully opaque
  125. bool bDrawStandardPass = true;
  126. if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting
  127. {
  128. CloakBlendedPassVars_t info;
  129. SetupVarsCloakBlendedPass( info );
  130. if ( CloakBlendedPassIsFullyOpaque( params, info ) )
  131. {
  132. // There is some strangeness in DX8 when trying to skip the main pass, so leave this alone for now
  133. //bDrawStandardPass = false;
  134. }
  135. }
  136. // Standard rendering pass
  137. if ( bDrawStandardPass )
  138. {
  139. Eyes_DX8_DX9_Vars_t info;
  140. SetupVars( info );
  141. DrawEyes_DX8_DX9( false, this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  142. }
  143. else
  144. {
  145. // Skip this pass!
  146. Draw( false );
  147. }
  148. // Cloak Pass
  149. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  150. {
  151. // If ( snapshotting ) or ( we need to draw this frame )
  152. if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) )
  153. {
  154. CloakBlendedPassVars_t info;
  155. SetupVarsCloakBlendedPass( info );
  156. DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  157. }
  158. else // We're not snapshotting and we don't need to draw this frame
  159. {
  160. // Skip this pass!
  161. Draw( false );
  162. }
  163. }
  164. }
  165. END_SHADER