summaryrefslogtreecommitdiffstats
path: root/DepthBlit.shader
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-01-13 20:42:27 -0800
committeryum <yum.food.vr@gmail.com>2026-01-13 22:27:33 -0800
commitad551018904f13b8af0d1c4c2aa8380ac57de89a (patch)
tree9915d06a03988cacd3c13131edc32946d7c9876d /DepthBlit.shader
parent6df5a9a34d81d1200231b974fcc85f89e80eb63e (diff)
Impostors: fix depth capture
Diffstat (limited to 'DepthBlit.shader')
-rw-r--r--DepthBlit.shader52
1 files changed, 52 insertions, 0 deletions
diff --git a/DepthBlit.shader b/DepthBlit.shader
new file mode 100644
index 0000000..04187c2
--- /dev/null
+++ b/DepthBlit.shader
@@ -0,0 +1,52 @@
+Shader "Hidden/yum_food/DepthBlit"
+{
+ // Reads from depth texture and outputs linearized depth to color
+ Properties
+ {
+ _MainTex ("", 2D) = "white" {}
+ }
+
+ SubShader
+ {
+ Cull Off ZWrite Off ZTest Always
+
+ Pass
+ {
+ CGPROGRAM
+ #pragma vertex vert
+ #pragma fragment frag
+
+ #include "UnityCG.cginc"
+
+ sampler2D _DepthTex;
+
+ struct v2f
+ {
+ float4 pos : SV_POSITION;
+ float2 uv : TEXCOORD0;
+ };
+
+ v2f vert(float4 vertex : POSITION, float2 uv : TEXCOORD0)
+ {
+ v2f o;
+ o.pos = UnityObjectToClipPos(vertex);
+ o.uv = uv;
+ return o;
+ }
+
+ float4 frag(v2f i) : SV_Target
+ {
+ float rawDepth = tex2D(_DepthTex, i.uv).r;
+
+ // Orthographic depth is already linear.
+ // We just need to handle the platform-specific Z-buffer direction.
+ #if defined(UNITY_REVERSED_Z)
+ return 1.0 - rawDepth;
+ #else
+ return rawDepth;
+ #endif
+ }
+ ENDCG
+ }
+ }
+}