Laplace filter, edge detection

https://www.shadertoy.com/view/MdlBz2

Shader code
shader_type canvas_item;

uniform sampler2D iChannel0;
uniform float threshold : hint_range(0.0, 10., 0.1) = 1.0;
uniform bool invert_color = false;
uniform bool remove_b_color = false;

const int conv_length = 9,
           conv_width = 3;

// Laplace filter kernel
const float conv[conv_length] = float[conv_length](
    -1.,-1.,-1.,
    -1., 8.,-1.,
    -1.,-1.,-1.
);

void fragment()
{
	vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE;
	vec2 uv = UV,
          ps = 1. / iResolution.xy; // pixel size

    vec4 acc = vec4(0);
    for (int i = 0; i < conv_length; i++){
        vec2 d = vec2(float(i % conv_width - conv_width / 2), float(i / conv_width - conv_width / 2));
    	acc += conv[i] * texture(iChannel0, uv + d * ps * threshold);
    }
    
	COLOR.rgb = acc.rgb;
	if (invert_color == true){
		COLOR.rgb = 1.0 - acc.rgb;
	}
	if (remove_b_color == true){
		COLOR.a = acc.r;
	}
}
This shader is a port from an existing Shadertoy project. Shadertoy shaders are by default protected under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) license unless anything else has been stated by the author. For more info, see our License terms.

More from RayL019

alien orb ball

Kinetic Pupils

voronoi 细胞边界距离

Related shaders

Edge Detection (Sobel Filter and Gaussian Blur)

Cheaper* Edge Detection Post-Processing

Distort Filter PerlinNoise

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments