label blur / shadow

adapts the dual kawase blur shaders by @sandervanhove to use for labels. needs a bit of setup to work as a drop shadow (i.e. duplicate the label -> set as child of blurred label) but otherwise does what it says on the tin!

Shader code
// BLURRED TEXT SHADER
// adapts the dual kawase blurs for labels. can be used as a child node to create a drop shadow effect.
// use the self_modulate / modulate properties in the editor to control colours
// https://godotshaders.com/shader/dual-kawase-up-fast-blur/

shader_type canvas_item;

uniform float offset: hint_range(0.0, 10.0);
uniform int mode : hint_enum("blur down", "blur up") = 0;

varying vec4 modulate;

void vertex() {
	modulate = COLOR;
}

void fragment() {
	vec2 uv = UV;
	vec2 halfpixel = TEXTURE_PIXEL_SIZE / 2.0;
	
	vec4 sum;
	vec4 temp;
	
	if ( mode == 0 ) {
		sum = texture(TEXTURE, uv) * 4.0;
		sum += texture(TEXTURE, uv - halfpixel.xy * offset);
		sum += texture(TEXTURE, uv + halfpixel.xy * offset);
		sum += texture(TEXTURE, uv + vec2(halfpixel.x, -halfpixel.y) * offset);
		sum += texture(TEXTURE, uv - vec2(halfpixel.x, -halfpixel.y) * offset);
		temp = sum / 8.0;
	} else if ( mode == 1 ) {
		sum = texture(TEXTURE, uv + vec2(-halfpixel.x * 2.0, 0.0) * offset);
		sum += texture(TEXTURE, uv + vec2(-halfpixel.x, halfpixel.y) * offset) * 2.0;
		sum += texture(TEXTURE, uv + vec2(0.0, halfpixel.y * 2.0) * offset);
		sum += texture(TEXTURE, uv + vec2(halfpixel.x, halfpixel.y) * offset) * 2.0;
		sum += texture(TEXTURE, uv + vec2(halfpixel.x * 2.0, 0.0) * offset);
		sum += texture(TEXTURE, uv + vec2(halfpixel.x, -halfpixel.y) * offset) * 2.0;
		sum += texture(TEXTURE, uv + vec2(0.0, -halfpixel.y * 2.0) * offset);
		sum += texture(TEXTURE, uv + vec2(-halfpixel.x, -halfpixel.y) * offset) * 2.0;
		temp = sum / 12.0;
	}

	COLOR.a = temp.a * modulate.a;
}
Live Preview
Tags
blur, Label, shadow
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.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted