This repository has been archived by the owner on Sep 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 404
/
EdgeDetectionBackground.shader
145 lines (114 loc) · 3.96 KB
/
EdgeDetectionBackground.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//-----------------------------------------------------------------------
// <copyright file="EdgeDetectionBackground.shader" company="Google LLC">
//
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
//-----------------------------------------------------------------------
Shader "EdgeDetectionBackground"
{
Properties
{
_ImageTex ("Texture", 2D) = "white" {}
}
// For GLES3
SubShader
{
Pass
{
ZWrite Off
GLSLPROGRAM
#pragma only_renderers gles3
#ifdef SHADER_API_GLES3
#extension GL_OES_EGL_image_external_essl3 : require
#endif
uniform vec4 _UvTopLeftRight;
uniform vec4 _UvBottomLeftRight;
uniform vec4 _ImageTex_ST;
#ifdef VERTEX
varying vec2 textureCoord;
void main()
{
#ifdef SHADER_API_GLES3
vec2 transformedUV = gl_MultiTexCoord0.xy * _ImageTex_ST.xy + _ImageTex_ST.zw;
vec2 uvTop = mix(_UvTopLeftRight.xy, _UvTopLeftRight.zw, transformedUV.x);
vec2 uvBottom = mix(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, transformedUV.x);
textureCoord = mix(uvTop, uvBottom, transformedUV.y);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
#endif
}
#endif
#ifdef FRAGMENT
varying vec2 textureCoord;
uniform sampler2D _ImageTex;
void main()
{
#ifdef SHADER_API_GLES3
vec4 color = texture2D(_ImageTex, textureCoord);
gl_FragColor = vec4(color.r, color.r, color.r, 1.0);
#endif
}
#endif
ENDGLSL
}
}
// For running the computer vision sample in the Unity Editor on a desktop
// using ARCore Instant Preview.
Subshader
{
Pass
{
ZWrite Off
CGPROGRAM
#pragma exclude_renderers gles3
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _UvTopLeftRight;
uniform float4 _UvBottomLeftRight;
uniform float4 _ImageTex_ST;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
float2 transformedUV = v.uv * _ImageTex_ST.xy + _ImageTex_ST.zw;
float2 uvTop = lerp(_UvTopLeftRight.xy, _UvTopLeftRight.zw, transformedUV.x);
float2 uvBottom = lerp(_UvBottomLeftRight.xy, _UvBottomLeftRight.zw, transformedUV.x);
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = lerp(uvTop, uvBottom, transformedUV.y);
// Instant preview's texture is transformed differently.
o.uv.x = 1.0 - o.uv.x;
return o;
}
sampler2D _ImageTex;
fixed4 frag(v2f i) : SV_Target
{
fixed4 color = tex2D(_ImageTex, i.uv);
return fixed4(color.r, color.r, color.r, 1.0);
}
ENDCG
}
}
FallBack Off
}