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.

231 lines
11 KiB

  1. //===== Copyright � 1996-2005, 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 "shaderapifast.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. BEGIN_VS_SHADER( UnlitGeneric, "Help for UnlitGeneric" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
  16. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  17. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  18. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  19. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  20. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "envmap frame number" )
  21. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  22. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  23. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  24. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  25. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  26. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  27. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.7", "" )
  28. SHADER_PARAM( VERTEXALPHATEST, SHADER_PARAM_TYPE_INTEGER, "0", "" )
  29. SHADER_PARAM( HDRCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "hdr color scale" )
  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( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" )
  34. SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "2D map for warping specular" )
  35. SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" )
  36. SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" )
  37. SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" )
  38. SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" )
  39. 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" )
  40. SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." )
  41. SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" )
  42. SHADER_PARAM( DECALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Decal texture" )
  43. SHADER_PARAM( DECALBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining decal texture with base. 0=normal(decal*srca + base*(1-srca), 1= mod, 2=mod2x, 3=additive" )
  44. SHADER_PARAM( DISTANCEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use distance-coded alpha generated from hi-res texture by vtex.")
  45. SHADER_PARAM( DISTANCEALPHAFROMDETAIL, SHADER_PARAM_TYPE_BOOL, "0", "Take the distance-coded alpha mask from the detail texture.")
  46. SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.")
  47. SHADER_PARAM( SCALEEDGESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft edges based upon resolution. 1024x768 = nominal.")
  48. SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha.");
  49. SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha.");
  50. SHADER_PARAM( GLOW, SHADER_PARAM_TYPE_BOOL, "0", "Enable glow/shadow for distance coded textures.")
  51. SHADER_PARAM( GLOWCOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outter glow for distance coded line art." )
  52. SHADER_PARAM( GLOWALPHA, SHADER_PARAM_TYPE_FLOAT, "1", "Base glow alpha amount for glows/shadows with distance alpha." )
  53. SHADER_PARAM( GLOWSTART, SHADER_PARAM_TYPE_FLOAT, "0.7", "start value for glow/shadow")
  54. SHADER_PARAM( GLOWEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "end value for glow/shadow")
  55. SHADER_PARAM( GLOWX, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset x for glow mask.")
  56. SHADER_PARAM( GLOWY, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset y for glow mask.")
  57. SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.")
  58. SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." )
  59. SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline")
  60. SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline")
  61. SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline")
  62. SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline")
  63. SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline")
  64. SHADER_PARAM( SCALEOUTLINESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft part of the outline based upon resolution. 1024x768 = nominal.")
  65. SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" )
  66. SHADER_PARAM( GAMMACOLORREAD, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of color texture read." )
  67. SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." )
  68. SHADER_PARAM( RECEIVEFLASHLIGHT, SHADER_PARAM_TYPE_INTEGER, "0", "Forces this material to receive flashlights." )
  69. SHADER_PARAM( SINGLEPASSFLASHLIGHT, SHADER_PARAM_TYPE_INTEGER, "0", "Flags this material as possibly being run through single pass flashlight code" )
  70. SHADER_PARAM( DISPLACEMENTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Displacement map" )
  71. SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code")
  72. SHADER_PARAM( TINTMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Separate tint mask texture (as opposed to using basetexture alpha)" )
  73. END_SHADER_PARAMS
  74. void SetupVars( VertexLitGeneric_DX9_Vars_t& info )
  75. {
  76. info.m_nBaseTexture = BASETEXTURE;
  77. info.m_nBaseTextureFrame = FRAME;
  78. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  79. info.m_nAlbedo = ALBEDO;
  80. info.m_nSelfIllumTint = -1;
  81. info.m_nDetail = DETAIL;
  82. info.m_nDetailFrame = DETAILFRAME;
  83. info.m_nDetailScale = DETAILSCALE;
  84. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  85. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  86. info.m_nDetailTextureTransform = DETAILTEXTURETRANSFORM;
  87. info.m_nDecalTexture = DECALTEXTURE;
  88. info.m_nDecalTextureCombineMode = DECALBLENDMODE;
  89. info.m_nEnvmap = ENVMAP;
  90. info.m_nEnvmapFrame = ENVMAPFRAME;
  91. info.m_nEnvmapMask = ENVMAPMASK;
  92. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  93. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  94. info.m_nEnvmapTint = ENVMAPTINT;
  95. info.m_nBumpmap = -1;
  96. info.m_nBumpFrame = -1;
  97. info.m_nBumpTransform = -1;
  98. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  99. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  100. info.m_nAlphaTestReference = ALPHATESTREFERENCE;
  101. info.m_nVertexAlphaTest = VERTEXALPHATEST;
  102. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  103. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  104. info.m_nHDRColorScale = HDRCOLORSCALE;
  105. info.m_nPhongExponent = -1;
  106. info.m_nPhongExponentTexture = -1;
  107. info.m_nDiffuseWarpTexture = -1;
  108. info.m_nPhongWarpTexture = -1;
  109. info.m_nPhongBoost = -1;
  110. info.m_nPhongFresnelRanges = -1;
  111. info.m_nPhong = -1;
  112. info.m_nForcePhong = -1;
  113. info.m_nPhongTint = -1;
  114. info.m_nPhongAlbedoTint = -1;
  115. info.m_nSelfIllumEnvMapMask_Alpha = -1;
  116. info.m_nAmbientOnly = -1;
  117. info.m_nBaseMapAlphaPhongMask = -1;
  118. info.m_nEnvmapFresnel = -1;
  119. info.m_nSelfIllumMask = -1;
  120. info.m_nAmbientOcclusion = -1;
  121. info.m_nBaseMapLuminancePhongMask = -1;
  122. info.m_nDistanceAlpha = DISTANCEALPHA;
  123. info.m_nDistanceAlphaFromDetail = DISTANCEALPHAFROMDETAIL;
  124. info.m_nSoftEdges = SOFTEDGES;
  125. info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART;
  126. info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND;
  127. info.m_nScaleEdgeSoftnessBasedOnScreenRes = SCALEEDGESOFTNESSBASEDONSCREENRES;
  128. info.m_nGlow = GLOW;
  129. info.m_nGlowColor = GLOWCOLOR;
  130. info.m_nGlowAlpha = GLOWALPHA;
  131. info.m_nGlowStart = GLOWSTART;
  132. info.m_nGlowEnd = GLOWEND;
  133. info.m_nGlowX = GLOWX;
  134. info.m_nGlowY = GLOWY;
  135. info.m_nOutline = OUTLINE;
  136. info.m_nOutlineColor = OUTLINECOLOR;
  137. info.m_nOutlineAlpha = OUTLINEALPHA;
  138. info.m_nOutlineStart0 = OUTLINESTART0;
  139. info.m_nOutlineStart1 = OUTLINESTART1;
  140. info.m_nOutlineEnd0 = OUTLINEEND0;
  141. info.m_nOutlineEnd1 = OUTLINEEND1;
  142. info.m_nScaleOutlineSoftnessBasedOnScreenRes = SCALEOUTLINESOFTNESSBASEDONSCREENRES;
  143. info.m_nSeparateDetailUVs = SEPARATEDETAILUVS;
  144. info.m_nLinearWrite = LINEARWRITE;
  145. info.m_nGammaColorRead = GAMMACOLORREAD;
  146. info.m_nReceiveFlashlight = RECEIVEFLASHLIGHT;
  147. info.m_nSinglePassFlashlight = SINGLEPASSFLASHLIGHT;
  148. info.m_nShaderSrgbRead360 = SHADERSRGBREAD360;
  149. info.m_nDisplacementMap = DISPLACEMENTMAP;
  150. info.m_nTintMaskTexture = TINTMASKTEXTURE;
  151. }
  152. SHADER_INIT_PARAMS()
  153. {
  154. VertexLitGeneric_DX9_Vars_t vars;
  155. SetupVars( vars );
  156. InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, false, vars );
  157. }
  158. SHADER_FALLBACK
  159. {
  160. return 0;
  161. }
  162. SHADER_INIT
  163. {
  164. VertexLitGeneric_DX9_Vars_t vars;
  165. SetupVars( vars );
  166. InitVertexLitGeneric_DX9( this, params, false, vars );
  167. }
  168. SHADER_DRAW
  169. {
  170. VertexLitGeneric_DX9_Vars_t vars;
  171. SetupVars( vars );
  172. if ( ( pShaderShadow == NULL ) && ( pShaderAPI != NULL ) && (params[RECEIVEFLASHLIGHT]->GetIntValue() == 0) && ShaderApiFast( pShaderAPI )->InFlashlightMode() && !( IsX360() || IsPS3() ) ) // Not snapshotting && flashlight pass
  173. {
  174. // Don't go in here on the 360/PS3 with single-pass flashlight, because there is no 2nd draw call for this material.
  175. // FIXME: Is the !IsX360/PS3() test too broad?
  176. Draw( false );
  177. }
  178. else
  179. {
  180. DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, false, vars, vertexCompression, pContextDataPtr );
  181. }
  182. }
  183. void ExecuteFastPath( int *dynVSIdx, int *dynPSIdx, IMaterialVar** params, IShaderDynamicAPI * pShaderAPI,
  184. VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr, BOOL bCSMEnabled )
  185. {
  186. *dynVSIdx = -1;
  187. *dynPSIdx = -1;
  188. VertexLitGeneric_DX9_Vars_t vars;
  189. SetupVars( vars );
  190. // Only draw standard pass for now
  191. DrawVertexLitGeneric_DX9_ExecuteFastPath( dynVSIdx, dynPSIdx, this, params, pShaderAPI, vars, vertexCompression,
  192. pContextDataPtr, bCSMEnabled, false );
  193. }
  194. END_SHADER