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.

150 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "BaseVSShader.h"
  7. #include "unlittwotexture.inc"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. DEFINE_FALLBACK_SHADER( MonitorScreen, MonitorScreen_DX8 )
  11. BEGIN_VS_SHADER( MonitorScreen_DX8,
  12. "This is a shader that does a contrast/saturation version of base times lightmap." )
  13. BEGIN_SHADER_PARAMS
  14. SHADER_PARAM( CONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  15. SHADER_PARAM( SATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  16. SHADER_PARAM( TINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "monitor tint" )
  17. SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "second texture" )
  18. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $texture2" )
  19. SHADER_PARAM( TEXTURE2TRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$texture2 texcoord transform" )
  20. END_SHADER_PARAMS
  21. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  22. SHADER_INIT_PARAMS()
  23. {
  24. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  25. if( !params[CONTRAST]->IsDefined() )
  26. {
  27. params[CONTRAST]->SetFloatValue( 0.0f );
  28. }
  29. if( !params[SATURATION]->IsDefined() )
  30. {
  31. params[SATURATION]->SetFloatValue( 1.0f );
  32. }
  33. if( !params[TINT]->IsDefined() )
  34. {
  35. params[TINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  36. }
  37. if (!IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ))
  38. {
  39. CLEAR_FLAGS( MATERIAL_VAR_MODEL );
  40. }
  41. }
  42. SHADER_FALLBACK
  43. {
  44. if( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 || (params && !params[BASETEXTURE]->IsDefined()) )
  45. {
  46. if( IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ) )
  47. {
  48. return "VertexLitGeneric_DX6";
  49. }
  50. else
  51. {
  52. return "LightmappedGeneric_DX6";
  53. }
  54. }
  55. return 0;
  56. }
  57. SHADER_INIT
  58. {
  59. if (params[BASETEXTURE]->IsDefined())
  60. {
  61. LoadTexture( BASETEXTURE );
  62. }
  63. if (params[TEXTURE2]->IsDefined())
  64. {
  65. LoadTexture( TEXTURE2 );
  66. }
  67. }
  68. SHADER_DRAW
  69. {
  70. bool bHasTexture2 = params[TEXTURE2]->IsTexture();
  71. SHADOW_STATE
  72. {
  73. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  74. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  75. if ( bHasTexture2 )
  76. {
  77. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  78. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  79. }
  80. pShaderShadow->EnableSRGBWrite( true );
  81. // Either we've got a constant modulation
  82. bool isTranslucent = IsAlphaModulating();
  83. // Or we've got a texture alpha on either texture
  84. isTranslucent = isTranslucent || TextureIsTranslucent( BASETEXTURE, true ) ||
  85. TextureIsTranslucent( TEXTURE2, true );
  86. if ( isTranslucent )
  87. {
  88. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  89. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  90. else
  91. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  92. }
  93. else
  94. {
  95. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  96. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  97. else
  98. DisableAlphaBlending( );
  99. }
  100. int fmt = VERTEX_POSITION | VERTEX_NORMAL;
  101. if (IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ))
  102. fmt |= VERTEX_COLOR;
  103. pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 );
  104. unlittwotexture_Static_Index vshIndex;
  105. pShaderShadow->SetVertexShader( "UnlitTwoTexture", vshIndex.GetIndex() );
  106. int pshIndex = bHasTexture2 ? 1 : 0;
  107. pShaderShadow->SetPixelShader( "MonitorScreen", pshIndex );
  108. DefaultFog();
  109. }
  110. DYNAMIC_STATE
  111. {
  112. BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME );
  113. if( bHasTexture2 )
  114. {
  115. BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 );
  116. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM );
  117. }
  118. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  119. SetPixelShaderConstant( 1, CONTRAST );
  120. SetPixelShaderConstant( 2, SATURATION );
  121. SetPixelShaderConstant( 3, TINT );
  122. SetModulationVertexShaderDynamicState();
  123. unlittwotexture_Dynamic_Index vshIndex;
  124. vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  125. vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 );
  126. pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() );
  127. }
  128. Draw();
  129. }
  130. END_SHADER