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.

253 lines
9.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "eye_refract_helper.h"
  4. #include "cloak_blended_pass_helper.h"
  5. #include "emissive_scroll_blended_pass_helper.h"
  6. // memdbgon must be the last include file in a .cpp file!!!
  7. #include "tier0/memdbgon.h"
  8. DEFINE_FALLBACK_SHADER( EyeRefract, EyeRefract_dx9 )
  9. BEGIN_VS_SHADER( EyeRefract_dx9, "Help for Eyes" )
  10. BEGIN_SHADER_PARAMS
  11. SHADER_PARAM( IRIS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "iris texture" )
  12. SHADER_PARAM( IRISFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame for the iris texture" )
  13. SHADER_PARAM( CORNEATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "cornea texture" )
  14. SHADER_PARAM( AMBIENTOCCLTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "reflection texture" )
  15. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  16. SHADER_PARAM( EYEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "origin for the eyes" )
  17. SHADER_PARAM( IRISU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0 ]", "U projection vector for the iris" )
  18. SHADER_PARAM( IRISV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the iris" )
  19. SHADER_PARAM( DILATION, SHADER_PARAM_TYPE_FLOAT, "0", "Pupil dilation (0 is none, 1 is maximal)" )
  20. SHADER_PARAM( GLOSSINESS, SHADER_PARAM_TYPE_FLOAT, "1", "Glossiness of eye (1 is default, 0 is not glossy at all)" )
  21. SHADER_PARAM( SPHERETEXKILLCOMBO, SHADER_PARAM_TYPE_BOOL, "1", "texkill pixels not on sphere" )
  22. SHADER_PARAM( RAYTRACESPHERE, SHADER_PARAM_TYPE_BOOL, "1", "Raytrace sphere" )
  23. SHADER_PARAM( PARALLAXSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1", "Parallax strength" )
  24. SHADER_PARAM( CORNEABUMPSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1", "Cornea strength" )
  25. SHADER_PARAM( AMBIENTOCCLCOLOR, SHADER_PARAM_TYPE_VEC3, "[1 1 1]", "Ambient occlusion color" )
  26. SHADER_PARAM( EYEBALLRADIUS, SHADER_PARAM_TYPE_FLOAT, "0", "Eyeball radius for ray casting" )
  27. SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is eyes in the ep1 intro" )
  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. SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
  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. // Emissive Scroll Pass
  37. SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" )
  38. SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" )
  39. SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" )
  40. SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" )
  41. SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  42. SHADER_PARAM( EMISSIVEBLENDFLOWTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" )
  43. END_SHADER_PARAMS
  44. void SetupVarsEyeRefract( Eye_Refract_Vars_t &info )
  45. {
  46. info.m_nFrame = FRAME;
  47. info.m_nIris = IRIS;
  48. info.m_nIrisFrame = IRISFRAME;
  49. info.m_nEyeOrigin = EYEORIGIN;
  50. info.m_nIrisU = IRISU;
  51. info.m_nIrisV = IRISV;
  52. info.m_nDilation = DILATION;
  53. info.m_nGlossiness = GLOSSINESS;
  54. info.m_nIntro = INTRO;
  55. info.m_nEntityOrigin = ENTITYORIGIN;
  56. info.m_nWarpParam = WARPPARAM;
  57. info.m_nCorneaTexture = CORNEATEXTURE;
  58. info.m_nAmbientOcclTexture = AMBIENTOCCLTEXTURE;
  59. info.m_nEnvmap = ENVMAP;
  60. info.m_nSphereTexKillCombo = SPHERETEXKILLCOMBO;
  61. info.m_nRaytraceSphere = RAYTRACESPHERE;
  62. info.m_nParallaxStrength = PARALLAXSTRENGTH;
  63. info.m_nCorneaBumpStrength = CORNEABUMPSTRENGTH;
  64. info.m_nAmbientOcclColor = AMBIENTOCCLCOLOR;
  65. info.m_nEyeballRadius = EYEBALLRADIUS;
  66. info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE;
  67. }
  68. // Cloak Pass
  69. void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info )
  70. {
  71. info.m_nCloakFactor = CLOAKFACTOR;
  72. info.m_nCloakColorTint = CLOAKCOLORTINT;
  73. info.m_nRefractAmount = REFRACTAMOUNT;
  74. }
  75. bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
  76. {
  77. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  78. {
  79. if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time
  80. return true;
  81. else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  82. return true;
  83. // else, not cloaking this frame, so check flag2 in case the base material still needs it
  84. }
  85. // Check flag2 if not drawing cloak pass
  86. return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE );
  87. }
  88. bool IsTranslucent( IMaterialVar **params ) const
  89. {
  90. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  91. {
  92. if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  93. return true;
  94. // else, not cloaking this frame, so check flag in case the base material still needs it
  95. }
  96. // Check flag if not drawing cloak pass
  97. return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
  98. }
  99. // Emissive Scroll Pass
  100. void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info )
  101. {
  102. info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH;
  103. info.m_nBaseTexture = IRIS;
  104. info.m_nFlowTexture = EMISSIVEBLENDFLOWTEXTURE;
  105. info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE;
  106. info.m_nEmissiveTint = EMISSIVEBLENDTINT;
  107. info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR;
  108. }
  109. SHADER_INIT_PARAMS()
  110. {
  111. Eye_Refract_Vars_t info;
  112. SetupVarsEyeRefract( info );
  113. InitParams_Eyes_Refract( this, params, pMaterialName, info );
  114. // Cloak Pass
  115. if ( !params[CLOAKPASSENABLED]->IsDefined() )
  116. {
  117. params[CLOAKPASSENABLED]->SetIntValue( 0 );
  118. }
  119. else if ( params[CLOAKPASSENABLED]->GetIntValue() )
  120. {
  121. CloakBlendedPassVars_t info;
  122. SetupVarsCloakBlendedPass( info );
  123. InitParamsCloakBlendedPass( this, params, pMaterialName, info );
  124. }
  125. // Emissive Scroll Pass
  126. if ( !params[EMISSIVEBLENDENABLED]->IsDefined() )
  127. {
  128. params[EMISSIVEBLENDENABLED]->SetIntValue( 0 );
  129. }
  130. else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  131. {
  132. EmissiveScrollBlendedPassVars_t info;
  133. SetupVarsEmissiveScrollBlendedPass( info );
  134. InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info );
  135. }
  136. }
  137. SHADER_FALLBACK
  138. {
  139. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  140. {
  141. return "Eyes_dx8";
  142. }
  143. return 0;
  144. }
  145. SHADER_INIT
  146. {
  147. Eye_Refract_Vars_t info;
  148. SetupVarsEyeRefract( info );
  149. Init_Eyes_Refract( this, params, info );
  150. // Cloak Pass
  151. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  152. {
  153. CloakBlendedPassVars_t info;
  154. SetupVarsCloakBlendedPass( info );
  155. InitCloakBlendedPass( this, params, info );
  156. }
  157. // Emissive Scroll Pass
  158. if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  159. {
  160. EmissiveScrollBlendedPassVars_t info;
  161. SetupVarsEmissiveScrollBlendedPass( info );
  162. InitEmissiveScrollBlendedPass( this, params, info );
  163. }
  164. }
  165. SHADER_DRAW
  166. {
  167. // Skip the standard rendering if cloak pass is fully opaque
  168. bool bDrawStandardEye = true;
  169. if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting
  170. {
  171. CloakBlendedPassVars_t info;
  172. SetupVarsCloakBlendedPass( info );
  173. if ( CloakBlendedPassIsFullyOpaque( params, info ) )
  174. {
  175. bDrawStandardEye = false;
  176. }
  177. }
  178. // Standard rendering pass
  179. if ( bDrawStandardEye )
  180. {
  181. Eye_Refract_Vars_t info;
  182. SetupVarsEyeRefract( info );
  183. Draw_Eyes_Refract( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  184. }
  185. else
  186. {
  187. // Skip this pass!
  188. Draw( false );
  189. }
  190. // Cloak Pass
  191. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  192. {
  193. // If ( snapshotting ) or ( we need to draw this frame )
  194. if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) )
  195. {
  196. CloakBlendedPassVars_t info;
  197. SetupVarsCloakBlendedPass( info );
  198. DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  199. }
  200. else // We're not snapshotting and we don't need to draw this frame
  201. {
  202. // Skip this pass!
  203. Draw( false );
  204. }
  205. }
  206. // Emissive Scroll Pass
  207. if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  208. {
  209. // If ( snapshotting ) or ( we need to draw this frame )
  210. if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) )
  211. {
  212. EmissiveScrollBlendedPassVars_t info;
  213. SetupVarsEmissiveScrollBlendedPass( info );
  214. DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  215. }
  216. else // We're not snapshotting and we don't need to draw this frame
  217. {
  218. // Skip this pass!
  219. Draw( false );
  220. }
  221. }
  222. }
  223. END_SHADER