Last active
January 9, 2023 16:06
-
-
Save kototoibashi/2309748cdb3cca63d68a95c527338b0e to your computer and use it in GitHub Desktop.
depthshader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/MyTestShader" | |
{ | |
Properties | |
{ | |
} | |
SubShader | |
{ | |
// Draw ourselves after all opaque geometry | |
Tags { "Queue" = "Overlay" "DisableBatching" = "True" } | |
Cull Off | |
GrabPass { "_GrabTexture" } | |
Pass { | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
sampler2D _GrabTexture,_CameraDepthTexture; | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
}; | |
struct v2f | |
{ | |
float4 grabPos : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
bool isCam : TEXCOORD1; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.grabPos = ComputeGrabScreenPos(o.vertex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
//return tex2Dproj(_GrabTexture,i.grabPos); | |
fixed4 transparent = tex2Dproj(_GrabTexture,i.grabPos); | |
//fixed4 depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv); | |
half depth = LinearEyeDepth(tex2Dproj(_CameraDepthTexture,i.grabPos))/10; | |
fixed4 color = depth; | |
return color; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment