Trail dewiggle

When using a particle trail with lots of sections, you may see an unintended wiggling artifact caused by naive interpolation. Here I use a trick to improve the interpolation by extracting the size of the TrailMesh encoded in length(VERTEX.xz). Apply the shader to the draw pass with trails enabled, and comment lines 11/18 to compare.

NOTE: Ribbon trails are only available in Godot 4, but you can adapt the trick to work in combo with my own trail technique for Godot 3

Shader code
shader_type spatial;

render_mode unshaded,blend_add,cull_disabled,particle_trails;

uniform sampler2D texture_albedo : source_color;

varying float scale_interp;
void vertex() {
	// dewiggle
	scale_interp = length(VERTEX.xz);
	UV *= scale_interp;
}

void fragment() {
	vec2 base_uv = UV;
	
	// dewiggle
	base_uv /= scale_interp;
	
	vec4 albedo_tex = texture(texture_albedo,base_uv);
	ALBEDO = COLOR.rgb * albedo_tex.rgb;
	ALPHA *= COLOR.a * albedo_tex.a;
}
Tags
trail
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from celyk

Ray-box setup

Particle based trail

Cool 3D text

Related shaders

Bloody Pool! – Smooth blood trail

Particle based trail

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments