GLSL Vertex trail clipping at 0.0

Hello : )

I’ve started to get into GLSL and I am struggling to understand this issue and I would like to know what would be a solution to this problem. I found this example of how to make GLSL trails in the forum (GLSL vertex trail)

Basically it draws a trail that originates from a feedback TOP that is fed by a noise. The issue is that if the feedback TOP is fed empty values the trails clip at point 0.0 like shown in this gif.

Clipping issue.0

If the input of the feedback doesn’t contain any empty values the trails don’t clip at 0.0.

Clipping issue.0

In the GLSL Vertex Shader i have:

in int pointIndex;

uniform sampler2D sPointPositions;

void main()
{


	vec3 positions = texture(sPointPositions, ivec2(pointIndex,TDInstanceID()), 0).rgb;

	// is this better to be done in the vertex shader or the pixel shader?
	
	if (positions.rgb != 0.0)
	{	
		//a sort of logic that discarts the drawing of the vertex
		//if the positions contains empty values i.e. rgb(0.0, 0.0, 0.0)
	}	

	vec3 pointTranslation =  texelFetch(sPointPositions, ivec2(pointIndex,TDInstanceID()), 0).rgb;
	vec4 worldSpacePos = TDDeform(pointTranslation);
	gl_Position = TDWorldToProj(worldSpacePos);


}

My guess is that you would need to discard the values that are empty so that they are not included in the final vector and then wouldn’t be drawn. But I am not sure how or where would this be coded, is it in the vertex shader of the GLSL Mat or the Pixel Shader?

This tox is a version of the original example and I tried to simplify it as I only need the lines to be shown.
glsl_trails_alpha_clip.tox (3.3 KB)

Any help or insight would be really appreciated : )

Thanks,
Sebi

It’s worth keeping in mind that in a vertex shader you’re never creating or destroying points… just displacing them. The problem you’re running into here is that when your feedback TOP is empty, all of the points are at the origin (0,0,0) - and it isn’t until the buffer is full that you have your nice trails. One way to think about this is that when you’re resetting your buffer, you want all of the points to be at the same noisy position. You can do this with a resolution and switch TOP:

This would put all of your points at the position of the most recent, and then have them grow from that location.

Use the reset button in the network to see this at play:

grow-from-last-pos.toe (10.8 KB)

1 Like