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.

111 lines
4.6 KiB

  1. //========= Copyright 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. DEFINE_FALLBACK_SHADER( Refract, Refract_DX90 )
  11. BEGIN_VS_SHADER( Refract_DX90, "Help for Refract" )
  12. BEGIN_SHADER_PARAMS
  13. SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
  14. SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE )
  15. SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" )
  16. SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" )
  17. SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" )
  18. SHADER_PARAM( NORMALMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" )
  19. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $normalmap" )
  20. SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $normalmap" )
  21. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$normalmap texcoord transform" )
  22. SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$normalmap texcoord transform" )
  23. SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" )
  24. SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "0, 1, or 2 for how much blur you want" )
  25. SHADER_PARAM( FADEOUTONSILHOUETTE, SHADER_PARAM_TYPE_BOOL, "1", "0 for no fade out on silhouette, 1 for fade out on sillhouette" )
  26. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  27. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" )
  28. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  29. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  30. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  31. SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" )
  32. SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  33. SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
  34. SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" )
  35. SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" )
  36. SHADER_PARAM( VERTEXCOLORMODULATE, SHADER_PARAM_TYPE_BOOL, "0","Use the vertex color to effect refract color. alpha will adjust refract amount" )
  37. SHADER_PARAM( FORCEALPHAWRITE, SHADER_PARAM_TYPE_BOOL, "0","Force the material to write alpha to the dest buffer" )
  38. END_SHADER_PARAMS
  39. // FIXME: doesn't support Fresnel!
  40. void SetupVars( Refract_DX9_Vars_t& info )
  41. {
  42. info.m_nBaseTexture = BASETEXTURE;
  43. info.m_nFrame = FRAME;
  44. info.m_nRefractAmount = REFRACTAMOUNT;
  45. info.m_nRefractTint = REFRACTTINT;
  46. info.m_nNormalMap = NORMALMAP;
  47. info.m_nNormalMap2 = NORMALMAP2;
  48. info.m_nBumpFrame = BUMPFRAME;
  49. info.m_nBumpFrame2 = BUMPFRAME2;
  50. info.m_nBumpTransform = BUMPTRANSFORM;
  51. info.m_nBumpTransform2 = BUMPTRANSFORM2;
  52. info.m_nBlurAmount = BLURAMOUNT;
  53. info.m_nFadeOutOnSilhouette = FADEOUTONSILHOUETTE;
  54. info.m_nEnvmap = ENVMAP;
  55. info.m_nEnvmapFrame = ENVMAPFRAME;
  56. info.m_nEnvmapTint = ENVMAPTINT;
  57. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  58. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  59. info.m_nRefractTintTexture = REFRACTTINTTEXTURE;
  60. info.m_nRefractTintTextureFrame = REFRACTTINTTEXTUREFRAME;
  61. info.m_nFresnelReflection = FRESNELREFLECTION;
  62. info.m_nNoWriteZ = NOWRITEZ;
  63. info.m_nMasked = MASKED;
  64. info.m_nVertexColorModulate = VERTEXCOLORMODULATE;
  65. info.m_nForceAlphaWrite = FORCEALPHAWRITE;
  66. }
  67. SHADER_INIT_PARAMS()
  68. {
  69. Refract_DX9_Vars_t info;
  70. SetupVars( info );
  71. InitParamsRefract_DX9( this, params, pMaterialName, info );
  72. }
  73. SHADER_FALLBACK
  74. {
  75. if( g_pHardwareConfig->GetDXSupportLevel() < 82 )
  76. return "Refract_DX80";
  77. return 0;
  78. }
  79. SHADER_INIT
  80. {
  81. Refract_DX9_Vars_t info;
  82. SetupVars( info );
  83. InitRefract_DX9( this, params, info );
  84. }
  85. SHADER_DRAW
  86. {
  87. Refract_DX9_Vars_t info;
  88. SetupVars( info );
  89. // If ( snapshotting ) or ( we need to draw this frame )
  90. bool bHasFlashlight = this->UsingFlashlight( params );
  91. if ( ( pShaderShadow != NULL ) || ( bHasFlashlight == false ) )
  92. {
  93. DrawRefract_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  94. }
  95. else
  96. {
  97. Draw( false );
  98. }
  99. }
  100. END_SHADER