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.

182 lines
6.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "BaseVSShader.h"
  7. #include "unlittwotexture_vs20.inc"
  8. #include "monitorscreen_ps20.inc"
  9. #include "monitorscreen_ps20b.inc"
  10. #include "cpp_shader_constant_register_map.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. DEFINE_FALLBACK_SHADER( MonitorScreen, MonitorScreen_DX9 )
  14. BEGIN_VS_SHADER( MonitorScreen_DX9,
  15. "This is a shader that does a contrast/saturation version of base times lightmap." )
  16. BEGIN_SHADER_PARAMS
  17. SHADER_PARAM( CONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" )
  18. SHADER_PARAM( SATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" )
  19. SHADER_PARAM( TINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "monitor tint" )
  20. SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "second texture" )
  21. SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $texture2" )
  22. SHADER_PARAM( TEXTURE2TRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$texture2 texcoord transform" )
  23. END_SHADER_PARAMS
  24. // Set up anything that is necessary to make decisions in SHADER_FALLBACK.
  25. SHADER_INIT_PARAMS()
  26. {
  27. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  28. if( !params[CONTRAST]->IsDefined() )
  29. {
  30. params[CONTRAST]->SetFloatValue( 0.0f );
  31. }
  32. if( !params[SATURATION]->IsDefined() )
  33. {
  34. params[SATURATION]->SetFloatValue( 1.0f );
  35. }
  36. if( !params[TINT]->IsDefined() )
  37. {
  38. params[TINT]->SetVecValue( 1.0f, 1.0f, 1.0f );
  39. }
  40. if (!IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ))
  41. {
  42. CLEAR_FLAGS( MATERIAL_VAR_MODEL );
  43. }
  44. }
  45. SHADER_FALLBACK
  46. {
  47. if( params && !params[BASETEXTURE]->IsDefined() )
  48. return "LightmappedGeneric";
  49. return 0;
  50. }
  51. SHADER_INIT
  52. {
  53. if (params[BASETEXTURE]->IsDefined())
  54. {
  55. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  56. }
  57. if (params[TEXTURE2]->IsDefined())
  58. {
  59. LoadTexture( TEXTURE2, TEXTUREFLAGS_SRGB );
  60. }
  61. }
  62. SHADER_DRAW
  63. {
  64. bool bHasTexture2 = params[TEXTURE2]->IsTexture();
  65. BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true );
  66. bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use
  67. SHADOW_STATE
  68. {
  69. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  70. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  71. if ( bHasTexture2 )
  72. {
  73. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  74. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  75. }
  76. pShaderShadow->EnableSRGBWrite( true );
  77. // Either we've got a constant modulation
  78. bool isTranslucent = IsAlphaModulating();
  79. // Or we've got a texture alpha on either texture
  80. isTranslucent = isTranslucent || TextureIsTranslucent( BASETEXTURE, true ) ||
  81. TextureIsTranslucent( TEXTURE2, true );
  82. if ( isTranslucent )
  83. {
  84. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  85. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  86. else
  87. EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  88. }
  89. else
  90. {
  91. if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) )
  92. EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  93. else
  94. DisableAlphaBlending( );
  95. }
  96. // Set stream format (note that this shader supports compression)
  97. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  98. int nTexCoordCount = 1;
  99. int userDataSize = 0;
  100. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  101. DECLARE_STATIC_VERTEX_SHADER( unlittwotexture_vs20 );
  102. SET_STATIC_VERTEX_SHADER( unlittwotexture_vs20 );
  103. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  104. {
  105. DECLARE_STATIC_PIXEL_SHADER( monitorscreen_ps20b );
  106. SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE2, (bHasTexture2)?(1):(0) );
  107. SET_STATIC_PIXEL_SHADER( monitorscreen_ps20b );
  108. }
  109. else
  110. {
  111. DECLARE_STATIC_PIXEL_SHADER( monitorscreen_ps20 );
  112. SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE2, (bHasTexture2)?(1):(0) );
  113. SET_STATIC_PIXEL_SHADER( monitorscreen_ps20 );
  114. }
  115. DefaultFog();
  116. pShaderShadow->EnableAlphaWrites( bFullyOpaque );
  117. PI_BeginCommandBuffer();
  118. PI_SetModulationVertexShaderDynamicState();
  119. PI_EndCommandBuffer();
  120. }
  121. DYNAMIC_STATE
  122. {
  123. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE, FRAME );
  124. if( bHasTexture2 )
  125. {
  126. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, TEXTURE2, FRAME2 );
  127. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM );
  128. }
  129. SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM );
  130. SetPixelShaderConstant( 1, CONTRAST );
  131. SetPixelShaderConstant( 2, SATURATION );
  132. SetPixelShaderConstant( 3, TINT );
  133. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  134. float vEyePos_SpecExponent[4];
  135. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  136. vEyePos_SpecExponent[3] = 0.0f;
  137. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  138. DECLARE_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 );
  139. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  140. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  141. SET_DYNAMIC_VERTEX_SHADER_COMBO( WORLD_NORMAL, 0 );
  142. SET_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 );
  143. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  144. {
  145. DECLARE_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20b );
  146. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() );
  147. SET_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20b );
  148. }
  149. else
  150. {
  151. DECLARE_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20 );
  152. SET_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20 );
  153. }
  154. }
  155. Draw();
  156. }
  157. END_SHADER