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.
90 lines
2.4 KiB
90 lines
2.4 KiB
Shader "Hidden/ImageScanner" |
|
{ |
|
Properties |
|
{ |
|
_MainTex ("Texture", 2D) = "white" {} |
|
_ScannerScale ("Scanner Scale", Float) = 1 |
|
_DepthScale ("Depth Scale", Float) = 1 |
|
_ScannerTex ("Texture", 2D) = "white" {} |
|
_TexX ("Tex X",Float) = 0 |
|
_TexY ("Tex Y",Float) = 0 |
|
_ScannerColor ("Scanner Color",Color) = (1,1,1,1) |
|
_ScannerStrength ("Scanner Strength",Float) = 1 |
|
} |
|
SubShader |
|
{ |
|
// No culling or depth |
|
Cull Off ZWrite Off ZTest Always |
|
|
|
Pass |
|
{ |
|
CGPROGRAM |
|
#pragma vertex vert |
|
#pragma fragment frag |
|
|
|
#include "UnityCG.cginc" |
|
|
|
sampler2D _CameraDepthTexture; |
|
sampler2D _CameraDepthNormalsTexture; |
|
sampler2D _MainTex; |
|
half _ScannerScale; |
|
float _DepthScale; |
|
sampler2D _ScannerTex; |
|
float4 _ScannerTex_ST; |
|
float _TexX; |
|
float _TexY; |
|
fixed4 _ScannerColor; |
|
float _ScannerStrength; |
|
|
|
struct appdata |
|
{ |
|
float4 vertex : POSITION; |
|
float2 uv : TEXCOORD0; |
|
}; |
|
|
|
struct v2f |
|
{ |
|
float2 uv : TEXCOORD0; |
|
float4 vertex : SV_POSITION; |
|
//float4 scrPos : TEXCOORD1; |
|
}; |
|
|
|
v2f vert (appdata v) |
|
{ |
|
v2f o; |
|
o.vertex = UnityObjectToClipPos(v.vertex); |
|
o.uv = v.uv; |
|
//o.scrPos = ComputeGrabScreenPos(o.vertex); |
|
return o; |
|
} |
|
|
|
fixed4 frag (v2f i) : SV_Target |
|
{ |
|
fixed4 col = tex2D(_MainTex, i.uv); |
|
fixed4 refrCol = tex2D(_CameraDepthTexture, i.uv); |
|
fixed3 normal = DecodeViewNormalStereo(tex2D(_CameraDepthNormalsTexture,i.uv)); |
|
fixed3 absnormal = abs(normal); |
|
//_ScannerTex_ST.xy = float2(_TexX,_TexY); |
|
i.uv = TRANSFORM_TEX(i.uv, _ScannerTex); |
|
i.uv = abs(0.5-i.uv)*float2(absnormal.r+1,absnormal.g+1); |
|
i.uv = i.uv*float2(_TexX,_TexY); |
|
//i.uv = i.uv*abs(float2(abs(normal.r*0.5+0.5)*_TexX,abs(normal.g*0.5+0.5)*_TexY)); |
|
fixed4 scannerTex = tex2D(_ScannerTex,i.uv); |
|
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv); |
|
float linearDepth = LinearEyeDepth(refrCol.r); |
|
float diff = linearDepth-_ScannerScale; |
|
float diff2 = linearDepth-_ScannerScale+_DepthScale; |
|
fixed4 border = 1-(saturate(diff*2)+saturate(-diff2*0.1)); |
|
// just invert the colors |
|
col.rgb = col.rgb+border*scannerTex*_ScannerColor*_ScannerStrength; |
|
return col; |
|
|
|
//fixed3 normal = DecodeViewNormalStereo(tex2D(_CameraDepthNormalsTexture,i.uv)); |
|
//return fixed4 (normal,1.0); |
|
//return fixed4 (absnormal,1.0)+scannerTex*_ScannerColor; |
|
|
|
} |
|
ENDCG |
|
} |
|
} |
|
}
|
|
|