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.

157 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "convar.h"
  10. #include "worldvertextransition_dx8_helper.h"
  11. #include "lightmappedgeneric_dx9_helper.h"
  12. static LightmappedGeneric_DX9_Vars_t s_info;
  13. DEFINE_FALLBACK_SHADER( WorldVertexTransition, WorldVertexTransition_DX9 )
  14. BEGIN_VS_SHADER( WorldVertexTransition_DX9, "Help for WorldVertexTransition" )
  15. BEGIN_SHADER_PARAMS
  16. SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" )
  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( 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/shader1_normal", "bump map" )
  42. SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail 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( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" )
  52. SHADER_PARAM( MASKEDBLENDING, SHADER_PARAM_TYPE_INTEGER, "0", "blend using texture with no vertex alpha. For using texture blending on non-displacements" )
  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. END_SHADER_PARAMS
  56. void SetupVars( WorldVertexTransitionEditor_DX8_Vars_t& info )
  57. {
  58. info.m_nBaseTextureVar = BASETEXTURE;
  59. info.m_nBaseTextureFrameVar = FRAME;
  60. info.m_nBaseTextureTransformVar = BASETEXTURETRANSFORM;
  61. info.m_nBaseTexture2Var = BASETEXTURE2;
  62. info.m_nBaseTexture2FrameVar = FRAME2;
  63. info.m_nBaseTexture2TransformVar = BASETEXTURETRANSFORM; // FIXME!!!!
  64. }
  65. void SetupVars( LightmappedGeneric_DX9_Vars_t& info )
  66. {
  67. info.m_nBaseTexture = BASETEXTURE;
  68. info.m_nBaseTextureFrame = FRAME;
  69. info.m_nBaseTextureTransform = BASETEXTURETRANSFORM;
  70. info.m_nAlbedo = ALBEDO;
  71. info.m_nSelfIllumTint = SELFILLUMTINT;
  72. info.m_nDetail = DETAIL;
  73. info.m_nDetailFrame = DETAILFRAME;
  74. info.m_nDetailScale = DETAILSCALE;
  75. info.m_nDetailTextureCombineMode = DETAILBLENDMODE;
  76. info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR;
  77. info.m_nDetailTint = DETAILTINT;
  78. info.m_nEnvmap = ENVMAP;
  79. info.m_nEnvmapFrame = ENVMAPFRAME;
  80. info.m_nEnvmapMask = ENVMAPMASK;
  81. info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME;
  82. info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM;
  83. info.m_nEnvmapTint = ENVMAPTINT;
  84. info.m_nBumpmap = BUMPMAP;
  85. info.m_nBumpFrame = BUMPFRAME;
  86. info.m_nBumpTransform = BUMPTRANSFORM;
  87. info.m_nEnvmapContrast = ENVMAPCONTRAST;
  88. info.m_nEnvmapSaturation = ENVMAPSATURATION;
  89. info.m_nFresnelReflection = FRESNELREFLECTION;
  90. info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING;
  91. info.m_nBumpmap2 = BUMPMAP2;
  92. info.m_nBumpFrame2 = BUMPFRAME2;
  93. info.m_nBaseTexture2 = BASETEXTURE2;
  94. info.m_nBaseTexture2Frame = FRAME2;
  95. info.m_nBumpTransform2 = BUMPTRANSFORM2;
  96. info.m_nBumpMask = BUMPMASK;
  97. info.m_nBaseTextureNoEnvmap = BASETEXTURENOENVMAP;
  98. info.m_nBaseTexture2NoEnvmap = BASETEXTURE2NOENVMAP;
  99. info.m_nDetailAlphaMaskBaseTexture = DETAIL_ALPHA_MASK_BASE_TEXTURE;
  100. info.m_nFlashlightTexture = FLASHLIGHTTEXTURE;
  101. info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME;
  102. info.m_nLightWarpTexture = LIGHTWARPTEXTURE;
  103. info.m_nBlendModulateTexture = BLENDMODULATETEXTURE;
  104. info.m_nBlendMaskTransform = BLENDMASKTRANSFORM;
  105. info.m_nMaskedBlending = MASKEDBLENDING;
  106. info.m_nSelfShadowedBumpFlag = SSBUMP;
  107. info.m_nSeamlessMappingScale = SEAMLESS_SCALE;
  108. info.m_nAlphaTestReference = -1;
  109. }
  110. SHADER_FALLBACK
  111. {
  112. if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  113. return "WorldVertexTransition_DX8";
  114. return 0;
  115. }
  116. SHADER_INIT_PARAMS()
  117. {
  118. SetupVars( s_info );
  119. InitParamsLightmappedGeneric_DX9( this, params, pMaterialName, s_info );
  120. }
  121. SHADER_INIT
  122. {
  123. SetupVars( s_info );
  124. InitLightmappedGeneric_DX9( this, params, s_info );
  125. }
  126. SHADER_DRAW
  127. {
  128. if ( UsingEditor( params ) )
  129. {
  130. WorldVertexTransitionEditor_DX8_Vars_t info;
  131. SetupVars( info );
  132. DrawWorldVertexTransitionEditor_DX8( this, params, pShaderAPI, pShaderShadow, info );
  133. return;
  134. }
  135. DrawLightmappedGeneric_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr );
  136. }
  137. END_SHADER