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.

200 lines
9.9 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. extern ConVar r_flashlight_version2;
  11. BEGIN_VS_SHADER( UnlitGeneric, "Help for UnlitGeneric" )
  12. BEGIN_SHADER_PARAMS
  13. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
  14. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  15. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  16. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  17. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  18. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "envmap frame number" )
  19. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  20. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  21. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  22. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  23. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  24. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  25. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.7", "" )
  26. SHADER_PARAM( VERTEXALPHATEST, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  27. SHADER_PARAM( HDRCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "hdr color scale" )
  28. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" )
  29. SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" )
  30. SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" )
  31. SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
  32. SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "2D map for warping specular" )
  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. SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" )
  37. 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" )
  38. SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." )
  39. SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" )
  40. SHADER_PARAM( SELFILLUMMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "If we bind a texture here, it overrides base alpha (if any) for self illum" )
  41. SHADER_PARAM( DISTANCEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use distance-coded alpha generated from hi-res texture by vtex.")
  42. SHADER_PARAM( DISTANCEALPHAFROMDETAIL, SHADER_PARAM_TYPE_BOOL, "0", "Take the distance-coded alpha mask from the detail texture.")
  43. SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.")
  44. SHADER_PARAM( SCALEEDGESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft edges based upon resolution. 1024x768 = nominal.")
  45. SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha.");
  46. SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha.");
  47. SHADER_PARAM( GLOW, SHADER_PARAM_TYPE_BOOL, "0", "Enable glow/shadow for distance coded textures.")
  48. SHADER_PARAM( GLOWCOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outter glow for distance coded line art." )
  49. SHADER_PARAM( GLOWALPHA, SHADER_PARAM_TYPE_FLOAT, "1", "Base glow alpha amount for glows/shadows with distance alpha." )
  50. SHADER_PARAM( GLOWSTART, SHADER_PARAM_TYPE_FLOAT, "0.7", "start value for glow/shadow")
  51. SHADER_PARAM( GLOWEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "end value for glow/shadow")
  52. SHADER_PARAM( GLOWX, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset x for glow mask.")
  53. SHADER_PARAM( GLOWY, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset y for glow mask.")
  54. SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.")
  55. SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." )
  56. SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline")
  57. SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline")
  58. SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline")
  59. SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline")
  60. SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline")
  61. SHADER_PARAM( SCALEOUTLINESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft part of the outline based upon resolution. 1024x768 = nominal.")
  62. SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" )
  63. SHADER_PARAM( GAMMACOLORREAD, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of color texture read." )
  64. SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." )
  65. SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" )
  66. SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." )
  67. SHADER_PARAM( RECEIVEFLASHLIGHT, SHADER_PARAM_TYPE_INTEGER, "0", "Forces this material to receive flashlights." )
  68. END_SHADER_PARAMS
  69. void SetupVars( VertexLitGeneric_DX9_Vars_t& info )
  70. {
  71. info.m_nBaseTexture = BASETEXTURE;
  72. info.m_nBaseTextureFrame = FRAME;
  73. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  74. info.m_nAlbedo = ALBEDO;
  75. info.m_nSelfIllumTint = -1;
  76. info.m_nDetail = DETAIL;
  77. info.m_nDetailFrame = DETAILFRAME;
  78. info.m_nDetailScale = DETAILSCALE;
  79. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  80. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  81. info.m_nDetailTextureTransform = DETAILTEXTURETRANSFORM;
  82. info.m_nEnvmap = ENVMAP;
  83. info.m_nEnvmapFrame = ENVMAPFRAME;
  84. info.m_nEnvmapMask = ENVMAPMASK;
  85. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  86. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  87. info.m_nEnvmapTint = ENVMAPTINT;
  88. info.m_nBumpmap = -1;
  89. info.m_nBumpFrame = -1;
  90. info.m_nBumpTransform = -1;
  91. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  92. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  93. info.m_nAlphaTestReference = ALPHATESTREFERENCE;
  94. info.m_nVertexAlphaTest = VERTEXALPHATEST;
  95. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  96. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  97. info.m_nHDRColorScale = HDRCOLORSCALE;
  98. info.m_nPhongExponent = -1;
  99. info.m_nPhongExponentTexture = -1;
  100. info.m_nDiffuseWarpTexture = -1;
  101. info.m_nPhongWarpTexture = -1;
  102. info.m_nPhongBoost = -1;
  103. info.m_nPhongFresnelRanges = -1;
  104. info.m_nPhong = -1;
  105. info.m_nPhongTint = -1;
  106. info.m_nPhongAlbedoTint = -1;
  107. info.m_nSelfIllumEnvMapMask_Alpha = -1;
  108. info.m_nAmbientOnly = -1;
  109. info.m_nBaseMapAlphaPhongMask = -1;
  110. info.m_nEnvmapFresnel = -1;
  111. info.m_nSelfIllumMask = -1;
  112. info.m_nDistanceAlpha = DISTANCEALPHA;
  113. info.m_nDistanceAlphaFromDetail = DISTANCEALPHAFROMDETAIL;
  114. info.m_nSoftEdges = SOFTEDGES;
  115. info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART;
  116. info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND;
  117. info.m_nScaleEdgeSoftnessBasedOnScreenRes = SCALEEDGESOFTNESSBASEDONSCREENRES;
  118. info.m_nGlow = GLOW;
  119. info.m_nGlowColor = GLOWCOLOR;
  120. info.m_nGlowAlpha = GLOWALPHA;
  121. info.m_nGlowStart = GLOWSTART;
  122. info.m_nGlowEnd = GLOWEND;
  123. info.m_nGlowX = GLOWX;
  124. info.m_nGlowY = GLOWY;
  125. info.m_nOutline = OUTLINE;
  126. info.m_nOutlineColor = OUTLINECOLOR;
  127. info.m_nOutlineAlpha = OUTLINEALPHA;
  128. info.m_nOutlineStart0 = OUTLINESTART0;
  129. info.m_nOutlineStart1 = OUTLINESTART1;
  130. info.m_nOutlineEnd0 = OUTLINEEND0;
  131. info.m_nOutlineEnd1 = OUTLINEEND1;
  132. info.m_nScaleOutlineSoftnessBasedOnScreenRes = SCALEOUTLINESOFTNESSBASEDONSCREENRES;
  133. info.m_nSeparateDetailUVs = SEPARATEDETAILUVS;
  134. info.m_nLinearWrite = LINEARWRITE;
  135. info.m_nGammaColorRead = GAMMACOLORREAD;
  136. info.m_nDepthBlend = DEPTHBLEND;
  137. info.m_nDepthBlendScale = DEPTHBLENDSCALE;
  138. info.m_nReceiveFlashlight = RECEIVEFLASHLIGHT;
  139. }
  140. SHADER_INIT_PARAMS()
  141. {
  142. VertexLitGeneric_DX9_Vars_t vars;
  143. SetupVars( vars );
  144. InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, false, vars );
  145. }
  146. SHADER_FALLBACK
  147. {
  148. if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  149. {
  150. return "UnlitGeneric_DX8";
  151. }
  152. return 0;
  153. }
  154. SHADER_INIT
  155. {
  156. VertexLitGeneric_DX9_Vars_t vars;
  157. SetupVars( vars );
  158. InitVertexLitGeneric_DX9( this, params, false, vars );
  159. }
  160. SHADER_DRAW
  161. {
  162. VertexLitGeneric_DX9_Vars_t vars;
  163. SetupVars( vars );
  164. bool bNewFlashlightPath = IsX360() || ( r_flashlight_version2.GetInt() != 0 );
  165. if ( ( pShaderShadow == NULL ) && ( pShaderAPI != NULL ) && !bNewFlashlightPath && pShaderAPI->InFlashlightMode() ) // Not snapshotting && flashlight pass
  166. {
  167. Draw( false );
  168. }
  169. else
  170. {
  171. DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, false, vars, vertexCompression, pContextDataPtr );
  172. }
  173. }
  174. END_SHADER