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.

197 lines
6.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A wet version of base * lightmap
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "BaseVSShader.h"
  9. #include "particlesphere_vs20.inc"
  10. #include "particlesphere_ps20.inc"
  11. #include "particlesphere_ps20b.inc"
  12. #include "common_hlsl_cpp_consts.h"
  13. #include "cpp_shader_constant_register_map.h"
  14. static ConVar mat_depthfeather_enable( "mat_depthfeather_enable", "1", FCVAR_DEVELOPMENTONLY );
  15. int GetDefaultDepthFeatheringValue( void ); //defined in spritecard.cpp
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. DEFINE_FALLBACK_SHADER( ParticleSphere, ParticleSphere_DX9 )
  19. BEGIN_VS_SHADER_FLAGS( ParticleSphere_DX9, "Help for BumpmappedEnvMap", SHADER_NOT_EDITABLE )
  20. BEGIN_SHADER_PARAMS
  21. SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" )
  22. SHADER_PARAM( SCENEDEPTH, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  23. SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." )
  24. SHADER_PARAM( USINGPIXELSHADER, SHADER_PARAM_TYPE_BOOL, "0", "Tells to client code whether the shader is using DX8 vertex/pixel shaders or not" )
  25. SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bumpmap" )
  26. SHADER_PARAM( LIGHTS, SHADER_PARAM_TYPE_FOURCC, "", "array of lights" )
  27. SHADER_PARAM( LIGHT_POSITION, SHADER_PARAM_TYPE_VEC3, "0 0 0", "This is the directional light position." )
  28. SHADER_PARAM( LIGHT_COLOR, SHADER_PARAM_TYPE_VEC3, "1 1 1", "This is the directional light color." )
  29. END_SHADER_PARAMS
  30. SHADER_INIT_PARAMS()
  31. {
  32. if ( !params[DEPTHBLEND]->IsDefined() )
  33. {
  34. params[ DEPTHBLEND ]->SetIntValue( GetDefaultDepthFeatheringValue() );
  35. }
  36. if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() )
  37. {
  38. params[ DEPTHBLEND ]->SetIntValue( 0 );
  39. }
  40. if ( !params[DEPTHBLENDSCALE]->IsDefined() )
  41. {
  42. params[ DEPTHBLENDSCALE ]->SetFloatValue( 50.0f );
  43. }
  44. if ( IsPS3() && !params[SCENEDEPTH]->IsDefined() )
  45. {
  46. params[SCENEDEPTH]->SetStringValue( "^PS3^DEPTHBUFFER" );
  47. }
  48. }
  49. SHADER_INIT
  50. {
  51. params[USINGPIXELSHADER]->SetIntValue( true );
  52. if( params[SCENEDEPTH]->IsDefined() )
  53. {
  54. LoadTexture( SCENEDEPTH, 0 );
  55. }
  56. LoadBumpMap( BUMPMAP );
  57. }
  58. SHADER_FALLBACK
  59. {
  60. return 0;
  61. }
  62. SHADER_DRAW
  63. {
  64. // This matches the logic in spritecard.cpp closer
  65. bool bDepthBlend = false;
  66. if ( IsX360() || IsPS3() )
  67. {
  68. bDepthBlend = ( params[DEPTHBLEND]->GetIntValue() != 0 ) && mat_depthfeather_enable.GetBool();
  69. }
  70. SHADOW_STATE
  71. {
  72. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  73. if ( bDepthBlend )
  74. {
  75. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  76. }
  77. int tCoordDimensions[] = {2};
  78. pShaderShadow->VertexShaderVertexFormat(
  79. VERTEX_POSITION | VERTEX_COLOR, 1, tCoordDimensions, 0 );
  80. pShaderShadow->EnableBlending( true );
  81. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  82. pShaderShadow->EnableDepthWrites( false );
  83. DECLARE_STATIC_VERTEX_SHADER( particlesphere_vs20 );
  84. SET_STATIC_VERTEX_SHADER( particlesphere_vs20 );
  85. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  86. {
  87. DECLARE_STATIC_PIXEL_SHADER( particlesphere_ps20b );
  88. SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDepthBlend );
  89. SET_STATIC_PIXEL_SHADER( particlesphere_ps20b );
  90. }
  91. else
  92. {
  93. DECLARE_STATIC_PIXEL_SHADER( particlesphere_ps20 );
  94. SET_STATIC_PIXEL_SHADER( particlesphere_ps20 );
  95. }
  96. FogToFogColor();
  97. }
  98. DYNAMIC_STATE
  99. {
  100. BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_NONE, BUMPMAP );
  101. if ( bDepthBlend )
  102. {
  103. if ( IsPS3() )
  104. {
  105. BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, SCENEDEPTH, -1 );
  106. }
  107. else
  108. {
  109. pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, TEXTURE_FRAME_BUFFER_FULL_DEPTH );
  110. }
  111. }
  112. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[LIGHT_POSITION]->GetVecValue() );
  113. // Separate the light color into something that has a max value of 1 and a scale
  114. // so the vertex shader can determine if it's going to overflow the color and scale back
  115. // if it needs to.
  116. //
  117. // (It does this by seeing if the intensity*1/distSqr is > 1. If so, then it scales it so
  118. // it is equal to 1).
  119. const float *f = params[LIGHT_COLOR]->GetVecValue();
  120. Vector vLightColor( f[0], f[1], f[2] );
  121. float flScale = MAX( vLightColor.x, MAX( vLightColor.y, vLightColor.z ) );
  122. if ( flScale < 0.01f )
  123. flScale = 0.01f;
  124. float vScaleVec[3] = { flScale, flScale, flScale };
  125. vLightColor /= flScale;
  126. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vLightColor.Base() );
  127. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec );
  128. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  129. float vEyePos_SpecExponent[4];
  130. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  131. vEyePos_SpecExponent[3] = 0.0f;
  132. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  133. pShaderAPI->SetDepthFeatheringShaderConstants( 0, params[DEPTHBLENDSCALE]->GetFloatValue() );
  134. // Get viewport and render target dimensions and set shader constant to do a 2D mad
  135. int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
  136. pShaderAPI->GetCurrentViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
  137. int nRtWidth, nRtHeight;
  138. pShaderAPI->GetCurrentRenderTargetDimensions( nRtWidth, nRtHeight );
  139. // Compute viewport mad that takes projection space coords (post divide by W) into normalized screenspace, taking into account the currently set viewport.
  140. float vViewportMad[4];
  141. vViewportMad[0] = .5f * ( ( float )nViewportWidth / ( float )nRtWidth );
  142. vViewportMad[1] = -.5f * ( ( float )nViewportHeight / ( float )nRtHeight );
  143. vViewportMad[2] = vViewportMad[0] + ( ( float )nViewportX / ( float )nRtWidth );
  144. vViewportMad[3] = -vViewportMad[1] + ( ( float )nViewportY / ( float )nRtHeight );
  145. pShaderAPI->SetPixelShaderConstant( DEPTH_FEATHER_VIEWPORT_MAD, vViewportMad, 1 );
  146. // Compute the vertex shader index.
  147. DECLARE_DYNAMIC_VERTEX_SHADER( particlesphere_vs20 );
  148. SET_DYNAMIC_VERTEX_SHADER_COMBO( FOGTYPE, s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  149. SET_DYNAMIC_VERTEX_SHADER( particlesphere_vs20 );
  150. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  151. {
  152. DECLARE_DYNAMIC_PIXEL_SHADER( particlesphere_ps20b );
  153. SET_DYNAMIC_PIXEL_SHADER( particlesphere_ps20b );
  154. }
  155. else
  156. {
  157. DECLARE_DYNAMIC_PIXEL_SHADER( particlesphere_ps20 );
  158. SET_DYNAMIC_PIXEL_SHADER( particlesphere_ps20 );
  159. }
  160. }
  161. Draw();
  162. }
  163. END_SHADER