Tunnel Speed Lines

This is a 3D Particles Shader updated for Godot 4, to draw Tunnel Speed Lines.

Tunnel dimensions are set by Tunnel Radius and Tunnel Length.

Velocity is set by Lifetime ( = Preprocess ).

Draw Pass 1 draws Quad-stripes with editable size x=3.0, y=0.4.

Draw Pass 1 Material has a Shader Param Texture Albedo, to use your own texture with alpha channel.

Shader code
// particles shader for Godot 4
shader_type particles;

uniform float tube_radius : hint_range( 0.0, 10.0 ) = 3.0;
uniform float tube_length : hint_range( 0.0, 100.0 ) = 50.0;

float rand_from_seed(inout uint seed) {
	int k;
	int s = int(seed);
	if (s == 0)
	s = 305420679;
	k = s / 127773;
	s = 16807 * (s - k * 127773) - 2836 * k;
	if (s < 0)
		s += 2147483647;
	seed = uint(s);
	return float(seed % uint(65536)) / 65535.0;
}

uint hash(uint x) {
	x = ((x >> uint(16)) ^ x) * uint(73244475);
	x = ((x >> uint(16)) ^ x) * uint(73244475);
	x = (x >> uint(16)) ^ x;
	return x;
}

void start() {
	if (RESTART_VELOCITY) {
		VELOCITY = (EMISSION_TRANSFORM * vec4( -tube_length / LIFETIME * 1.0, 0.0, 0.0, 0.0)).xyz;
	}
	if (RESTART_POSITION) {
		uint alt_seed1 = hash(NUMBER + uint(1) + RANDOM_SEED);
		// set particle position by tube_radius and tube_length
		float a = rand_from_seed( alt_seed1 ) * TAU;
		TRANSFORM = mat4(
			vec4( 1.0,0.0,0.0,0.0 ),
			vec4( 0.0,sin(a),-cos(a),0.0 ),
			vec4( 0.0,-cos(a),sin(a),0.0 ),
			vec4( tube_length, sin( a + PI ) * tube_radius, cos( a + PI ) * tube_radius, 1.0 )
		);
		TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;
	}
}
Tags
Tunnel Speed Lines
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.
Subscribe
Notify of
guest

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ninjakrom
2 years ago

This coulde be used in a sprite node or how?

Stormbringer
Stormbringer
10 months ago

Hi. Did you still have the 3.x version?

Torguen
Torguen
9 months ago
Reply to  Stormbringer

No 3.x version?

WheatleyHDD
WheatleyHDD
8 months ago

Doesn’t work in 4.1 version