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.

73 lines
3.2 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" [ps20b] [CONSOLE]
  5. #include "common_fog_ps_fxc.h"
  6. // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b]
  7. // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30]
  8. // DYNAMIC: "UBERLIGHT" "0..1" [ps30] [PC]
  9. #include "common_flashlight_fxc.h"
  10. #include "shader_constant_register_map.h"
  11. sampler BaseTextureSampler : register( s0 );
  12. sampler SpotSampler : register( s1 );
  13. sampler FlashlightDepthSampler : register( s2 );
  14. sampler RandomRotationSampler : register( s3 );
  15. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  16. const float3 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT );
  17. const float4 g_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS );
  18. #if UBERLIGHT && defined( SHADER_MODEL_PS_3_0 )
  19. const float3 g_vSmoothEdge0 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_0 ); // ps_3_0 and up (over 32 registers)
  20. const float3 g_vSmoothEdge1 : register( PSREG_UBERLIGHT_SMOOTH_EDGE_1 );
  21. const float3 g_vSmoothOneOverWidth : register( PSREG_UBERLIGHT_SMOOTH_EDGE_OOW );
  22. const float4 g_vShearRound : register( PSREG_UBERLIGHT_SHEAR_ROUND );
  23. const float4 g_aAbB : register( PSREG_UBERLIGHT_AABB );
  24. const float4x4 g_FlashlightWorldToLight : register( PSREG_UBERLIGHT_WORLD_TO_LIGHT );
  25. #endif
  26. struct PS_INPUT
  27. {
  28. float2 baseTexCoord : TEXCOORD0; // Base texture coordinates
  29. float4 spotTexCoord : TEXCOORD1; // Spotlight texture coordinates
  30. float3 vertAtten : TEXCOORD2; // Distance/spot attenuation
  31. float4 projPos : TEXCOORD3; // Projective space position
  32. float3 worldPos : TEXCOORD4; // Necessary for pixel fog
  33. };
  34. float4_color_return_type main( PS_INPUT i ) : COLOR
  35. {
  36. #if defined( SHADER_MODEL_PS_2_0 )
  37. float3 result = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw );
  38. #else
  39. float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w;
  40. float3 result = tex2D( SpotSampler, vProjCoords ).rgb;
  41. #endif
  42. result *= cFlashlightColor.rgb;
  43. #if FLASHLIGHTSHADOWS && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) )
  44. result *= DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_ShadowTweaks );
  45. #if UBERLIGHT && defined( SHADER_MODEL_PS_3_0 )
  46. float4 uberLightPosition = mul( float4( i.worldPos, 1.0f ), g_FlashlightWorldToLight ).yzxw;
  47. result *= uberlight( uberLightPosition, g_vSmoothEdge0, g_vSmoothEdge1,
  48. g_vSmoothOneOverWidth, g_vShearRound.xy, g_aAbB, g_vShearRound.zw );
  49. #endif
  50. #endif
  51. result *= 0.35f; // Without this, unshadowed teeth always seem to glow
  52. result *= i.vertAtten; // Distance atten, NdotL and forward vector
  53. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  54. result *= baseSample.rgb; // Multiply by base map and diffuse
  55. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.xyz, i.worldPos.xyz, i.projPos.z );
  56. return FinalOutput( float4( result, baseSample.a ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  57. }