Team Fortress 2 Source Code as on 22/4/2020
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.

69 lines
1.9 KiB

  1. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  2. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  3. #define HDRTYPE HDR_TYPE_NONE
  4. #define HDRENABLED 0
  5. #include "common_ps_fxc.h"
  6. sampler AlbedoSampler : register( s0 );
  7. sampler NormalSampler : register( s1 );
  8. sampler PositionSampler : register( s2 );
  9. sampler AccBuf_In : register( s3 );
  10. float4 EyePosition : register (c10);
  11. float4 Light_origin : register( c0 );
  12. #define INNER_COS (Light_origin.w)
  13. #define OUTER_COS (Light_dir.w)
  14. float4 Light_dir : register( c1 );
  15. float4 Light_attn : register (c2);
  16. #define QUADRATIC_ATTN (Light_attn.x)
  17. #define LINEAR_ATTN (Light_attn.y)
  18. #define CONSTANT_ATTN (Light_attn.z)
  19. #define SCALE_FACTOR (Light_attn.w)
  20. float3 Light_color: register(c3);
  21. struct PS_INPUT
  22. {
  23. float2 texCoord : TEXCOORD0;
  24. };
  25. float Lerp5(float f1, float f2, float i1, float i2, float x)
  26. {
  27. return f1+(f2-f1)*(x-i1)/(i2-i1);
  28. }
  29. float4 main( PS_INPUT i ) : COLOR
  30. {
  31. float4 normal=tex2D( NormalSampler, i.texCoord );
  32. float4 albedo=tex2D( AlbedoSampler, i.texCoord );
  33. float4 pos=tex2D( PositionSampler, i.texCoord );
  34. float3 old_acc=tex2D( AccBuf_In, i.texCoord );
  35. // pos.xyz+=EyePosition.xyz;
  36. float3 ldir=Light_origin.xyz-pos.xyz;
  37. float dist=sqrt(dot(ldir,ldir));
  38. ldir=normalize(ldir);
  39. float spot_dot=dot(ldir,-Light_dir);
  40. float3 ret=Light_color*0.09*albedo.xyz; // ambient
  41. float dist_falloff=(SCALE_FACTOR/(QUADRATIC_ATTN*dist*dist+LINEAR_ATTN*dist+CONSTANT_ATTN));
  42. if (spot_dot>OUTER_COS)
  43. {
  44. float falloff=1;
  45. if (spot_dot<INNER_COS)
  46. {
  47. falloff=Lerp5(1,0,INNER_COS,OUTER_COS,spot_dot);
  48. }
  49. float dotprod=max(0,dot(ldir.xyz,normal.xyz));
  50. ret+=dotprod*falloff*(Light_color*albedo.xyz);
  51. }
  52. else
  53. dist_falloff=min(1,dist_falloff);
  54. ret*=dist_falloff;
  55. // ret=float3(1,0,0);
  56. return FinalOutput( float4(ret+old_acc,1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  57. }