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.

74 lines
3.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..3" [ps20b] [PC]
  3. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC]
  4. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [XBOX]
  5. // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1"
  6. // DYNAMIC: "UBERLIGHT" "0..1" [ps30] [PC]
  7. #include "common_flashlight_fxc.h"
  8. #include "shader_constant_register_map.h"
  9. const float4 g_PackedParams : register( c0 );
  10. const float4 g_NoiseScroll : register( c1 );
  11. const float4 g_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS ); // c2
  12. const float4 g_FlashlightAttenuationFactors : register( PSREG_FLASHLIGHT_ATTENUATION );
  13. const float4 g_FlashlightPos : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST );
  14. #define g_NoiseStrength g_PackedParams.x
  15. #define g_PerPlaneFactor g_PackedParams.y
  16. #if UBERLIGHT
  17. const float3 g_vSmoothEdge0 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_0 );
  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. sampler FlashlightCookieSampler : register( s0 );
  25. sampler ShadowDepthSampler : register( s1 );
  26. sampler RandRotSampler : register( s2 );
  27. sampler NoiseSampler : register( s3 );
  28. #if defined(_PS3)
  29. // Needed for optimal shadow filter code generation on PS3.
  30. #pragma texformat ShadowDepthSampler DEPTH_COMPONENT24
  31. #endif
  32. struct PS_INPUT
  33. {
  34. float3 vWorldPos : TEXCOORD0;
  35. float4 vProjPos : TEXCOORD1;
  36. float4 spotTexCoord : TEXCOORD2;
  37. float4 uberLightPos : TEXCOORD3; // not currently actually used
  38. };
  39. float4 main( PS_INPUT i ) : COLOR
  40. {
  41. float3 flashlightColor = DoFlashlight( g_FlashlightPos, i.vWorldPos, i.spotTexCoord,
  42. float3(1,0,0), g_FlashlightAttenuationFactors.xyz, g_FlashlightAttenuationFactors.w,
  43. FlashlightCookieSampler, ShadowDepthSampler, RandRotSampler,
  44. FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS, i.vProjPos.xy / i.vProjPos.w, false, g_ShadowTweaks, false );
  45. #if UBERLIGHT
  46. float4 uberLightPosition = mul( float4( i.vWorldPos, 1.0f ), g_FlashlightWorldToLight ).yzxw;
  47. flashlightColor *= uberlight( uberLightPosition, g_vSmoothEdge0, g_vSmoothEdge1,
  48. g_vSmoothOneOverWidth, g_vShearRound.xy, g_aAbB, g_vShearRound.zw );
  49. #endif
  50. // Scrolling noise with adjustable strength
  51. float fNoise = tex2D( NoiseSampler, (i.spotTexCoord.xy / i.spotTexCoord.w) + g_NoiseScroll.xy ).x;
  52. fNoise *= tex2D( NoiseSampler, (i.spotTexCoord.xy / i.spotTexCoord.w) + g_NoiseScroll.zw ).y;
  53. fNoise = lerp( 1.0, fNoise, g_NoiseStrength );
  54. // Pre-tonemapped result
  55. float4 vResult = float4( flashlightColor * 0.005f * g_PerPlaneFactor * fNoise, 1 );
  56. // Tone map on the way out (no fog and no depthwrite)
  57. return FinalOutput( vResult, 0.0f, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR, false, 0 );
  58. }