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.

249 lines
9.0 KiB

  1. //========= Copyright � 1996-2006, 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( AMBIENTOCCLUSION, SHADER_PARAM_TYPE_FLOAT, "1.0", "Dynamic ambient occlusion strength" )
  27. SHADER_PARAM( EYEBALLRADIUS, SHADER_PARAM_TYPE_FLOAT, "0", "Eyeball radius for ray casting" )
  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_nEntityOrigin = ENTITYORIGIN;
  55. info.m_nWarpParam = WARPPARAM;
  56. info.m_nCorneaTexture = CORNEATEXTURE;
  57. info.m_nAmbientOcclTexture = AMBIENTOCCLTEXTURE;
  58. info.m_nEnvmap = ENVMAP;
  59. info.m_nSphereTexKillCombo = SPHERETEXKILLCOMBO;
  60. info.m_nRaytraceSphere = RAYTRACESPHERE;
  61. info.m_nParallaxStrength = PARALLAXSTRENGTH;
  62. info.m_nCorneaBumpStrength = CORNEABUMPSTRENGTH;
  63. info.m_nAmbientOcclColor = AMBIENTOCCLCOLOR;
  64. info.m_nEyeballRadius = EYEBALLRADIUS;
  65. info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE;
  66. info.m_nAmbientOcclusion = AMBIENTOCCLUSION;
  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. return 0;
  140. }
  141. SHADER_INIT
  142. {
  143. Eye_Refract_Vars_t info;
  144. SetupVarsEyeRefract( info );
  145. Init_Eyes_Refract( this, params, info );
  146. // Cloak Pass
  147. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  148. {
  149. CloakBlendedPassVars_t info;
  150. SetupVarsCloakBlendedPass( info );
  151. InitCloakBlendedPass( this, params, info );
  152. }
  153. // Emissive Scroll Pass
  154. if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  155. {
  156. EmissiveScrollBlendedPassVars_t info;
  157. SetupVarsEmissiveScrollBlendedPass( info );
  158. InitEmissiveScrollBlendedPass( this, params, info );
  159. }
  160. }
  161. SHADER_DRAW
  162. {
  163. // Skip the standard rendering if cloak pass is fully opaque
  164. bool bDrawStandardEye = true;
  165. if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting
  166. {
  167. CloakBlendedPassVars_t info;
  168. SetupVarsCloakBlendedPass( info );
  169. if ( CloakBlendedPassIsFullyOpaque( params, info ) )
  170. {
  171. bDrawStandardEye = false;
  172. }
  173. }
  174. // Standard rendering pass
  175. if ( bDrawStandardEye )
  176. {
  177. Eye_Refract_Vars_t info;
  178. SetupVarsEyeRefract( info );
  179. Draw_Eyes_Refract( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  180. }
  181. else
  182. {
  183. // Skip this pass!
  184. Draw( false );
  185. }
  186. // Cloak Pass
  187. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  188. {
  189. // If ( snapshotting ) or ( we need to draw this frame )
  190. if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) )
  191. {
  192. CloakBlendedPassVars_t info;
  193. SetupVarsCloakBlendedPass( info );
  194. DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  195. }
  196. else // We're not snapshotting and we don't need to draw this frame
  197. {
  198. // Skip this pass!
  199. Draw( false );
  200. }
  201. }
  202. // Emissive Scroll Pass
  203. if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  204. {
  205. // If ( snapshotting ) or ( we need to draw this frame )
  206. if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) )
  207. {
  208. EmissiveScrollBlendedPassVars_t info;
  209. SetupVarsEmissiveScrollBlendedPass( info );
  210. DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  211. }
  212. else // We're not snapshotting and we don't need to draw this frame
  213. {
  214. // Skip this pass!
  215. Draw( false );
  216. }
  217. }
  218. }
  219. END_SHADER