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.

141 lines
5.4 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "mathlib/vmatrix.h"
  4. #include "volume_clouds_helper.h"
  5. #include "convar.h"
  6. // Auto generated inc files
  7. #include "volume_clouds_vs20.inc"
  8. #include "volume_clouds_ps20.inc"
  9. #include "volume_clouds_ps20b.inc"
  10. // NOTE: This has to be the last file included!
  11. #include "tier0/memdbgon.h"
  12. void InitParamsVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, VolumeCloudsVars_t &info )
  13. {
  14. // Set material flags
  15. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  16. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  17. SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
  18. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f );
  19. // Set material parameter default values
  20. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nRefractAmount, kDefaultRefractAmount );
  21. }
  22. void InitVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, VolumeCloudsVars_t &info )
  23. {
  24. // Load textures
  25. if ( (info.m_nTexture1 != -1) && params[info.m_nTexture1]->IsDefined() )
  26. {
  27. pShader->LoadTexture( info.m_nTexture1, TEXTUREFLAGS_SRGB );
  28. }
  29. if ( (info.m_nTexture2 != -1) && params[info.m_nTexture2]->IsDefined() )
  30. {
  31. pShader->LoadTexture( info.m_nTexture2, TEXTUREFLAGS_SRGB );
  32. }
  33. if ( (info.m_nTexture3 != -1) && params[info.m_nTexture3]->IsDefined() )
  34. {
  35. pShader->LoadTexture( info.m_nTexture3, TEXTUREFLAGS_SRGB );
  36. }
  37. }
  38. void DrawVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  39. IShaderShadow* pShaderShadow, VolumeCloudsVars_t &info, VertexCompressionType_t vertexCompression )
  40. {
  41. SHADOW_STATE
  42. {
  43. // Set stream format (note that this shader supports compression)
  44. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  45. int nTexCoordCount = 1;
  46. int userDataSize = 0;
  47. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  48. // Vertex Shader
  49. DECLARE_STATIC_VERTEX_SHADER( volume_clouds_vs20 );
  50. SET_STATIC_VERTEX_SHADER( volume_clouds_vs20 );
  51. // Pixel Shader
  52. if( g_pHardwareConfig->SupportsPixelShaders_2_b() && !IsOpenGL() ) // Always send OpenGL down the 20 path (rg - why?)
  53. {
  54. DECLARE_STATIC_PIXEL_SHADER( volume_clouds_ps20b );
  55. SET_STATIC_PIXEL_SHADER( volume_clouds_ps20b );
  56. }
  57. else
  58. {
  59. DECLARE_STATIC_PIXEL_SHADER( volume_clouds_ps20 );
  60. SET_STATIC_PIXEL_SHADER( volume_clouds_ps20 );
  61. }
  62. // Textures
  63. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  64. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  65. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  66. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  67. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  68. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true );
  69. pShaderShadow->EnableSRGBWrite( true );
  70. // Blending
  71. pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  72. pShaderShadow->EnableAlphaWrites( false );
  73. // !!! We need to turn this back on because EnableAlphaBlending() above disables it!
  74. //pShaderShadow->EnableDepthWrites( true );
  75. }
  76. DYNAMIC_STATE
  77. {
  78. // Set Vertex Shader Combos
  79. DECLARE_DYNAMIC_VERTEX_SHADER( volume_clouds_vs20 );
  80. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  81. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  82. SET_DYNAMIC_VERTEX_SHADER( volume_clouds_vs20 );
  83. // Set Vertex Shader Constants
  84. // Time
  85. float vPackedVsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  86. float flTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime();
  87. float flRotateSpeed = 0.065f;
  88. vPackedVsConst1[0] = flTime * flRotateSpeed * 1.0f;
  89. vPackedVsConst1[1] = flTime * flRotateSpeed * 2.0f;
  90. vPackedVsConst1[2] = flTime * flRotateSpeed * 4.0f;
  91. vPackedVsConst1[0] -= (float)( (int)( vPackedVsConst1[0] / ( 2.0f * 3.14159f ) ) ) * 2.0f * 3.14159f;
  92. vPackedVsConst1[1] -= (float)( (int)( vPackedVsConst1[1] / ( 2.0f * 3.14159f ) ) ) * 2.0f * 3.14159f;
  93. vPackedVsConst1[2] -= (float)( (int)( vPackedVsConst1[2] / ( 2.0f * 3.14159f ) ) ) * 2.0f * 3.14159f;
  94. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vPackedVsConst1, 1 );
  95. // Set Pixel Shader Combos
  96. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() && !IsOpenGL() ) // Always send OpenGL down the 20 path (rg - why?)
  97. {
  98. DECLARE_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20b );
  99. SET_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20b );
  100. }
  101. else
  102. {
  103. DECLARE_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20 );
  104. SET_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20 );
  105. }
  106. // Bind textures
  107. pShader->BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nTexture1 );
  108. pShader->BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nTexture2 );
  109. pShader->BindTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nTexture3 );
  110. // Set Pixel Shader Constants
  111. float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  112. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos );
  113. pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 );
  114. float vPackedConst6[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  115. vPackedConst6[0] = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount;
  116. vPackedConst6[1] = vPackedVsConst1[0]; // Time % 1000
  117. pShaderAPI->SetPixelShaderConstant( 6, vPackedConst6, 1 );
  118. }
  119. pShader->Draw();
  120. }