Basic Gaussian Blur

The shader samples the x and y by the amount of blur set.

Shader code
shader_type spatial;

uniform sampler2D uTexture;

vec4 gaussianBlur(sampler2D source, vec2 uv, int samples, float amount) {
	vec4 color = texture(source, uv);
	amount *= .015;
	
	for (int i = 1; i < samples; i++) {
		float offset_x = sin(float(i) * 3.14 / amount) * amount - amount;
		float offset_y = cos(float(i) * 3.14 / amount) * amount + amount;

		color += texture(source, uv + vec2(offset_x, offset_y));
	}

	color = color / float(samples);

	return color;
}

void fragment() {
	ALBEDO = gaussianBlur(uTexture, UV, 12, 1).rgb;
}
Tags
blur
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from mikemike

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments