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.

85 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #include "shaderlib/cshader.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. DEFINE_FALLBACK_SHADER( UnlitTwoTexture, UnlitTwoTexture_DX6 )
  12. BEGIN_SHADER( UnlitTwoTexture_DX6,
  13. "Help for UnlitTwoTexture_DX6" )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "second texture" )
  16. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $texture2" )
  17. SHADER_PARAM( TEXTURE2TRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$texture2 texcoord transform" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT
  20. {
  21. if (params[BASETEXTURE]->IsDefined())
  22. LoadTexture( BASETEXTURE );
  23. if (params[TEXTURE2]->IsDefined())
  24. LoadTexture( TEXTURE2 );
  25. }
  26. SHADER_DRAW
  27. {
  28. SHADOW_STATE
  29. {
  30. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  31. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  32. SetModulationShadowState();
  33. // Either we've got a constant modulation
  34. bool isTranslucent = IsAlphaModulating();
  35. // Or we've got a texture alpha on either texture
  36. isTranslucent = isTranslucent || TextureIsTranslucent( BASETEXTURE, true ) ||
  37. TextureIsTranslucent( TEXTURE2, true );
  38. if ( isTranslucent )
  39. {
  40. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  41. {
  42. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  43. }
  44. else
  45. {
  46. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  47. }
  48. }
  49. else
  50. {
  51. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  52. {
  53. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  54. }
  55. else
  56. {
  57. DisableAlphaBlending( );
  58. }
  59. }
  60. pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 |
  61. SHADER_DRAW_TEXCOORD1 );
  62. DefaultFog();
  63. }
  64. DYNAMIC_STATE
  65. {
  66. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  67. SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM );
  68. BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 );
  69. SetFixedFunctionTextureTransform( MATERIAL_TEXTURE1, TEXTURE2TRANSFORM );
  70. SetModulationDynamicState();
  71. }
  72. Draw();
  73. }
  74. END_SHADER