UDShader.shader 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Shader "Hidden/UDSDK/UDSDKShader"
  2. {
  3. HLSLINCLUDE
  4. #include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"
  5. Texture2D _MainTex;
  6. sampler2D _CameraDepthTexture;
  7. Texture2D _udCol;
  8. Texture2D _udDep;
  9. SamplerState my_point_clamp_sampler;
  10. struct PS_OUTPUT
  11. {
  12. float4 Color0 : SV_Target;
  13. float Depth0 : SV_Depth;
  14. };
  15. PS_OUTPUT Frag(VaryingsDefault i)
  16. {
  17. PS_OUTPUT output;
  18. #if 1//UNITY_UV_STARTS_AT_TOP
  19. float2 udUV = float2(i.texcoord.x, 1 - i.texcoord.y);
  20. #else
  21. float2 udUV = float2(i.texcoord.x, i.texcoord.y);
  22. #endif
  23. float4 ud = _udCol.Sample(my_point_clamp_sampler, udUV).bgra;
  24. float4 color = _MainTex.Sample(my_point_clamp_sampler, i.texcoord);
  25. float depthCam = tex2D(_CameraDepthTexture, i.texcoord).r;
  26. float depthVDK = (_udDep.Sample(my_point_clamp_sampler, udUV).r * 0.5 + 0.5);
  27. #if UNITY_REVERSED_Z
  28. //depthCam = 1.0 - depthCam;
  29. depthVDK = 1.0 - depthVDK;
  30. if (depthVDK == 0.0 || depthCam > depthVDK /*&& 0*/)
  31. #else
  32. if (depthVDK == 1.0 || depthCam < depthVDK )
  33. #endif
  34. {
  35. output.Color0 = color;
  36. output.Depth0 = depthCam;
  37. }
  38. else
  39. {
  40. output.Color0 = ud;
  41. //#if UNITY_REVERSED_Z
  42. output.Depth0 = depthVDK;
  43. //#else
  44. //output.Depth0 = -depthVDK - 1;
  45. //#endif
  46. }
  47. return output;
  48. }
  49. ENDHLSL
  50. SubShader
  51. {
  52. Cull Off ZWrite On ZTest LEqual
  53. Pass
  54. {
  55. HLSLPROGRAM
  56. #pragma vertex VertDefault
  57. #pragma fragment Frag
  58. ENDHLSL
  59. }
  60. }
  61. }