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.

212 lines
12 KiB

  1. //========= Copyright � 1996-2014, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Multiblend shader
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "convar.h"
  10. #include "lightmapped_4wayblend_dx9_helper.h"
  11. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. static Lightmapped_4WayBlend_DX9_Vars_t s_info;
  14. BEGIN_VS_SHADER( Lightmapped_4WayBlend,
  15. "Help for Lightmapped_4WayBlend" )
  16. BEGIN_SHADER_PARAMS
  17. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  18. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  19. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  20. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  21. // detail (multi-) texturing
  22. 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" )
  23. SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." )
  24. SHADER_PARAM( DETAILBLENDFACTOR2, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture on texture 2." )
  25. SHADER_PARAM( DETAILBLENDFACTOR3, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture on texture 3." )
  26. SHADER_PARAM( DETAILBLENDFACTOR4, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture on texture 4." )
  27. SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" )
  28. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  29. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  30. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  31. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  32. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  33. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  34. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" )
  35. SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  36. SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  37. SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  38. SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  39. SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
  40. SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" )
  41. SHADER_PARAM( TEXTURE1_LUMSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 1 start component for lum smoothstep" )
  42. SHADER_PARAM( TEXTURE1_LUMEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 1 end component for lum smoothstep" )
  43. SHADER_PARAM( BUMPMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
  44. SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  45. SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  46. SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture" )
  47. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" )
  48. SHADER_PARAM( TEXTURE2_UVSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "uniform scale texture 2 uv coords" )
  49. SHADER_PARAM( TEXTURE2_BLENDSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 2 start component for blend smoothstep" )
  50. SHADER_PARAM( TEXTURE2_BLENDEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 2 end component for blend smoothstep" )
  51. SHADER_PARAM( TEXTURE2_LUMSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 2 start component for lum smoothstep" )
  52. SHADER_PARAM( TEXTURE2_LUMEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 2 end component for lum smoothstep" )
  53. SHADER_PARAM( TEXTURE2_BUMPBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 2 how much the bump blends in (ignored if bumpmap2 exists)" )
  54. SHADER_PARAM( BASETEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture 3" )
  55. SHADER_PARAM( TEXTURE3_BLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "blendmode for texture 3. 0 = blend, 1 = multiply 2x" )
  56. SHADER_PARAM( FRAME3, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture3" )
  57. SHADER_PARAM( TEXTURE3_UVSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "uniform scale texture 3 uv coords" )
  58. SHADER_PARAM( TEXTURE3_BLENDSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 3 start component for blend smoothstep" )
  59. SHADER_PARAM( TEXTURE3_BLENDEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 3 end component for blend smoothstep" )
  60. SHADER_PARAM( TEXTURE3_LUMSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 3 start component for lum smoothstep" )
  61. SHADER_PARAM( TEXTURE3_LUMEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 3 end component for lum smoothstep" )
  62. SHADER_PARAM( TEXTURE3_BUMPBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 3 how much the bump blends in" )
  63. SHADER_PARAM( BASETEXTURE4, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture 4" )
  64. SHADER_PARAM( TEXTURE4_BLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "blendmode for texture 4. 0 = blend, 1 = multiply 2x" )
  65. SHADER_PARAM( FRAME4, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture4" )
  66. SHADER_PARAM( TEXTURE4_UVSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "uniform scale texture 4 uv coords" )
  67. SHADER_PARAM( TEXTURE4_BLENDSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 4 start component for blend smoothstep" )
  68. SHADER_PARAM( TEXTURE4_BLENDEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 4 end component for blend smoothstep" )
  69. SHADER_PARAM( TEXTURE4_LUMSTART, SHADER_PARAM_TYPE_FLOAT, "0.0", "texture 4 start component for lum smoothstep" )
  70. SHADER_PARAM( TEXTURE4_LUMEND, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 4 end component for lum smoothstep" )
  71. SHADER_PARAM( TEXTURE4_BUMPBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "texture 4 how much the bump blends in" )
  72. SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" )
  73. SHADER_PARAM( BUMP_FORCE_ON, SHADER_PARAM_TYPE_BOOL, "0", "force bump-mapping on, even for low-end machines" )
  74. SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" )
  75. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  76. SHADER_PARAM( LUMBLENDFACTOR2, SHADER_PARAM_TYPE_FLOAT, "1.0", "blend factor between the luminance of layer 2 and layer one" )
  77. SHADER_PARAM( LUMBLENDFACTOR3, SHADER_PARAM_TYPE_FLOAT, "1.0", "blend factor between the luminance of layer 3 and layers below it" )
  78. SHADER_PARAM( LUMBLENDFACTOR4, SHADER_PARAM_TYPE_FLOAT, "1.0", "blend factor between the luminance of layer 4 and layers below it" )
  79. SHADER_PARAM( ENVMAPANISOTROPY, SHADER_PARAM_TYPE_BOOL, "0", "Enable anisotropic cubemap lookups for macroscopically rough/microscopically smooth surfaces, like wet asphalt" )
  80. SHADER_PARAM( ENVMAPANISOTROPYSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "Scale anisotropy amount for cubemap lookups" )
  81. #if defined( CSTRIKE15 )
  82. SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "1", "Simulate srgb read in shader code")
  83. #else
  84. SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code")
  85. #endif
  86. 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" )
  87. 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." )
  88. END_SHADER_PARAMS
  89. void SetupVars( Lightmapped_4WayBlend_DX9_Vars_t& info )
  90. {
  91. info.m_nBaseTexture = BASETEXTURE;
  92. info.m_nBaseTextureFrame = FRAME;
  93. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  94. info.m_nSelfIllumTint = SELFILLUMTINT;
  95. info.m_nDetail = DETAIL;
  96. info.m_nDetailFrame = DETAILFRAME;
  97. info.m_nDetailScale = DETAILSCALE;
  98. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  99. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  100. info.m_nDetailTextureBlendFactor2 = DETAILBLENDFACTOR2;
  101. info.m_nDetailTextureBlendFactor3 = DETAILBLENDFACTOR3;
  102. info.m_nDetailTextureBlendFactor4 = DETAILBLENDFACTOR4;
  103. info.m_nDetailTint = DETAILTINT;
  104. info.m_nEnvmap = ENVMAP;
  105. info.m_nEnvmapFrame = ENVMAPFRAME;
  106. info.m_nEnvmapMask = ENVMAPMASK;
  107. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  108. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  109. info.m_nEnvmapTint = ENVMAPTINT;
  110. info.m_nBumpmap = BUMPMAP;
  111. info.m_nBumpFrame = BUMPFRAME;
  112. info.m_nBumpTransform = BUMPTRANSFORM;
  113. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  114. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  115. info.m_nFresnelReflection = FRESNELREFLECTION;
  116. info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING;
  117. info.m_nTexture1LumStart = TEXTURE1_LUMSTART;
  118. info.m_nTexture1LumEnd = TEXTURE1_LUMEND;
  119. info.m_nBumpmap2 = BUMPMAP2;
  120. info.m_nBumpFrame2 = BUMPFRAME2;
  121. info.m_nBumpTransform2 = BUMPTRANSFORM2;
  122. info.m_nBaseTexture2 = BASETEXTURE2;
  123. info.m_nBaseTexture2Frame = FRAME2;
  124. info.m_nTexture2uvScale = TEXTURE2_UVSCALE;
  125. info.m_nTexture2BlendStart = TEXTURE2_BLENDSTART;
  126. info.m_nTexture2BlendEnd = TEXTURE2_BLENDEND;
  127. info.m_nTexture2LumStart = TEXTURE2_LUMSTART;
  128. info.m_nTexture2LumEnd = TEXTURE2_LUMEND;
  129. info.m_nTexture2BumpBlendFactor = TEXTURE2_BUMPBLENDFACTOR;
  130. info.m_nBaseTexture3 = BASETEXTURE3;
  131. info.m_nTexture3BlendMode = TEXTURE3_BLENDMODE;
  132. info.m_nBaseTexture3Frame = FRAME3;
  133. info.m_nTexture3uvScale = TEXTURE3_UVSCALE;
  134. info.m_nTexture3BlendStart = TEXTURE3_BLENDSTART;
  135. info.m_nTexture3BlendEnd = TEXTURE3_BLENDEND;
  136. info.m_nTexture3LumStart = TEXTURE3_LUMSTART;
  137. info.m_nTexture3LumEnd = TEXTURE3_LUMEND;
  138. info.m_nTexture3BumpBlendFactor = TEXTURE3_BUMPBLENDFACTOR;
  139. info.m_nBaseTexture4 = BASETEXTURE4;
  140. info.m_nTexture4BlendMode = TEXTURE4_BLENDMODE;
  141. info.m_nBaseTexture4Frame = FRAME4;
  142. info.m_nTexture4uvScale = TEXTURE4_UVSCALE;
  143. info.m_nTexture4BlendStart = TEXTURE4_BLENDSTART;
  144. info.m_nTexture4BlendEnd = TEXTURE4_BLENDEND;
  145. info.m_nTexture4LumStart = TEXTURE4_LUMSTART;
  146. info.m_nTexture4LumEnd = TEXTURE4_LUMEND;
  147. info.m_nTexture4BumpBlendFactor = TEXTURE4_BUMPBLENDFACTOR;
  148. info.m_nLumBlendFactor2 = LUMBLENDFACTOR2;
  149. info.m_nLumBlendFactor3 = LUMBLENDFACTOR3;
  150. info.m_nLumBlendFactor4 = LUMBLENDFACTOR4;
  151. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  152. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  153. info.m_nSelfShadowedBumpFlag = SSBUMP;
  154. info.m_nForceBumpEnable = BUMP_FORCE_ON;
  155. info.m_nSeamlessMappingScale = SEAMLESS_SCALE;
  156. info.m_nAlphaTestReference = ALPHATESTREFERENCE;
  157. info.m_nEnvmapAnisotropy = ENVMAPANISOTROPY;
  158. info.m_nEnvmapAnisotropyScale = ENVMAPANISOTROPYSCALE;
  159. info.m_nShaderSrgbRead360 = SHADERSRGBREAD360;
  160. info.m_nEnvMapLightScale = ENVMAPLIGHTSCALE;
  161. info.m_nEnvMapLightScaleMinMax = ENVMAPLIGHTSCALEMINMAX;
  162. }
  163. SHADER_FALLBACK
  164. {
  165. return 0;
  166. }
  167. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  168. SHADER_INIT_PARAMS()
  169. {
  170. SetupVars( s_info );
  171. InitParamsLightmapped_4WayBlend_DX9( this, params, pMaterialName, s_info );
  172. }
  173. SHADER_INIT
  174. {
  175. SetupVars( s_info );
  176. InitLightmapped_4WayBlend_DX9( this, params, s_info );
  177. }
  178. SHADER_DRAW
  179. {
  180. DrawLightmapped_4WayBlend_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr );
  181. }
  182. void ExecuteFastPath( int *dynVSIdx, int *dynPSIdx, IMaterialVar** params, IShaderDynamicAPI * pShaderAPI,
  183. VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr, BOOL bCSMEnabled )
  184. {
  185. *dynVSIdx = -1;
  186. *dynPSIdx = -1;
  187. DrawLightmapped_4WayBlend_DX9_FastPath( dynVSIdx, dynPSIdx, this, params, pShaderAPI, s_info, pContextDataPtr, bCSMEnabled );
  188. }
  189. END_SHADER