Cube Mesh Glow Outline

Simple glow outline shader that has adjustable width, sharpness, glow, and color

Only works with a cube mesh with the size set to (1, 1, 1) and is scaled using the shader

Also needs a custom aabb or it won’t cull properly

Demo project has everything setup properly and a collision shape that adjusts itself to the shader scale which is handy for making simple levels quickly

Shader code
shader_type spatial;

uniform vec3 scale = vec3(2.0);
uniform float width: hint_range(0.0, 10.0) = 0.25;
uniform float sharpness: hint_range(0.0, 1.0) = 0.5;
uniform float glow: hint_range(1.0, 16.0) = 4.0;
uniform vec4 color: hint_color = vec4(1.0);
uniform sampler2D tex: hint_albedo;

varying vec3 vert;
varying vec3 normal;

void vertex(){
	VERTEX += sign(VERTEX) * (scale - 1.0) * 0.5;
	
	vert = VERTEX;
	normal = abs(NORMAL);
}

void fragment(){
	vec3 fv = fract(vec3(vert.x, vert.y * -1.0, vert.z));
	vec3 vs = abs(vert) - scale * 0.5;
	float ws = width * sharpness;
	
	ALBEDO = (texture(tex, fv.zy).rgb * normal.x + texture(tex, fv.xz).rgb * normal.y + texture(tex, fv.xy).rgb * normal.z) * float(width < length(vs.xy)) * float(width < length(vs.yz)) * float(width < length(vs.xz));
	EMISSION = (1.0 - smoothstep(ws, width, length(vs.xy)) * smoothstep(ws, width, length(vs.yz)) * smoothstep(ws, width, length(vs.xz))) * color.rgb * glow;
}
Tags
Glow Outline, outline
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 Turtle

Rainbow

Particle Rope

Related shaders

2D Outline and Rainbow outline 2 in 1

Mesh Blending with Alpha

Terrain Mesh Blending with Dithering

guest

0 Comments
Inline Feedbacks
View all comments