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.

238 lines
13 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Lightmap only shader
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "convar.h"
  10. #include "lightmappedgeneric_dx9_helper.h"
  11. #include "lightmappedpaint_dx9_helper.h"
  12. // NOTE: This has to be the last file included!
  13. #include "tier0/memdbgon.h"
  14. static LightmappedGeneric_DX9_Vars_t s_info;
  15. BEGIN_VS_SHADER( LightmappedGeneric,
  16. "Help for LightmappedGeneric" )
  17. BEGIN_SHADER_PARAMS
  18. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  19. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  20. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  21. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  22. SHADER_PARAM( DETAIL2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture 2" )
  23. SHADER_PARAM( DETAILFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail2" )
  24. SHADER_PARAM( DETAILSCALE2, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture 2" )
  25. // detail (multi-) texturing
  26. 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" )
  27. SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." )
  28. SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" )
  29. SHADER_PARAM( DETAILBLENDFACTOR2, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture 2." )
  30. SHADER_PARAM( DETAILTINT2, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture 2 tint" )
  31. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  32. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  33. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  34. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  35. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  36. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  37. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
  38. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  39. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  40. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  41. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  42. SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
  43. SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" )
  44. SHADER_PARAM( BUMPMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
  45. SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  46. SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  47. SHADER_PARAM( BUMPMASK, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
  48. SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture" )
  49. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" )
  50. SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" )
  51. SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" )
  52. SHADER_PARAM( BUMP_FORCE_ON, SHADER_PARAM_TYPE_BOOL, "0", "force bump-mapping on, even for low-end machines" )
  53. SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" )
  54. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  55. SHADER_PARAM( ENVMAPANISOTROPY, SHADER_PARAM_TYPE_BOOL, "0", "Enable anisotropic cubemap lookups for macroscopically rough/microscopically smooth surfaces, like wet asphalt" )
  56. SHADER_PARAM( ENVMAPANISOTROPYSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "Scale anisotropy amount for cubemap lookups" )
  57. SHADER_PARAM( NOENVMAPMIP, SHADER_PARAM_TYPE_BOOL, "0", "Force envmap lookup to always use the top-level mip map" )
  58. SHADER_PARAM( ADDBUMPMAPS, SHADER_PARAM_TYPE_BOOL, "0", "Add bump map 1 and 2 together, renormalize" )
  59. SHADER_PARAM( BUMPDETAILSCALE1, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
  60. SHADER_PARAM( BUMPDETAILSCALE2, SHADER_PARAM_TYPE_FLOAT, "1.0", "" )
  61. #if defined( CSTRIKE15 )
  62. SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "1", "Simulate srgb read in shader code" )
  63. #else
  64. SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code")
  65. #endif
  66. SHADER_PARAM( ENVMAPLIGHTSCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "How much the lightmap effects environment map reflection, 0.0 is off, 1.0 will allow complete blackness of the environment map if the lightmap is black" )
  67. SHADER_PARAM( ENVMAPLIGHTSCALEMINMAX, SHADER_PARAM_TYPE_VEC2, "[0.0 1.0]", "Thresholds for the lightmap envmap effect. Setting the min higher increases the minimum light amount at which the envmap gets nerfed to nothing." )
  68. SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "1", "Phong" )
  69. SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for Key (CSM Casting) Light - on $basetexture" )
  70. SHADER_PARAM( PHONGEXPONENT2, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for Key (CSM Casting) Light - on $basetexture2" )
  71. SHADER_PARAM( PHONGBASETINT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount to tint Phong * $basetexture" )
  72. SHADER_PARAM( PHONGBASETINT2, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount to tint Phong * $basetexture2" )
  73. SHADER_PARAM( PHONGMASKCONTRASTBRIGHTNESS, SHADER_PARAM_TYPE_VEC2, "[1.0 0.0]", "Contrast and Brightness for Phong Mask generation using $basetexture" )
  74. SHADER_PARAM( PHONGMASKCONTRASTBRIGHTNESS2, SHADER_PARAM_TYPE_VEC2, "[1.0 0.0]", "Contrast and Brightness for Phong Mask generation using $basetexture2" )
  75. SHADER_PARAM( PHONGAMOUNT, SHADER_PARAM_TYPE_VEC4, "[1.0 1.0 1.0 1.0]", "Phong tint and amount on $basetexture > 1 to scale phong, .a is diffuseComponent multiplier, 0=> remove diffuse, >1 => overbright diffuse" )
  76. SHADER_PARAM( PHONGAMOUNT2, SHADER_PARAM_TYPE_VEC4, "[1.0 1.0 1.0 1.0]", "Phong tint and amount on $basetexture2 > 1 to scale phong, .a is diffuseComponent multiplier, 0=> remove diffuse, >1 => overbright diffuse" )
  77. SHADER_PARAM( BASETEXTURETRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$basetexture2 texcoord transform" )
  78. SHADER_PARAM( LAYERTINT1, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color tint for layer 1" )
  79. SHADER_PARAM( LAYERTINT2, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color tint for layer 2" )
  80. SHADER_PARAM( BLENDMODULATETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" )
  81. SHADER_PARAM( ENVMAPMASK2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask 2" )
  82. SHADER_PARAM( ENVMAPMASKFRAME2, SHADER_PARAM_TYPE_INTEGER, "", "" )
  83. SHADER_PARAM( ENVMAPMASKTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask2 texcoord transform" )
  84. SHADER_PARAM( NEWLAYERBLENDING, SHADER_PARAM_TYPE_BOOL, "0", "Enable new layer blend math" )
  85. SHADER_PARAM( BLENDSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.5", "Layer blend softness" )
  86. SHADER_PARAM( LAYERBORDERSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "0.5", "Layer border strength" )
  87. SHADER_PARAM( LAYERBORDEROFFSET, SHADER_PARAM_TYPE_FLOAT, "0.0", "Layer border offset" )
  88. SHADER_PARAM( LAYERBORDERSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.5", "Layer border softness" )
  89. SHADER_PARAM( LAYERBORDERTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color tint for layer border" )
  90. SHADER_PARAM( LAYEREDGENORMAL, SHADER_PARAM_TYPE_BOOL, "0", "Enable normals on layer edge" )
  91. SHADER_PARAM( LAYEREDGEPUNCHIN, SHADER_PARAM_TYPE_BOOL, "0", "Invert normals on layer edge" )
  92. SHADER_PARAM( LAYEREDGESTRENGTH, SHADER_PARAM_TYPE_FLOAT, "0.5", "Layer edge normal strength" )
  93. SHADER_PARAM( LAYEREDGESOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.5", "Layer edge normal blend softness" )
  94. SHADER_PARAM( LAYEREDGEOFFSET, SHADER_PARAM_TYPE_FLOAT, "0.0", "Layer edge normal blend offset" )
  95. END_SHADER_PARAMS
  96. void SetupVars( LightmappedGeneric_DX9_Vars_t& info )
  97. {
  98. info.m_nBaseTexture = BASETEXTURE;
  99. info.m_nBaseTextureFrame = FRAME;
  100. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  101. info.m_nSelfIllumTint = SELFILLUMTINT;
  102. info.m_nDetail = DETAIL;
  103. info.m_nDetailFrame = DETAILFRAME;
  104. info.m_nDetailScale = DETAILSCALE;
  105. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  106. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  107. info.m_nDetailTint = DETAILTINT;
  108. info.m_nDetail2 = DETAIL2;
  109. info.m_nDetailFrame2 = DETAILFRAME2;
  110. info.m_nDetailScale2 = DETAILSCALE2;
  111. info.m_nDetailTextureBlendFactor2 = DETAILBLENDFACTOR2;
  112. info.m_nDetailTint2 = DETAILTINT2;
  113. info.m_nEnvmap = ENVMAP;
  114. info.m_nEnvmapFrame = ENVMAPFRAME;
  115. info.m_nEnvmapMask = ENVMAPMASK;
  116. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  117. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  118. info.m_nEnvmapTint = ENVMAPTINT;
  119. info.m_nBumpmap = BUMPMAP;
  120. info.m_nBumpFrame = BUMPFRAME;
  121. info.m_nBumpTransform = BUMPTRANSFORM;
  122. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  123. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  124. info.m_nFresnelReflection = FRESNELREFLECTION;
  125. info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING;
  126. info.m_nBumpmap2 = BUMPMAP2;
  127. info.m_nBumpFrame2 = BUMPFRAME2;
  128. info.m_nBumpTransform2 = BUMPTRANSFORM2;
  129. info.m_nBumpMask = BUMPMASK;
  130. info.m_nBaseTexture2 = BASETEXTURE2;
  131. info.m_nBaseTextureFrame2 = FRAME2;
  132. info.m_nBaseTextureTransform2 = BASETEXTURETRANSFORM2;
  133. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  134. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  135. info.m_nBlendModulateTexture = BLENDMODULATETEXTURE;
  136. info.m_nSelfShadowedBumpFlag = SSBUMP;
  137. info.m_nForceBumpEnable = BUMP_FORCE_ON;
  138. info.m_nSeamlessMappingScale = SEAMLESS_SCALE;
  139. info.m_nAlphaTestReference = ALPHATESTREFERENCE;
  140. info.m_nEnvmapAnisotropy = ENVMAPANISOTROPY;
  141. info.m_nEnvmapAnisotropyScale = ENVMAPANISOTROPYSCALE;
  142. info.m_nNoEnvmapMip = NOENVMAPMIP;
  143. info.m_nAddBumpMaps = ADDBUMPMAPS;
  144. info.m_nBumpDetailScale1 = BUMPDETAILSCALE1;
  145. info.m_nBumpDetailScale2 = BUMPDETAILSCALE2;
  146. info.m_nShaderSrgbRead360 = SHADERSRGBREAD360;
  147. info.m_nEnvMapLightScale = ENVMAPLIGHTSCALE;
  148. info.m_nEnvMapLightScaleMinMax = ENVMAPLIGHTSCALEMINMAX;
  149. info.m_nPhong = PHONG;
  150. info.m_nPhongExp = PHONGEXPONENT;
  151. info.m_nPhongExp2 = PHONGEXPONENT2;
  152. info.m_nPhongBaseTint = PHONGBASETINT;
  153. info.m_nPhongBaseTint2 = PHONGBASETINT2;
  154. info.m_nPhongMaskContrastBrightness = PHONGMASKCONTRASTBRIGHTNESS;
  155. info.m_nPhongMaskContrastBrightness2 = PHONGMASKCONTRASTBRIGHTNESS2;
  156. info.m_nPhongAmount = PHONGAMOUNT;
  157. info.m_nPhongAmount2 = PHONGAMOUNT2;
  158. info.m_nLayerTint1 = LAYERTINT1;
  159. info.m_nLayerTint2 = LAYERTINT2;
  160. info.m_nBlendModulateTransform = BLENDMODULATETRANSFORM;
  161. info.m_nEnvmapMask2 = ENVMAPMASK2;
  162. info.m_nEnvmapMaskFrame2 = ENVMAPMASKFRAME2;
  163. info.m_nEnvmapMaskTransform2 = ENVMAPMASKTRANSFORM2;
  164. info.m_nAltLayerBlending = NEWLAYERBLENDING;
  165. info.m_nBlendSoftness = BLENDSOFTNESS;
  166. info.m_nLayerBorderStrength = LAYERBORDERSTRENGTH;
  167. info.m_nLayerBorderOffset = LAYERBORDEROFFSET;
  168. info.m_nLayerBorderSoftness = LAYERBORDERSOFTNESS;
  169. info.m_nLayerBorderTint = LAYERBORDERTINT;
  170. info.m_nLayerEdgePunchIn = LAYEREDGEPUNCHIN;
  171. info.m_nLayerEdgeStrength = LAYEREDGESTRENGTH;
  172. info.m_nLayerEdgeOffset = LAYEREDGEOFFSET;
  173. info.m_nLayerEdgeSoftness = LAYEREDGESOFTNESS;
  174. info.m_nLayerEdgeNormal = LAYEREDGENORMAL;
  175. }
  176. SHADER_FALLBACK
  177. {
  178. return 0;
  179. }
  180. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  181. SHADER_INIT_PARAMS()
  182. {
  183. SetupVars( s_info );
  184. InitParamsLightmappedGeneric_DX9( this, params, pMaterialName, s_info );
  185. }
  186. SHADER_INIT
  187. {
  188. SetupVars( s_info );
  189. InitLightmappedGeneric_DX9( this, params, s_info );
  190. }
  191. SHADER_DRAW
  192. {
  193. DrawLightmappedGeneric_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr );
  194. }
  195. void ExecuteFastPath( int *dynVSIdx, int *dynPSIdx, IMaterialVar** params, IShaderDynamicAPI * pShaderAPI,
  196. VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr, BOOL bCSMEnabled )
  197. {
  198. *dynVSIdx = -1;
  199. *dynPSIdx = -1;
  200. DrawLightmappedGeneric_DX9_FastPath( dynVSIdx, dynPSIdx, this, params, pShaderAPI, s_info, pContextDataPtr, bCSMEnabled );
  201. }
  202. END_SHADER