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.

524 lines
24 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=====================================================================================//
  8. #include "BaseVSShader.h"
  9. #include "vertexlitgeneric_dx9_helper.h"
  10. #include "emissive_scroll_blended_pass_helper.h"
  11. #include "cloak_blended_pass_helper.h"
  12. #include "flesh_interior_blended_pass_helper.h"
  13. #include "weapon_sheen_pass_helper.h"
  14. BEGIN_VS_SHADER( VertexLitGeneric, "Help for VertexLitGeneric" )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
  17. SHADER_PARAM( COMPRESS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "compression wrinklemap" )
  18. SHADER_PARAM( STRETCH, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "expansion wrinklemap" )
  19. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  20. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  21. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  22. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  23. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  24. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" )
  25. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  26. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  27. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  28. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  29. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
  30. SHADER_PARAM( BUMPCOMPRESS, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "compression bump map" )
  31. SHADER_PARAM( BUMPSTRETCH, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "expansion bump map" )
  32. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  33. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  34. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  35. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  36. SHADER_PARAM( SELFILLUM_ENVMAPMASK_ALPHA, SHADER_PARAM_TYPE_FLOAT,"0.0","defines that self illum value comes from env map mask alpha" )
  37. SHADER_PARAM( SELFILLUMFRESNEL, SHADER_PARAM_TYPE_BOOL, "0", "Self illum fresnel" )
  38. SHADER_PARAM( SELFILLUMFRESNELMINMAXEXP, SHADER_PARAM_TYPE_VEC4, "0", "Self illum fresnel min, max, exp" )
  39. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  40. SHADER_PARAM( FLASHLIGHTNOLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Flashlight pass sets N.L=1.0" )
  41. SHADER_PARAM( LIGHTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "lightmap texture--will be bound by the engine")
  42. // Debugging term for visualizing ambient data on its own
  43. SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" )
  44. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" )
  45. SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" )
  46. SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" )
  47. SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
  48. SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "warp the specular term" )
  49. SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" )
  50. SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" )
  51. SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" )
  52. SHADER_PARAM( PHONGEXPONENTFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "When using a phong exponent texture, this will be multiplied by the 0..1 that comes out of the texture." )
  53. SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" )
  54. SHADER_PARAM( BASEMAPALPHAPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "indicates that there is no normal map and that the phong mask is in base alpha" )
  55. SHADER_PARAM( INVERTPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "invert the phong mask (0=full phong, 1=no phong)" )
  56. SHADER_PARAM( ENVMAPFRESNEL, SHADER_PARAM_TYPE_FLOAT, "0", "Degree to which Fresnel should be applied to env map" )
  57. SHADER_PARAM( SELFILLUMMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "If we bind a texture here, it overrides base alpha (if any) for self illum" )
  58. // detail (multi-) texturing
  59. SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" )
  60. SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." )
  61. SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" )
  62. SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" )
  63. // Rim lighting terms
  64. SHADER_PARAM( RIMLIGHT, SHADER_PARAM_TYPE_BOOL, "0", "enables rim lighting" )
  65. SHADER_PARAM( RIMLIGHTEXPONENT, SHADER_PARAM_TYPE_FLOAT, "4.0", "Exponent for rim lights" )
  66. SHADER_PARAM( RIMLIGHTBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Boost for rim lights" )
  67. SHADER_PARAM( RIMMASK, SHADER_PARAM_TYPE_BOOL, "0", "Indicates whether or not to use alpha channel of exponent texture to mask the rim term" )
  68. // Seamless mapping scale
  69. SHADER_PARAM( SEAMLESS_BASE, SHADER_PARAM_TYPE_BOOL, "0", "whether to apply seamless mapping to the base texture. requires a smooth model." )
  70. SHADER_PARAM( SEAMLESS_DETAIL, SHADER_PARAM_TYPE_BOOL, "0", "where to apply seamless mapping to the detail texture." )
  71. SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "the scale for the seamless mapping. # of repetions of texture per inch." )
  72. // Emissive Scroll Pass
  73. SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" )
  74. SHADER_PARAM( EMISSIVEBLENDBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" )
  75. SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" )
  76. SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" )
  77. SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" )
  78. SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  79. SHADER_PARAM( EMISSIVEBLENDFLOWTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" )
  80. SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" )
  81. // Cloak Pass
  82. SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" )
  83. SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  84. SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" )
  85. SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" )
  86. // Weapon Sheen Pass
  87. SHADER_PARAM( SHEENPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables weapon sheen render in a second pass" )
  88. SHADER_PARAM( SHEENMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "sheenmap" )
  89. SHADER_PARAM( SHEENMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "sheenmap mask" )
  90. SHADER_PARAM( SHEENMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  91. SHADER_PARAM( SHEENMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "sheenmap tint" )
  92. SHADER_PARAM( SHEENMAPMASKSCALEX, SHADER_PARAM_TYPE_FLOAT, "1", "X Scale the size of the map mask to the size of the target" )
  93. SHADER_PARAM( SHEENMAPMASKSCALEY, SHADER_PARAM_TYPE_FLOAT, "1", "Y Scale the size of the map mask to the size of the target" )
  94. SHADER_PARAM( SHEENMAPMASKOFFSETX, SHADER_PARAM_TYPE_FLOAT, "0", "X Offset of the mask relative to model space coords of target" )
  95. SHADER_PARAM( SHEENMAPMASKOFFSETY, SHADER_PARAM_TYPE_FLOAT, "0", "Y Offset of the mask relative to model space coords of target" )
  96. SHADER_PARAM( SHEENMAPMASKDIRECTION, SHADER_PARAM_TYPE_INTEGER, "0", "The direction the sheen should move (length direction of weapon) XYZ, 0,1,2" )
  97. SHADER_PARAM( SHEENINDEX, SHADER_PARAM_TYPE_INTEGER, "0", "Index of the Effect Type (Color Additive, Override etc...)" )
  98. // Flesh Interior Pass
  99. SHADER_PARAM( FLESHINTERIORENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable Flesh interior blend pass" )
  100. SHADER_PARAM( FLESHINTERIORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh color texture" )
  101. SHADER_PARAM( FLESHINTERIORNOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh noise texture" )
  102. SHADER_PARAM( FLESHBORDERTEXTURE1D, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh border 1D texture" )
  103. SHADER_PARAM( FLESHNORMALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh normal texture" )
  104. SHADER_PARAM( FLESHSUBSURFACETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh subsurface texture" )
  105. SHADER_PARAM( FLESHCUBETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh cubemap texture" )
  106. SHADER_PARAM( FLESHBORDERNOISESCALE, SHADER_PARAM_TYPE_FLOAT, "1.5", "Flesh Noise UV scalar for border" )
  107. SHADER_PARAM( FLESHDEBUGFORCEFLESHON, SHADER_PARAM_TYPE_BOOL, "0", "Flesh Debug full flesh" )
  108. SHADER_PARAM( FLESHEFFECTCENTERRADIUS1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" )
  109. SHADER_PARAM( FLESHEFFECTCENTERRADIUS2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" )
  110. SHADER_PARAM( FLESHEFFECTCENTERRADIUS3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" )
  111. SHADER_PARAM( FLESHEFFECTCENTERRADIUS4, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" )
  112. SHADER_PARAM( FLESHSUBSURFACETINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Subsurface Color" )
  113. SHADER_PARAM( FLESHBORDERWIDTH, SHADER_PARAM_TYPE_FLOAT, "0.3", "Flesh border" )
  114. SHADER_PARAM( FLESHBORDERSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.42", "Flesh border softness (> 0.0 && <= 0.5)" )
  115. SHADER_PARAM( FLESHBORDERTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Flesh border Color" )
  116. SHADER_PARAM( FLESHGLOBALOPACITY, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh global opacity" )
  117. SHADER_PARAM( FLESHGLOSSBRIGHTNESS, SHADER_PARAM_TYPE_FLOAT, "0.66", "Flesh gloss brightness" )
  118. SHADER_PARAM( FLESHSCROLLSPEED, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh scroll speed" )
  119. SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" )
  120. SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." )
  121. SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries. Only supported without bumpmaps" )
  122. SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." )
  123. SHADER_PARAM( BLENDTINTBYBASEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use the base alpha to blend in the $color modulation")
  124. SHADER_PARAM( BLENDTINTCOLOROVERBASE, SHADER_PARAM_TYPE_FLOAT, "0", "blend between tint acting as a multiplication versus a replace" )
  125. END_SHADER_PARAMS
  126. void SetupVars( VertexLitGeneric_DX9_Vars_t& info )
  127. {
  128. info.m_nBaseTexture = BASETEXTURE;
  129. info.m_nWrinkle = COMPRESS;
  130. info.m_nStretch = STRETCH;
  131. info.m_nBaseTextureFrame = FRAME;
  132. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  133. info.m_nAlbedo = ALBEDO;
  134. info.m_nSelfIllumTint = SELFILLUMTINT;
  135. info.m_nDetail = DETAIL;
  136. info.m_nDetailFrame = DETAILFRAME;
  137. info.m_nDetailScale = DETAILSCALE;
  138. info.m_nEnvmap = ENVMAP;
  139. info.m_nEnvmapFrame = ENVMAPFRAME;
  140. info.m_nEnvmapMask = ENVMAPMASK;
  141. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  142. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  143. info.m_nEnvmapTint = ENVMAPTINT;
  144. info.m_nBumpmap = BUMPMAP;
  145. info.m_nNormalWrinkle = BUMPCOMPRESS;
  146. info.m_nNormalStretch = BUMPSTRETCH;
  147. info.m_nBumpFrame = BUMPFRAME;
  148. info.m_nBumpTransform = BUMPTRANSFORM;
  149. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  150. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  151. info.m_nAlphaTestReference = ALPHATESTREFERENCE;
  152. info.m_nFlashlightNoLambert = FLASHLIGHTNOLAMBERT;
  153. info.m_nLightmap = LIGHTMAP;
  154. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  155. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  156. info.m_nSelfIllumEnvMapMask_Alpha = SELFILLUM_ENVMAPMASK_ALPHA;
  157. info.m_nSelfIllumFresnel = SELFILLUMFRESNEL;
  158. info.m_nSelfIllumFresnelMinMaxExp = SELFILLUMFRESNELMINMAXEXP;
  159. info.m_nAmbientOnly = AMBIENTONLY;
  160. info.m_nPhongExponent = PHONGEXPONENT;
  161. info.m_nPhongExponentTexture = PHONGEXPONENTTEXTURE;
  162. info.m_nPhongTint = PHONGTINT;
  163. info.m_nPhongAlbedoTint = PHONGALBEDOTINT;
  164. info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE;
  165. info.m_nPhongWarpTexture = PHONGWARPTEXTURE;
  166. info.m_nPhongBoost = PHONGBOOST;
  167. info.m_nPhongExponentFactor = PHONGEXPONENTFACTOR;
  168. info.m_nPhongFresnelRanges = PHONGFRESNELRANGES;
  169. info.m_nPhong = PHONG;
  170. info.m_nBaseMapAlphaPhongMask = BASEMAPALPHAPHONGMASK;
  171. info.m_nEnvmapFresnel = ENVMAPFRESNEL;
  172. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  173. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  174. info.m_nDetailTextureTransform = DETAILTEXTURETRANSFORM;
  175. // Rim lighting parameters
  176. info.m_nRimLight = RIMLIGHT;
  177. info.m_nRimLightPower = RIMLIGHTEXPONENT;
  178. info.m_nRimLightBoost = RIMLIGHTBOOST;
  179. info.m_nRimMask = RIMMASK;
  180. // seamless
  181. info.m_nSeamlessScale = SEAMLESS_SCALE;
  182. info.m_nSeamlessDetail = SEAMLESS_DETAIL;
  183. info.m_nSeamlessBase = SEAMLESS_BASE;
  184. info.m_nSeparateDetailUVs = SEPARATEDETAILUVS;
  185. info.m_nLinearWrite = LINEARWRITE;
  186. info.m_nDetailTint = DETAILTINT;
  187. info.m_nInvertPhongMask = INVERTPHONGMASK;
  188. info.m_nDepthBlend = DEPTHBLEND;
  189. info.m_nDepthBlendScale = DEPTHBLENDSCALE;
  190. info.m_nSelfIllumMask = SELFILLUMMASK;
  191. info.m_nBlendTintByBaseAlpha = BLENDTINTBYBASEALPHA;
  192. info.m_nTintReplacesBaseColor = BLENDTINTCOLOROVERBASE;
  193. }
  194. // Cloak Pass
  195. void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info )
  196. {
  197. info.m_nCloakFactor = CLOAKFACTOR;
  198. info.m_nCloakColorTint = CLOAKCOLORTINT;
  199. info.m_nRefractAmount = REFRACTAMOUNT;
  200. // Delete these lines if not bump mapping!
  201. info.m_nBumpmap = BUMPMAP;
  202. info.m_nBumpFrame = BUMPFRAME;
  203. info.m_nBumpTransform = BUMPTRANSFORM;
  204. }
  205. // Weapon Sheen Pass
  206. void SetupVarsWeaponSheenPass( WeaponSheenPassVars_t &info )
  207. {
  208. info.m_nSheenMap = SHEENMAP;
  209. info.m_nSheenMapMask = SHEENMAPMASK;
  210. info.m_nSheenMapMaskFrame = SHEENMAPMASKFRAME;
  211. info.m_nSheenMapTint = SHEENMAPTINT;
  212. info.m_nSheenMapMaskScaleX = SHEENMAPMASKSCALEX;
  213. info.m_nSheenMapMaskScaleY = SHEENMAPMASKSCALEY;
  214. info.m_nSheenMapMaskOffsetX = SHEENMAPMASKOFFSETX;
  215. info.m_nSheenMapMaskOffsetY = SHEENMAPMASKOFFSETY;
  216. info.m_nSheenMapMaskDirection = SHEENMAPMASKDIRECTION;
  217. info.m_nSheenIndex = SHEENINDEX;
  218. info.m_nBumpmap = BUMPMAP;
  219. info.m_nBumpFrame = BUMPFRAME;
  220. info.m_nBumpTransform = BUMPTRANSFORM;
  221. }
  222. bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const
  223. {
  224. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  225. {
  226. if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time
  227. return true;
  228. else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  229. return true;
  230. // else, not cloaking this frame, so check flag2 in case the base material still needs it
  231. }
  232. if ( params[SHEENPASSENABLED]->GetIntValue() ) // If material supports weapon sheen
  233. return true;
  234. // Check flag2 if not drawing cloak pass
  235. return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE );
  236. }
  237. bool IsTranslucent( IMaterialVar **params ) const
  238. {
  239. if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking
  240. {
  241. if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check
  242. return true;
  243. // else, not cloaking this frame, so check flag in case the base material still needs it
  244. }
  245. // Check flag if not drawing cloak pass
  246. return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
  247. }
  248. // Emissive Scroll Pass
  249. void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info )
  250. {
  251. info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH;
  252. info.m_nBaseTexture = EMISSIVEBLENDBASETEXTURE;
  253. info.m_nFlowTexture = EMISSIVEBLENDFLOWTEXTURE;
  254. info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE;
  255. info.m_nEmissiveTint = EMISSIVEBLENDTINT;
  256. info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR;
  257. info.m_nTime = TIME;
  258. }
  259. // Flesh Interior Pass
  260. void SetupVarsFleshInteriorBlendedPass( FleshInteriorBlendedPassVars_t &info )
  261. {
  262. info.m_nFleshTexture = FLESHINTERIORTEXTURE;
  263. info.m_nFleshNoiseTexture = FLESHINTERIORNOISETEXTURE;
  264. info.m_nFleshBorderTexture1D = FLESHBORDERTEXTURE1D;
  265. info.m_nFleshNormalTexture = FLESHNORMALTEXTURE;
  266. info.m_nFleshSubsurfaceTexture = FLESHSUBSURFACETEXTURE;
  267. info.m_nFleshCubeTexture = FLESHCUBETEXTURE;
  268. info.m_nflBorderNoiseScale = FLESHBORDERNOISESCALE;
  269. info.m_nflDebugForceFleshOn = FLESHDEBUGFORCEFLESHON;
  270. info.m_nvEffectCenterRadius1 = FLESHEFFECTCENTERRADIUS1;
  271. info.m_nvEffectCenterRadius2 = FLESHEFFECTCENTERRADIUS2;
  272. info.m_nvEffectCenterRadius3 = FLESHEFFECTCENTERRADIUS3;
  273. info.m_nvEffectCenterRadius4 = FLESHEFFECTCENTERRADIUS4;
  274. info.m_ncSubsurfaceTint = FLESHSUBSURFACETINT;
  275. info.m_nflBorderWidth = FLESHBORDERWIDTH;
  276. info.m_nflBorderSoftness = FLESHBORDERSOFTNESS;
  277. info.m_ncBorderTint = FLESHBORDERTINT;
  278. info.m_nflGlobalOpacity = FLESHGLOBALOPACITY;
  279. info.m_nflGlossBrightness = FLESHGLOSSBRIGHTNESS;
  280. info.m_nflScrollSpeed = FLESHSCROLLSPEED;
  281. info.m_nTime = TIME;
  282. }
  283. SHADER_INIT_PARAMS()
  284. {
  285. VertexLitGeneric_DX9_Vars_t vars;
  286. SetupVars( vars );
  287. InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, true, vars );
  288. // Cloak Pass
  289. if ( !params[CLOAKPASSENABLED]->IsDefined() )
  290. {
  291. params[CLOAKPASSENABLED]->SetIntValue( 0 );
  292. }
  293. else if ( params[CLOAKPASSENABLED]->GetIntValue() )
  294. {
  295. CloakBlendedPassVars_t info;
  296. SetupVarsCloakBlendedPass( info );
  297. InitParamsCloakBlendedPass( this, params, pMaterialName, info );
  298. }
  299. // Sheen Pass
  300. if ( !params[SHEENPASSENABLED]->IsDefined() )
  301. {
  302. params[SHEENPASSENABLED]->SetIntValue( 0 );
  303. }
  304. else if ( params[SHEENPASSENABLED]->GetIntValue() )
  305. {
  306. WeaponSheenPassVars_t info;
  307. SetupVarsWeaponSheenPass( info );
  308. InitParamsWeaponSheenPass( this, params, pMaterialName, info );
  309. }
  310. // Emissive Scroll Pass
  311. if ( !params[EMISSIVEBLENDENABLED]->IsDefined() )
  312. {
  313. params[EMISSIVEBLENDENABLED]->SetIntValue( 0 );
  314. }
  315. else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  316. {
  317. EmissiveScrollBlendedPassVars_t info;
  318. SetupVarsEmissiveScrollBlendedPass( info );
  319. InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info );
  320. }
  321. // Flesh Interior Pass
  322. if ( !params[FLESHINTERIORENABLED]->IsDefined() )
  323. {
  324. params[FLESHINTERIORENABLED]->SetIntValue( 0 );
  325. }
  326. else if ( params[FLESHINTERIORENABLED]->GetIntValue() )
  327. {
  328. FleshInteriorBlendedPassVars_t info;
  329. SetupVarsFleshInteriorBlendedPass( info );
  330. InitParamsFleshInteriorBlendedPass( this, params, pMaterialName, info );
  331. }
  332. }
  333. SHADER_FALLBACK
  334. {
  335. if (g_pHardwareConfig->GetDXSupportLevel() < 70)
  336. return "VertexLitGeneric_DX6";
  337. if (g_pHardwareConfig->GetDXSupportLevel() < 80)
  338. return "VertexLitGeneric_DX7";
  339. if (g_pHardwareConfig->GetDXSupportLevel() < 90)
  340. return "VertexLitGeneric_DX8";
  341. return 0;
  342. }
  343. SHADER_INIT
  344. {
  345. VertexLitGeneric_DX9_Vars_t vars;
  346. SetupVars( vars );
  347. InitVertexLitGeneric_DX9( this, params, true, vars );
  348. // Cloak Pass
  349. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  350. {
  351. CloakBlendedPassVars_t info;
  352. SetupVarsCloakBlendedPass( info );
  353. InitCloakBlendedPass( this, params, info );
  354. }
  355. // TODO : Only do this if we're in range of the camera
  356. // Weapon Sheen
  357. if ( params[SHEENPASSENABLED]->GetIntValue() )
  358. {
  359. WeaponSheenPassVars_t info;
  360. SetupVarsWeaponSheenPass( info );
  361. InitWeaponSheenPass( this, params, info );
  362. }
  363. // Emissive Scroll Pass
  364. if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  365. {
  366. EmissiveScrollBlendedPassVars_t info;
  367. SetupVarsEmissiveScrollBlendedPass( info );
  368. InitEmissiveScrollBlendedPass( this, params, info );
  369. }
  370. // Flesh Interior Pass
  371. if ( params[FLESHINTERIORENABLED]->GetIntValue() )
  372. {
  373. FleshInteriorBlendedPassVars_t info;
  374. SetupVarsFleshInteriorBlendedPass( info );
  375. InitFleshInteriorBlendedPass( this, params, info );
  376. }
  377. }
  378. SHADER_DRAW
  379. {
  380. // Skip the standard rendering if cloak pass is fully opaque
  381. bool bDrawStandardPass = true;
  382. if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting
  383. {
  384. CloakBlendedPassVars_t info;
  385. SetupVarsCloakBlendedPass( info );
  386. if ( CloakBlendedPassIsFullyOpaque( params, info ) )
  387. {
  388. bDrawStandardPass = false;
  389. }
  390. }
  391. // Standard rendering pass
  392. if ( bDrawStandardPass )
  393. {
  394. VertexLitGeneric_DX9_Vars_t vars;
  395. SetupVars( vars );
  396. DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, true, vars, vertexCompression, pContextDataPtr );
  397. }
  398. else
  399. {
  400. // Skip this pass!
  401. Draw( false );
  402. }
  403. // Weapon sheen pass
  404. // only if doing standard as well (don't do it if cloaked)
  405. if ( params[SHEENPASSENABLED]->GetIntValue() )
  406. {
  407. WeaponSheenPassVars_t info;
  408. SetupVarsWeaponSheenPass( info );
  409. if ( ( pShaderShadow != NULL ) || ( bDrawStandardPass && ShouldDrawMaterialSheen( params, info ) ) )
  410. {
  411. DrawWeaponSheenPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  412. }
  413. else
  414. {
  415. // Skip this pass!
  416. Draw( false );
  417. }
  418. }
  419. // Cloak Pass
  420. if ( params[CLOAKPASSENABLED]->GetIntValue() )
  421. {
  422. // If ( snapshotting ) or ( we need to draw this frame )
  423. if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) )
  424. {
  425. CloakBlendedPassVars_t info;
  426. SetupVarsCloakBlendedPass( info );
  427. DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  428. }
  429. else // We're not snapshotting and we don't need to draw this frame
  430. {
  431. // Skip this pass!
  432. Draw( false );
  433. }
  434. }
  435. // Emissive Scroll Pass
  436. if ( params[EMISSIVEBLENDENABLED]->GetIntValue() )
  437. {
  438. // If ( snapshotting ) or ( we need to draw this frame )
  439. if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) )
  440. {
  441. EmissiveScrollBlendedPassVars_t info;
  442. SetupVarsEmissiveScrollBlendedPass( info );
  443. DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  444. }
  445. else // We're not snapshotting and we don't need to draw this frame
  446. {
  447. // Skip this pass!
  448. Draw( false );
  449. }
  450. }
  451. // Flesh Interior Pass
  452. if ( params[FLESHINTERIORENABLED]->GetIntValue() )
  453. {
  454. // If ( snapshotting ) or ( we need to draw this frame )
  455. if ( ( pShaderShadow != NULL ) || ( true ) )
  456. {
  457. FleshInteriorBlendedPassVars_t info;
  458. SetupVarsFleshInteriorBlendedPass( info );
  459. DrawFleshInteriorBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  460. }
  461. else // We're not snapshotting and we don't need to draw this frame
  462. {
  463. // Skip this pass!
  464. Draw( false );
  465. }
  466. }
  467. }
  468. END_SHADER