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.
71 lines
1.5 KiB
71 lines
1.5 KiB
Shader "Hidden/ExampleScannerImage" |
|
{ |
|
Properties |
|
{ |
|
_MainTex ("Texture", 2D) = "white" {} |
|
_MaskTex("Mask Texture", 2D) = "white" {} |
|
_MaskTexTillY("Till Y",Float) = 1.0 |
|
_DepthParam ("DepthParam",Float) = 1.0 |
|
_DepthColor("DepthColor",Color) = (1,1,1,1) |
|
_DepthLength ("DepthLength",Float) = 1.0 |
|
} |
|
SubShader |
|
{ |
|
// No culling or depth |
|
Cull Off ZWrite Off ZTest Always |
|
|
|
Pass |
|
{ |
|
CGPROGRAM |
|
#pragma vertex vert |
|
#pragma fragment frag |
|
#include "UnityCG.cginc" |
|
|
|
sampler2D _MainTex; |
|
sampler2D _CameraDepthTexture; |
|
sampler2D _MaskTex; |
|
float4 _MaskTex_ST; |
|
float _MaskTexTillY; |
|
float _DepthParam; |
|
fixed4 _DepthColor; |
|
float _DepthLength; |
|
|
|
struct appdata |
|
{ |
|
float4 vertex : POSITION; |
|
float2 uv : TEXCOORD0; |
|
}; |
|
|
|
struct v2f |
|
{ |
|
float2 uv : TEXCOORD0; |
|
float4 vertex : SV_POSITION; |
|
}; |
|
|
|
v2f vert (appdata v) |
|
{ |
|
v2f o; |
|
o.vertex = UnityObjectToClipPos(v.vertex); |
|
o.uv = v.uv; |
|
return o; |
|
} |
|
|
|
fixed4 frag (v2f i) : SV_Target |
|
{ |
|
fixed4 mainTex = tex2D(_MainTex, i.uv); |
|
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv); |
|
float linearDepth = LinearEyeDepth(depth.r); |
|
float diff = linearDepth-_DepthParam; |
|
fixed4 border = 1-(saturate(floor(diff))+saturate(-diff*_DepthLength)); |
|
|
|
_MaskTex_ST.y = _MaskTexTillY; |
|
i.uv = TRANSFORM_TEX(i.uv, _MaskTex); |
|
fixed4 maskTex = tex2D(_MaskTex,i.uv); |
|
|
|
fixed4 final = lerp(mainTex,saturate(border*_DepthColor+mainTex*_DepthColor.a+maskTex*_DepthColor),saturate(border)); |
|
return final; |
|
} |
|
ENDCG |
|
} |
|
} |
|
}
|
|
|