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.

94 lines
2.6 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. //
  3. // DirectX 9 Cloud shader
  4. //
  5. //===============================================================================
  6. #include "BaseVSShader.h"
  7. #include "cloud_vs20.inc"
  8. #include "cloud_ps20.inc"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. DEFINE_FALLBACK_SHADER( Cloud, Cloud_dx9 )
  12. BEGIN_VS_SHADER( Cloud_dx9, "Help for Cloud" )
  13. BEGIN_SHADER_PARAMS
  14. SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloud", "cloud texture", 0 )
  15. SHADER_PARAM( CLOUDALPHATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloudalpha", "cloud alpha texture" )
  16. SHADER_PARAM( CLOUDSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "cloudscale" )
  17. SHADER_PARAM( MASKSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "maskscale" )
  18. END_SHADER_PARAMS
  19. SHADER_FALLBACK
  20. {
  21. if( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  22. return "Cloud";
  23. return 0;
  24. }
  25. SHADER_INIT
  26. {
  27. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  28. LoadTexture( CLOUDALPHATEXTURE, TEXTUREFLAGS_SRGB );
  29. if ( !params[CLOUDSCALE]->IsDefined() )
  30. {
  31. params[CLOUDSCALE]->SetVecValue( 1.0f, 1.0f );
  32. }
  33. if ( !params[MASKSCALE]->IsDefined() )
  34. {
  35. params[MASKSCALE]->SetVecValue( 1.0f, 1.0f );
  36. }
  37. }
  38. SHADER_DRAW
  39. {
  40. SHADOW_STATE
  41. {
  42. pShaderShadow->EnableDepthWrites( false );
  43. pShaderShadow->EnableBlending( true );
  44. if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) )
  45. {
  46. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE );
  47. }
  48. else
  49. {
  50. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  51. }
  52. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  53. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  54. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 );
  55. DECLARE_STATIC_VERTEX_SHADER( cloud_vs20 );
  56. SET_STATIC_VERTEX_SHADER( cloud_vs20 );
  57. DECLARE_STATIC_PIXEL_SHADER( cloud_ps20 );
  58. SET_STATIC_PIXEL_SHADER( cloud_ps20 );
  59. DefaultFog();
  60. }
  61. DYNAMIC_STATE
  62. {
  63. BindTexture( SHADER_SAMPLER0, false, BASETEXTURE, FRAME );
  64. BindTexture( SHADER_SAMPLER1, false, CLOUDALPHATEXTURE );
  65. // Handle scrolling of base texture
  66. SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM, CLOUDSCALE );
  67. SetVertexShaderTextureScale( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, MASKSCALE );
  68. DECLARE_DYNAMIC_VERTEX_SHADER( cloud_vs20 );
  69. SET_DYNAMIC_VERTEX_SHADER( cloud_vs20 );
  70. DECLARE_DYNAMIC_PIXEL_SHADER( cloud_ps20 );
  71. SET_DYNAMIC_PIXEL_SHADER( cloud_ps20 );
  72. }
  73. Draw();
  74. }
  75. END_SHADER