Skip to content

Instantly share code, notes, and snippets.

@kototoibashi
Created January 10, 2023 13:25
Show Gist options
  • Save kototoibashi/3eb7d981eb66a8aae07a5b7d028b9727 to your computer and use it in GitHub Desktop.
Save kototoibashi/3eb7d981eb66a8aae07a5b7d028b9727 to your computer and use it in GitHub Desktop.
Shader "Custom/MyTestShader"
{
Properties
{
_Shift ("Shift", Range(0.0, 5.0)) = 0
}
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;
float _Shift;
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 grabPos : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 screenPos : TEXCOORD1;
bool isCam : COLOR0;
};
v2f vert (appdata v)
{
v2f o = (v2f)0;
o.vertex = UnityObjectToClipPos(v.vertex);
o.grabPos = ComputeGrabScreenPos(o.vertex);
o.isCam = (_ScreenParams.x >= 3840 && _ScreenParams.y >= 2160);
//o.isCam = o.isCam * (abs(UNITY_MATRIX_V._12) >= 0.00000174532926);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
#if defined(USING_STEREO_MATRICES)
discard;
#endif
if(i.isCam < 1) discard;
fixed4 passthru = tex2Dproj(_GrabTexture,i.grabPos);
float2 depthtexpos = i.grabPos.xy / i.grabPos.w;
float2 viewPortPos = i.grabPos.xy / i.grabPos.w;
float2 screenPosInPixel = viewPortPos.xy * _ScreenParams.xy;
half depth = LinearEyeDepth(tex2D(_CameraDepthTexture,depthtexpos))/10;
fixed4 color = lerp(passthru,depth,(fmod(screenPosInPixel.y, 4.0f) < 1) && (fmod(screenPosInPixel.x, 4.0f) < 1));
return color;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment