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.

92 lines
3.1 KiB

  1. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..3" [ps20b] [PC]
  2. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC]
  3. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..1" [ps20b] [CONSOLE]
  4. // DYNAMIC: "FLASHLIGHT" "0..1"
  5. // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1"
  6. // We don't care about flashlight depth unless the flashlight is on
  7. // SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps20b]
  8. // SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps30]
  9. #include "common_ps_fxc.h"
  10. #include "common_fog_ps_forcevertexfog_fxc.h"
  11. #include "common_flashlight_fxc.h"
  12. sampler BaseTimesLightmapSampler : register( s0 );
  13. sampler BaseTextureSampler : register( s1 );
  14. sampler g_tShadowDepth : register( s2 ); // Flashlight shadow depth map sampler
  15. sampler g_tNormalizeRandRot : register( s3 ); // Normalization / RandomRotation samplers
  16. sampler g_tFlashlightSampler : register( s4 ); // Flashlight cookie
  17. const float4 g_vFlashlightAttenuationFactors_FarZ : register( c0 );
  18. #define g_vFlashlightAttenuationFactors g_vFlashlightAttenuationFactors_FarZ.xyz
  19. #define g_flFlashlightFarZ g_vFlashlightAttenuationFactors_FarZ.w
  20. const float4 g_vFlashlightPos_RimBoost : register( c1 );
  21. #define g_vFlashlightPos g_vFlashlightPos_RimBoost.xyz
  22. const float4x4 g_mFlashlightWorldToTexture : register( c2 );
  23. const float4 g_vShadowTweaks : register( c6 );
  24. // THIS NEEDS TO BE THE SAME IN buildmodelforworld.cpp!!!!
  25. #define BASE_TIMES_LIGHTMAP_LINEAR_TONEMAP_SCALE 4.0f
  26. // THIS NEEDS TO BE THE SAME IN buildmodelforworld.cpp!!!!
  27. struct PS_INPUT
  28. {
  29. float4 projPos : POSITION; // Projection-space position
  30. #if ( HARDWAREFOGBLEND )
  31. float fog : FOG;
  32. #else
  33. float fog : TEXCOORD0;
  34. #endif
  35. float2 vBaseTexCoord : TEXCOORD1;
  36. #if ( FLASHLIGHT )
  37. float3 worldPos : TEXCOORD2;
  38. float3 worldNormal : TEXCOORD3;
  39. #endif
  40. };
  41. float4_color_return_type main( PS_INPUT i ) : COLOR
  42. {
  43. float3 baseTimesLightmap = tex2D( BaseTimesLightmapSampler, i.vBaseTexCoord ).xyz;
  44. #if defined( _X360 )
  45. {
  46. baseTimesLightmap = SrgbGammaToLinear( baseTimesLightmap );
  47. }
  48. #endif
  49. baseTimesLightmap *= ( 1.0f / BASE_TIMES_LIGHTMAP_LINEAR_TONEMAP_SCALE );
  50. float flVertexFogFactor = 0.0f;
  51. #if ( !HARDWAREFOGBLEND )
  52. {
  53. flVertexFogFactor = i.fog;
  54. }
  55. #endif
  56. float4 result;
  57. result.a = 1.0f;
  58. result.xyz = baseTimesLightmap;
  59. #if ( FLASHLIGHT && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) ) )
  60. {
  61. float3 baseColor = tex2D( BaseTextureSampler, i.vBaseTexCoord ).xyz;
  62. float4 flashlightSpacePosition = TransformFlashlightWorldToTexture( i.worldPos, g_mFlashlightWorldToTexture );
  63. float2 vScreenPos = i.projPos.xy / i.projPos.w;
  64. float3 flashlightDiffuseLighting =
  65. DoFlashlight( g_vFlashlightPos, i.worldPos, flashlightSpacePosition, i.worldNormal,
  66. g_vFlashlightAttenuationFactors, g_flFlashlightFarZ, g_tFlashlightSampler, g_tShadowDepth,
  67. g_tNormalizeRandRot, ( int )FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS != 0,
  68. vScreenPos, false /* bClip */, g_vShadowTweaks );
  69. result.xyz += ( flashlightDiffuseLighting * baseColor );
  70. }
  71. #endif
  72. return FinalOutput( result, flVertexFogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  73. }