I am trying to implement a parametric curve plotter on a fragment shader in GLSL.
I managed to make a rudimentary one by iterating the parameter and drawing a circle for each computed position.
You can find the (working and commented) code here.
Here are my questions:
I would like to plot it with a line. From what I have understood, I see two different ways I could do it :
by computing the distance between each pixel and the computed position inside the loop, accumulate the computed value in a float variable, and then draw the curve using a step function.
I tried doing this and it seems like I only compute the distance for the one t position:
#define PI 3.14 void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = -1. + 2.*fragCoord.xy / iResolution.xy; uv.x *= iResolution.x/iResolution.y; vec3 color = vec3(0.); vec2 pos; float dist; for(float t=-2.; t<2.02; t+=.02){ pos.x = sin(4.*t+(iGlobalTime)); pos.y = cos(6.*t); dist += 1.-sqrt(pow((uv.x-pos.x),2.)+pow((uv.y-pos.y),2.)); color += vec3(dist); }//for fragColor = mix(vec4(0.0), vec4(1.0), dist); }
By drawing line segment between each consecutive positions of the parameter
I found this implementation that seems to do what I am trying to achieve, but i don't quite understand why they are using the previous position of the parameter.
Is there a way to do such a function without a for loop managing the parameter?
Last precision : I'm only suing a fragment shader because my goal is to upload it on a VJing software that manages fragment shaders