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.

164 lines
8.3 KiB

  1. //========= Copyright 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. static LightmappedGeneric_DX9_Vars_t s_info;
  12. BEGIN_VS_SHADER( LightmappedGeneric,
  13. "Help for LightmappedGeneric" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
  16. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" )
  17. SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  18. SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" )
  19. SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" )
  20. SHADER_PARAM( ALPHA2, SHADER_PARAM_TYPE_FLOAT, "1", "" )
  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( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" )
  25. SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" )
  26. SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  27. SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" )
  28. SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" )
  29. SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" )
  30. SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" )
  31. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "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( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" )
  37. SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" )
  38. SHADER_PARAM( BUMPMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
  39. SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" )
  40. SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" )
  41. SHADER_PARAM( BUMPMASK, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" )
  42. SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture" )
  43. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" )
  44. SHADER_PARAM( BASETEXTURENOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" )
  45. SHADER_PARAM( BASETEXTURE2NOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" )
  46. SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0",
  47. "If this is 1, then when detail alpha=0, no base texture is blended and when "
  48. "detail alpha=1, you get detail*base*lightmap" )
  49. SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "light munging lookup texture" )
  50. SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" )
  51. SHADER_PARAM( MASKEDBLENDING, SHADER_PARAM_TYPE_INTEGER, "0", "blend using texture with no vertex alpha. For using texture blending on non-displacements" )
  52. SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" )
  53. SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" )
  54. SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" )
  55. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  56. SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.")
  57. SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha.");
  58. SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha.");
  59. SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.")
  60. SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." )
  61. SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline")
  62. SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline")
  63. SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline")
  64. SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline")
  65. SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline")
  66. END_SHADER_PARAMS
  67. void SetupVars( LightmappedGeneric_DX9_Vars_t& info )
  68. {
  69. info.m_nBaseTexture = BASETEXTURE;
  70. info.m_nBaseTextureFrame = FRAME;
  71. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  72. info.m_nAlbedo = ALBEDO;
  73. info.m_nSelfIllumTint = SELFILLUMTINT;
  74. info.m_nAlpha2 = ALPHA2;
  75. info.m_nDetail = DETAIL;
  76. info.m_nDetailFrame = DETAILFRAME;
  77. info.m_nDetailScale = DETAILSCALE;
  78. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  79. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  80. info.m_nDetailTint = DETAILTINT;
  81. info.m_nEnvmap = ENVMAP;
  82. info.m_nEnvmapFrame = ENVMAPFRAME;
  83. info.m_nEnvmapMask = ENVMAPMASK;
  84. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  85. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  86. info.m_nEnvmapTint = ENVMAPTINT;
  87. info.m_nBumpmap = BUMPMAP;
  88. info.m_nBumpFrame = BUMPFRAME;
  89. info.m_nBumpTransform = BUMPTRANSFORM;
  90. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  91. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  92. info.m_nFresnelReflection = FRESNELREFLECTION;
  93. info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING;
  94. info.m_nBumpmap2 = BUMPMAP2;
  95. info.m_nBumpFrame2 = BUMPFRAME2;
  96. info.m_nBumpTransform2 = BUMPTRANSFORM2;
  97. info.m_nBumpMask = BUMPMASK;
  98. info.m_nBaseTexture2 = BASETEXTURE2;
  99. info.m_nBaseTexture2Frame = FRAME2;
  100. info.m_nBaseTextureNoEnvmap = BASETEXTURENOENVMAP;
  101. info.m_nBaseTexture2NoEnvmap = BASETEXTURE2NOENVMAP;
  102. info.m_nDetailAlphaMaskBaseTexture = DETAIL_ALPHA_MASK_BASE_TEXTURE;
  103. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  104. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  105. info.m_nLightWarpTexture = LIGHTWARPTEXTURE;
  106. info.m_nBlendModulateTexture = BLENDMODULATETEXTURE;
  107. info.m_nMaskedBlending = MASKEDBLENDING;
  108. info.m_nBlendMaskTransform = BLENDMASKTRANSFORM;
  109. info.m_nSelfShadowedBumpFlag = SSBUMP;
  110. info.m_nSeamlessMappingScale = SEAMLESS_SCALE;
  111. info.m_nAlphaTestReference = ALPHATESTREFERENCE;
  112. info.m_nSoftEdges = SOFTEDGES;
  113. info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART;
  114. info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND;
  115. info.m_nOutline = OUTLINE;
  116. info.m_nOutlineColor = OUTLINECOLOR;
  117. info.m_nOutlineAlpha = OUTLINEALPHA;
  118. info.m_nOutlineStart0 = OUTLINESTART0;
  119. info.m_nOutlineStart1 = OUTLINESTART1;
  120. info.m_nOutlineEnd0 = OUTLINEEND0;
  121. info.m_nOutlineEnd1 = OUTLINEEND1;
  122. }
  123. SHADER_FALLBACK
  124. {
  125. if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  126. return "LightmappedGeneric_DX8";
  127. return 0;
  128. }
  129. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  130. SHADER_INIT_PARAMS()
  131. {
  132. SetupVars( s_info );
  133. InitParamsLightmappedGeneric_DX9( this, params, pMaterialName, s_info );
  134. }
  135. SHADER_INIT
  136. {
  137. SetupVars( s_info );
  138. InitLightmappedGeneric_DX9( this, params, s_info );
  139. }
  140. SHADER_DRAW
  141. {
  142. DrawLightmappedGeneric_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr );
  143. }
  144. END_SHADER