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.

62 lines
1.5 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. sampler g_sDepth : register( s0 );
  3. float4x4 g_mInvVP : register( c0 );
  4. float2 g_vInvScreenSize : register( c4 );
  5. struct PS_INPUT
  6. {
  7. #ifdef _X360
  8. float2 vPos : VPOS;
  9. #else
  10. float2 uv : TEXCOORD0;
  11. #endif
  12. };
  13. struct PSOutput
  14. {
  15. float4 vColor : COLOR0;
  16. float fDepth : DEPTH;
  17. };
  18. PSOutput main( PS_INPUT i)
  19. {
  20. #ifdef _X360
  21. float2 vUV = 4.0 * i.vPos + 0.5;
  22. vUV *= g_vInvScreenSize;
  23. #else
  24. float2 vUV = i.uv;
  25. #endif
  26. float4 vDepths;
  27. vDepths.x = tex2D( g_sDepth, vUV );
  28. vDepths.y = tex2D( g_sDepth, vUV + float2(g_vInvScreenSize.x, 0.0) );
  29. vDepths.z = tex2D( g_sDepth, vUV + float2(0.0, g_vInvScreenSize.y) );
  30. vDepths.w = tex2D( g_sDepth, vUV + g_vInvScreenSize );
  31. // convert sample to world-space
  32. float4 vClipPos;
  33. vClipPos.xy = 2.0 * vUV.xy - 1.0;
  34. vClipPos.y = -vClipPos.y;
  35. vClipPos.z = 1.0 - vDepths.x;
  36. vClipPos.w = 1.0;
  37. float4 vWorldPos = mul( vClipPos, g_mInvVP );
  38. vWorldPos /= vWorldPos.w;
  39. // Derive normal from depth buffer. Ideally I'd compute a world space pos from vDepths.x, y, and z and then cross the deltas of that,
  40. // but that's a lot of work.
  41. float3 vNormal = cross( ddx(vWorldPos.xyz), ddy(vWorldPos.xyz) );
  42. PSOutput o;
  43. // TODO: output normal
  44. o.vColor = 1.0;//-vPos.x/320.0;//float4( 0.5 * vNormal + 0.5, 0.0 );
  45. // get max depth
  46. vDepths.xy = min( vDepths.xy, vDepths.zw );
  47. o.fDepth = min( vDepths.x, vDepths.y );
  48. //o.fDepth = dot( vDepths, float4( 0.25, 0.25, 0.25, 0.25 ) );
  49. return o;
  50. }