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.

70 lines
2.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. #include "common_ps_fxc.h"
  3. sampler AlbedoSampler : register( s0 );
  4. sampler NormalSampler : register( s1 );
  5. sampler PositionSampler : register( s2 );
  6. struct PS_INPUT
  7. {
  8. float2 texCoord : TEXCOORD0;
  9. float4 lightColor_InnerCos : TEXCOORD1;
  10. float4 lightDir_OuterCos : TEXCOORD2;
  11. float3 lightOrigin : TEXCOORD3;
  12. float4 attnInfo : TEXCOORD4;
  13. float3 SampleXYW : TEXCOORD5;
  14. float3 col : TEXCOORD6;
  15. };
  16. #define INNER_COS (i.lightColor_InnerCos.w)
  17. #define OUTER_COS (i.lightDir_OuterCos.w)
  18. #define QUADRATIC_ATTN ( i.attnInfo.x )
  19. #define LINEAR_ATTN ( i.attnInfo.y )
  20. #define CONSTANT_ATTN ( i.attnInfo.z )
  21. #define SCALE_FACTOR ( i.attnInfo.w )
  22. float Lerp5( float f1, float f2, float i1, float i2, float x )
  23. {
  24. return f1 + ( f2 - f1 ) * ( x - i1 ) / ( i2 - i1 );
  25. }
  26. float4 main( PS_INPUT i ) : COLOR
  27. {
  28. // figure out screen sample location
  29. float ooW = 1.0 / i.SampleXYW.z;
  30. float2 sampleUV = i.SampleXYW.xy * ooW;
  31. float4 normal = tex2D( NormalSampler, sampleUV );
  32. float4 albedo = tex2D( AlbedoSampler, sampleUV );
  33. float4 pos = tex2D( PositionSampler, sampleUV );
  34. float3 ldir = i.lightOrigin - pos.xyz;
  35. float dist = sqrt( dot( ldir, ldir ) );
  36. ldir = normalize( ldir );
  37. float spot_dot = dot( ldir, -i.lightDir_OuterCos.xyz );
  38. float3 ret = i.lightColor_InnerCos.xyz * 0.09 * albedo.xyz; // ambient
  39. float dist_falloff = ( SCALE_FACTOR / ( QUADRATIC_ATTN * dist * dist + LINEAR_ATTN * dist + CONSTANT_ATTN ) );
  40. if ( spot_dot > OUTER_COS )
  41. {
  42. float falloff = 1;
  43. if (spot_dot < INNER_COS)
  44. {
  45. falloff = Lerp5( 1, 0, INNER_COS, OUTER_COS, spot_dot);
  46. }
  47. float dotprod=max( 0, dot( ldir.xyz, normal.xyz ) );
  48. ret += dotprod * falloff * ( i.lightColor_InnerCos.xyz * albedo.xyz );
  49. }
  50. else
  51. dist_falloff = min( 1, dist_falloff );
  52. ret *= dist_falloff;
  53. // ret += 0.1 * i.col;
  54. return FinalOutput( float4( ret, 1 ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  55. }