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.

99 lines
3.5 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "portal_refract_helper.h"
  4. // memdbgon must be the last include file in a .cpp file!!!
  5. #include "tier0/memdbgon.h"
  6. DEFINE_FALLBACK_SHADER( PortalRefract, PortalRefract_dx9 )
  7. BEGIN_VS_SHADER( PortalRefract_dx9, "PortalRefract" )
  8. BEGIN_SHADER_PARAMS
  9. SHADER_PARAM( STAGE, SHADER_PARAM_TYPE_INTEGER, "0", "Stage of portal rendering (0, 1, 2)" )
  10. SHADER_PARAM( PORTALOPENAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal open amount 0.0-1.0" )
  11. SHADER_PARAM( PORTALSTATIC, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal static amount 0.0-1.0" )
  12. SHADER_PARAM( PORTALMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Mask texture" )
  13. SHADER_PARAM( TEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "Texcoord transform" )
  14. SHADER_PARAM( PORTALCOLORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Color texture" )
  15. SHADER_PARAM( PORTALCOLORGRADIENTDARK, SHADER_PARAM_TYPE_COLOR, "[0.0 0.0 0.0]", "The dark end of a tint gradient if not using a color texture" )
  16. SHADER_PARAM( PORTALCOLORGRADIENTLIGHT, SHADER_PARAM_TYPE_COLOR, "[1.0 1.0 1.0]", "The light end of a tint gradient if not using a color texture" )
  17. SHADER_PARAM( PORTALCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal color scale" )
  18. SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" )
  19. SHADER_PARAM( USEONSTATICPROP, SHADER_PARAM_TYPE_BOOL, "0", "Activate special mode to use this shader on a static prop" )
  20. END_SHADER_PARAMS
  21. void SetupVarsPortalRefract( PortalRefractVars_t &info )
  22. {
  23. info.m_nStage = STAGE;
  24. info.m_nPortalOpenAmount = PORTALOPENAMOUNT;
  25. info.m_nPortalStatic = PORTALSTATIC;
  26. info.m_nPortalMaskTexture = PORTALMASKTEXTURE;
  27. info.m_nTextureTransform = TEXTURETRANSFORM;
  28. info.m_nPortalColorTexture = PORTALCOLORTEXTURE;
  29. info.m_nPortalColorGradientDark = PORTALCOLORGRADIENTDARK;
  30. info.m_nPortalColorGradientLight = PORTALCOLORGRADIENTLIGHT;
  31. info.m_nPortalColorScale = PORTALCOLORSCALE;
  32. info.m_nTime = TIME;
  33. info.m_nUseOnStaticProp = USEONSTATICPROP;
  34. }
  35. bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
  36. {
  37. // For setting model flag at load time
  38. if ( bCheckSpecificToThisFrame == false )
  39. return true;
  40. // We only need the texture for stage 0
  41. if ( params[STAGE]->GetIntValue() == 0 )
  42. {
  43. //Msg( "Portal Refract @ %f time\n", params[TIME]->GetFloatValue() );
  44. return true;
  45. }
  46. else
  47. {
  48. return false;
  49. }
  50. }
  51. SHADER_INIT_PARAMS()
  52. {
  53. PortalRefractVars_t info;
  54. SetupVarsPortalRefract( info );
  55. InitParamsPortalRefract( this, params, pMaterialName, info );
  56. }
  57. SHADER_FALLBACK
  58. {
  59. return 0;
  60. }
  61. SHADER_INIT
  62. {
  63. PortalRefractVars_t info;
  64. SetupVarsPortalRefract( info );
  65. InitPortalRefract( this, params, info );
  66. }
  67. SHADER_DRAW
  68. {
  69. // Skip drawing if in stage 0 and the portal isn't partially opened
  70. bool bDraw = true;
  71. if ( ( params[STAGE]->GetIntValue() == 0 ) && ( ( params[PORTALOPENAMOUNT]->GetFloatValue() <= 0.0f ) || ( params[PORTALOPENAMOUNT]->GetFloatValue() >= 1.0f ) ) ) // If in stage 0 and not partially opened
  72. {
  73. bDraw = false;
  74. }
  75. // If ( snapshotting ) or ( we need to draw this frame )
  76. if ( ( pShaderShadow != NULL ) || ( bDraw == true ) )
  77. {
  78. PortalRefractVars_t info;
  79. SetupVarsPortalRefract( info );
  80. DrawPortalRefract( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  81. }
  82. else // We're not snapshotting and we don't need to draw this frame
  83. {
  84. // Skip this pass!
  85. Draw( false );
  86. }
  87. }
  88. END_SHADER