2023-07-22 23:59:17 +08:00
|
|
|
#version 310 es
|
|
|
|
precision highp float;
|
|
|
|
precision highp int;
|
|
|
|
|
2023-07-25 19:06:12 +08:00
|
|
|
layout(location = COLOR0) in vec4 v_color;
|
|
|
|
layout(location = TEXCOORD0) in vec2 v_texCoord;
|
2023-07-22 23:59:17 +08:00
|
|
|
|
|
|
|
layout(binding = 0) uniform sampler2D u_tex0;
|
|
|
|
|
|
|
|
layout(std140, binding = 0) uniform fs_ub {
|
|
|
|
vec2 resolution;
|
|
|
|
};
|
|
|
|
|
|
|
|
float lookup(vec2 p, float dx, float dy)
|
|
|
|
{
|
|
|
|
vec2 uv = p.xy + vec2(dx , dy ) / resolution.xy;
|
|
|
|
vec4 c = texture(u_tex0, uv.xy);
|
|
|
|
return 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;
|
|
|
|
}
|
|
|
|
|
2023-07-25 19:06:12 +08:00
|
|
|
layout(location = SV_Target0) out vec4 FragColor;
|
2023-07-22 23:59:17 +08:00
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
vec2 p = v_texCoord.xy;
|
|
|
|
// simple sobel edge detection
|
|
|
|
float gx = 0.0;
|
|
|
|
gx += -1.0 * lookup(p, -1.0, -1.0);
|
|
|
|
gx += -2.0 * lookup(p, -1.0, 0.0);
|
|
|
|
gx += -1.0 * lookup(p, -1.0, 1.0);
|
|
|
|
gx += 1.0 * lookup(p, 1.0, -1.0);
|
|
|
|
gx += 2.0 * lookup(p, 1.0, 0.0);
|
|
|
|
gx += 1.0 * lookup(p, 1.0, 1.0);
|
|
|
|
|
|
|
|
float gy = 0.0;
|
|
|
|
gy += -1.0 * lookup(p, -1.0, -1.0);
|
|
|
|
gy += -2.0 * lookup(p, 0.0, -1.0);
|
|
|
|
gy += -1.0 * lookup(p, 1.0, -1.0);
|
|
|
|
gy += 1.0 * lookup(p, -1.0, 1.0);
|
|
|
|
gy += 2.0 * lookup(p, 0.0, 1.0);
|
|
|
|
gy += 1.0 * lookup(p, 1.0, 1.0);
|
|
|
|
|
|
|
|
float g = gx*gx + gy*gy;
|
|
|
|
|
|
|
|
FragColor.xyz = vec3(1.-g);
|
|
|
|
FragColor.w = 1.;
|
|
|
|
}
|