Counter Strike : Global Offensive Source Code
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.

181 lines
6.0 KiB

  1. //========= Copyright � 1996-2005, 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( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" )
  29. SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" )
  30. // Cloak Pass
  31. SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" )
  32. SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  33. SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" )
  34. SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" )
  35. END_SHADER_PARAMS
  36. void SetupVars( Eyes_DX8_DX9_Vars_t &info )
  37. {
  38. info.m_nBaseTexture = BASETEXTURE;
  39. info.m_nFrame = FRAME;
  40. info.m_nIris = IRIS;
  41. info.m_nIrisFrame = IRISFRAME;
  42. info.m_nGlint = GLINT;
  43. info.m_nEyeOrigin = EYEORIGIN;
  44. info.m_nEyeUp = EYEUP;
  45. info.m_nIrisU = IRISU;
  46. info.m_nIrisV = IRISV;
  47. info.m_nGlintU = GLINTU;
  48. info.m_nGlintV = GLINTV;
  49. info.m_nDilation = DILATION;
  50. info.m_nEntityOrigin = ENTITYORIGIN;
  51. info.m_nWarpParam = WARPPARAM;
  52. }
  53. // Cloak Pass
  54. void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info )
  55. {
  56. info.m_nCloakFactor = CLOAKFACTOR;
  57. info.m_nCloakColorTint = CLOAKCOLORTINT;
  58. info.m_nRefractAmount = REFRACTAMOUNT;
  59. }
  60. bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
  61. {
  62. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  63. {
  64. if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time
  65. return true;
  66. else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  67. return true;
  68. // else, not cloaking this frame, so check flag2 in case the base material still needs it
  69. }
  70. // Check flag2 if not drawing cloak pass
  71. return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE );
  72. }
  73. bool IsTranslucent( IMaterialVar **params ) const
  74. {
  75. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  76. {
  77. if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  78. return true;
  79. // else, not cloaking this frame, so check flag in case the base material still needs it
  80. }
  81. // Check flag if not drawing cloak pass
  82. return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
  83. }
  84. SHADER_INIT_PARAMS()
  85. {
  86. Eyes_DX8_DX9_Vars_t info;
  87. SetupVars( info );
  88. InitParamsEyes_DX8_DX9( this, params, pMaterialName, info );
  89. // Cloak Pass
  90. if ( !params[CLOAKPASSENABLED]->IsDefined() )
  91. {
  92. params[CLOAKPASSENABLED]->SetIntValue( 0 );
  93. }
  94. else if ( params[CLOAKPASSENABLED]->GetIntValue() )
  95. {
  96. CloakBlendedPassVars_t info;
  97. SetupVarsCloakBlendedPass( info );
  98. InitParamsCloakBlendedPass( this, params, pMaterialName, info );
  99. }
  100. }
  101. SHADER_FALLBACK
  102. {
  103. return 0;
  104. }
  105. SHADER_INIT
  106. {
  107. Eyes_DX8_DX9_Vars_t info;
  108. SetupVars( info );
  109. InitEyes_DX8_DX9( this, params, info );
  110. // Cloak Pass
  111. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  112. {
  113. CloakBlendedPassVars_t info;
  114. SetupVarsCloakBlendedPass( info );
  115. InitCloakBlendedPass( this, params, info );
  116. }
  117. }
  118. SHADER_DRAW
  119. {
  120. // Skip the standard rendering if cloak pass is fully opaque
  121. bool bDrawStandardPass = true;
  122. if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting
  123. {
  124. CloakBlendedPassVars_t info;
  125. SetupVarsCloakBlendedPass( info );
  126. if ( CloakBlendedPassIsFullyOpaque( params, info ) )
  127. {
  128. // There is some strangeness in DX8 when trying to skip the main pass, so leave this alone for now
  129. //bDrawStandardPass = false;
  130. }
  131. }
  132. // Standard rendering pass
  133. if ( bDrawStandardPass )
  134. {
  135. Eyes_DX8_DX9_Vars_t info;
  136. SetupVars( info );
  137. DrawEyes_DX8_DX9( false, this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  138. }
  139. else
  140. {
  141. // Skip this pass!
  142. Draw( false );
  143. }
  144. // Cloak Pass
  145. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  146. {
  147. // If ( snapshotting ) or ( we need to draw this frame )
  148. if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) )
  149. {
  150. CloakBlendedPassVars_t info;
  151. SetupVarsCloakBlendedPass( info );
  152. DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  153. }
  154. else // We're not snapshotting and we don't need to draw this frame
  155. {
  156. // Skip this pass!
  157. Draw( false );
  158. }
  159. }
  160. }
  161. END_SHADER