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.

111 lines
4.2 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "common_flashlight_fxc.h"
  7. #include "shader_constant_register_map.h"
  8. const float4 g_vShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS );
  9. sampler SpotSampler : register( s0 );
  10. sampler BaseTextureSampler : register( s1 );
  11. sampler IrisSampler : register( s3 );
  12. #if FLASHLIGHTSHADOWS && (!SHADER_MODEL_PS_1_1) && (!SHADER_MODEL_PS_1_4) && (!SHADER_MODEL_PS_2_0)
  13. sampler FlashlightDepthSampler : register( s4 );
  14. sampler RandomRotationSampler : register( s5 );
  15. #endif
  16. #if UBERLIGHT && defined( SHADER_MODEL_PS_3_0 )
  17. const float3 g_vSmoothEdge0 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_0 ); // ps_3_0 and up (over 32 registers)
  18. const float3 g_vSmoothEdge1 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_1 );
  19. const float3 g_vSmoothOneOverWidth : register( PSREG_UBERLIGHT_SMOOTH_EDGE_OOW );
  20. const float4 g_vShearRound : register( PSREG_UBERLIGHT_SHEAR_ROUND );
  21. const float4 g_aAbB : register( PSREG_UBERLIGHT_AABB );
  22. const float4x4 g_FlashlightWorldToLight : register( PSREG_UBERLIGHT_WORLD_TO_LIGHT );
  23. #endif
  24. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  25. #else
  26. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  27. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  28. #endif
  29. struct PS_INPUT
  30. {
  31. float4 spotTexCoord : TEXCOORD0;
  32. float2 baseTexCoord : TEXCOORD1;
  33. float2 irisTexCoord : TEXCOORD3;
  34. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  35. float3 vertAtten : COLOR0;
  36. #else
  37. float3 vertAtten : TEXCOORD4;
  38. float3 worldPos : TEXCOORD5;
  39. float3 projPos : TEXCOORD7;
  40. #endif
  41. };
  42. float4 main( PS_INPUT i ) : COLOR
  43. {
  44. #if defined(SHADER_MODEL_PS_2_0)
  45. float3 spotColor = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw ) * cFlashlightColor.rgb;
  46. #elif ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) )
  47. float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w;
  48. float3 spotColor = tex2D( SpotSampler, vProjCoords ).rgb * cFlashlightColor.rgb;
  49. #else
  50. float3 spotColor = tex2D( SpotSampler, i.spotTexCoord );
  51. #endif
  52. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  53. float4 irisSample = tex2D( IrisSampler, i.irisTexCoord );
  54. float3 outcolor = float3(1,1,1);
  55. #if !defined( SHADER_MODEL_PS_1_1 ) && !defined( SHADER_MODEL_PS_1_4 )
  56. if( i.spotTexCoord.w <= 0.0f )
  57. {
  58. outcolor = float3(0,0,0);
  59. }
  60. #endif
  61. // Composite the iris and sclera together
  62. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  63. float3 albedo = lerp( baseSample.xyz, irisSample.xyz, irisSample.a );
  64. #else
  65. float3 albedo = lerp( baseSample.xyz, irisSample.xyz * 0.5f, irisSample.a ); // dim down the iris in HDR
  66. #endif
  67. // Do shadow depth mapping...
  68. #if FLASHLIGHTSHADOWS && ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) )
  69. float flShadow = DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_vShadowTweaks );
  70. float flAttenuated = lerp( flShadow, 1.0f, g_vShadowTweaks.y ); // Blend between fully attenuated and not attenuated
  71. flShadow = lerp( flAttenuated, flShadow, dot(i.vertAtten, float3(0.30f, 0.59f, 0.11f) ) ); // Blend between shadow and above, according to light attenuation
  72. outcolor *= flShadow * spotColor * albedo;
  73. #if UBERLIGHT && defined( SHADER_MODEL_PS_3_0 )
  74. float4 uberLightPosition = mul( float4( i.worldPos, 1.0f ), g_FlashlightWorldToLight ).yzxw;
  75. outcolor *= uberlight( uberLightPosition, g_vSmoothEdge0, g_vSmoothEdge1,
  76. g_vSmoothOneOverWidth, g_vShearRound.xy, g_aAbB, g_vShearRound.zw );
  77. #endif
  78. #else
  79. outcolor *= spotColor * albedo;
  80. #endif
  81. // NOTE!! This has to be last to avoid loss of range.
  82. outcolor *= i.vertAtten;
  83. outcolor = max( 0, outcolor );
  84. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  85. return float4( outcolor, baseSample.a );
  86. #else
  87. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos.z, i.projPos.z );
  88. return FinalOutput( float4( outcolor, 1.0f ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  89. #endif
  90. }