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.

123 lines
5.1 KiB

  1. //========= Copyright (c) 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Cloaking shader for Spy in TF2 (and probably many other things to come)
  4. //
  5. // $NoKeywords: $
  6. //=====================================================================================//
  7. #include "BaseVSShader.h"
  8. #include "convar.h"
  9. #include "cloak_dx9_helper.h"
  10. // NOTE: This has to be the last file included!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( Cloak, Cloak_DX90 )
  13. BEGIN_VS_SHADER( Cloak_DX90, "Help for Cloak" )
  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( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  21. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  22. SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" )
  23. SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" )
  24. SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  25. SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
  26. SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" )
  27. SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" )
  28. SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0", "How cloaked? Zero is not cloaked, 1 is fully cloaked." )
  29. SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
  30. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" )
  31. SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" )
  32. SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" )
  33. SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" )
  34. SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" )
  35. SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" )
  36. // Rim lighting terms
  37. SHADER_PARAM( RIMLIGHT, SHADER_PARAM_TYPE_BOOL, "0", "enables rim lighting" )
  38. SHADER_PARAM( RIMLIGHTEXPONENT, SHADER_PARAM_TYPE_FLOAT, "4.0", "Exponent for rim lights" )
  39. SHADER_PARAM( RIMLIGHTBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Boost for rim lights" )
  40. SHADER_PARAM( RIMMASK, SHADER_PARAM_TYPE_BOOL, "0", "Indicates whether or not to use alpha channel of exponent texture to mask the rim term" )
  41. END_SHADER_PARAMS
  42. // FIXME: doesn't support Fresnel!
  43. void SetupVars( Cloak_DX9_Vars_t& info )
  44. {
  45. info.m_nBaseTexture = BASETEXTURE;
  46. info.m_nRefractAmount = REFRACTAMOUNT;
  47. info.m_nRefractTint = REFRACTTINT;
  48. info.m_nNormalMap = NORMALMAP;
  49. info.m_nBumpFrame = BUMPFRAME;
  50. info.m_nBumpTransform = BUMPTRANSFORM;
  51. info.m_nRefractTintTexture = REFRACTTINTTEXTURE;
  52. info.m_nRefractTintTextureFrame = REFRACTTINTTEXTUREFRAME;
  53. info.m_nFresnelReflection = FRESNELREFLECTION;
  54. info.m_nMasked = MASKED;
  55. info.m_nCloakFactor = CLOAKFACTOR;
  56. info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE;
  57. info.m_nPhongExponent = PHONGEXPONENT;
  58. info.m_nPhongTint = PHONGTINT;
  59. info.m_nPhongAlbedoTint = PHONGALBEDOTINT;
  60. info.m_nPhongExponentTexture = PHONGEXPONENTTEXTURE;
  61. info.m_nPhongBoost = PHONGBOOST;
  62. info.m_nPhongFresnelRanges = PHONGFRESNELRANGES;
  63. // Rim lighting parameters
  64. info.m_nRimLight = RIMLIGHT;
  65. info.m_nRimLightPower = RIMLIGHTEXPONENT;
  66. info.m_nRimLightBoost = RIMLIGHTBOOST;
  67. info.m_nRimMask = RIMMASK;
  68. }
  69. bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
  70. {
  71. if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time
  72. return true;
  73. else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  74. return true;
  75. else
  76. return false;
  77. }
  78. bool IsTranslucent( IMaterialVar **params ) const
  79. {
  80. if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  81. return true;
  82. else
  83. return false;
  84. }
  85. SHADER_INIT_PARAMS()
  86. {
  87. Cloak_DX9_Vars_t info;
  88. SetupVars( info );
  89. InitParamsCloak_DX9( this, params, pMaterialName, info );
  90. }
  91. SHADER_FALLBACK
  92. {
  93. return 0;
  94. }
  95. SHADER_INIT
  96. {
  97. Cloak_DX9_Vars_t info;
  98. SetupVars( info );
  99. InitCloak_DX9( this, params, info );
  100. }
  101. SHADER_DRAW
  102. {
  103. Cloak_DX9_Vars_t info;
  104. SetupVars( info );
  105. DrawCloak_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  106. }
  107. END_SHADER