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.

125 lines
5.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BaseVSShader.h"
  8. #include "convar.h"
  9. #include "refract_dx9_helper.h"
  10. // NOTE: This has to be the last file included!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( Refract, Refract_DX90 )
  13. BEGIN_VS_SHADER( Refract_DX90, "Help for Refract" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
  16. SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE )
  17. SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" )
  18. SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" )
  19. SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" )
  20. SHADER_PARAM( NORMALMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" )
  21. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $normalmap" )
  22. SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $normalmap" )
  23. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$normalmap texcoord transform" )
  24. SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$normalmap texcoord transform" )
  25. SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" )
  26. SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "0, 1, or 2 for how much blur you want" )
  27. SHADER_PARAM( FADEOUTONSILHOUETTE, SHADER_PARAM_TYPE_BOOL, "1", "0 for no fade out on silhouette, 1 for fade out on sillhouette" )
  28. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  29. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" )
  30. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  31. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  32. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  33. SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" )
  34. SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  35. SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
  36. SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" )
  37. SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" )
  38. SHADER_PARAM( VERTEXCOLORMODULATE, SHADER_PARAM_TYPE_BOOL, "0","Use the vertex color to effect refract color. alpha will adjust refract amount" )
  39. SHADER_PARAM( NOVIEWPORTFIXUP, SHADER_PARAM_TYPE_INTEGER, "0", "Don't adjust uv's for current viewport" )
  40. SHADER_PARAM( MIRRORABOUTVIEWPORTEDGES, SHADER_PARAM_TYPE_INTEGER, "0", "don't sample outside of the viewport" )
  41. SHADER_PARAM( MAGNIFYENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable magnification of refracted image around the $magnifyCenter screen position by $magnifyScale" )
  42. SHADER_PARAM( MAGNIFYCENTER, SHADER_PARAM_TYPE_VEC2, "[0 0]", "Magnify refracted image around this screen position" )
  43. SHADER_PARAM( MAGNIFYSCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Magnify refracted image by this factor" )
  44. SHADER_PARAM( LOCALREFRACT, SHADER_PARAM_TYPE_BOOL, "0", "" )
  45. SHADER_PARAM( LOCALREFRACTDEPTH, SHADER_PARAM_TYPE_FLOAT, "0", "" )
  46. END_SHADER_PARAMS
  47. // FIXME: doesn't support Fresnel!
  48. void SetupVars( Refract_DX9_Vars_t& info )
  49. {
  50. info.m_nBaseTexture = BASETEXTURE;
  51. info.m_nFrame = FRAME;
  52. info.m_nRefractAmount = REFRACTAMOUNT;
  53. info.m_nRefractTint = REFRACTTINT;
  54. info.m_nNormalMap = NORMALMAP;
  55. info.m_nNormalMap2 = NORMALMAP2;
  56. info.m_nBumpFrame = BUMPFRAME;
  57. info.m_nBumpFrame2 = BUMPFRAME2;
  58. info.m_nBumpTransform = BUMPTRANSFORM;
  59. info.m_nBumpTransform2 = BUMPTRANSFORM2;
  60. info.m_nBlurAmount = BLURAMOUNT;
  61. info.m_nFadeOutOnSilhouette = FADEOUTONSILHOUETTE;
  62. info.m_nEnvmap = ENVMAP;
  63. info.m_nEnvmapFrame = ENVMAPFRAME;
  64. info.m_nEnvmapTint = ENVMAPTINT;
  65. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  66. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  67. info.m_nRefractTintTexture = REFRACTTINTTEXTURE;
  68. info.m_nRefractTintTextureFrame = REFRACTTINTTEXTUREFRAME;
  69. info.m_nFresnelReflection = FRESNELREFLECTION;
  70. info.m_nNoWriteZ = NOWRITEZ;
  71. info.m_nMasked = MASKED;
  72. info.m_nVertexColorModulate = VERTEXCOLORMODULATE;
  73. info.m_nNoViewportFixup = NOVIEWPORTFIXUP;
  74. info.m_nMirrorAboutViewportEdges = MIRRORABOUTVIEWPORTEDGES;
  75. info.m_nMagnifyEnable = MAGNIFYENABLE;
  76. info.m_nMagnifyCenter = MAGNIFYCENTER;
  77. info.m_nMagnifyScale = MAGNIFYSCALE;
  78. info.m_nLocalRefract = LOCALREFRACT;
  79. info.m_nLocalRefractDepth = LOCALREFRACTDEPTH;
  80. }
  81. SHADER_INIT_PARAMS()
  82. {
  83. Refract_DX9_Vars_t info;
  84. SetupVars( info );
  85. InitParamsRefract_DX9( this, params, pMaterialName, info );
  86. }
  87. SHADER_FALLBACK
  88. {
  89. return 0;
  90. }
  91. SHADER_INIT
  92. {
  93. Refract_DX9_Vars_t info;
  94. SetupVars( info );
  95. InitRefract_DX9( this, params, info );
  96. }
  97. SHADER_DRAW
  98. {
  99. Refract_DX9_Vars_t info;
  100. SetupVars( info );
  101. // If ( snapshotting ) or ( we need to draw this frame )
  102. bool bHasFlashlight = this->UsingFlashlight( params );
  103. bool bSinglePassFlashlight = ( pShaderAPI != NULL ) ? pShaderAPI->SinglePassFlashlightModeEnabled() : false;
  104. if ( ( pShaderShadow != NULL ) || ( !bHasFlashlight ) || ( bSinglePassFlashlight ) )
  105. {
  106. DrawRefract_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  107. }
  108. else
  109. {
  110. Draw( false );
  111. }
  112. }
  113. END_SHADER