GLSL Parametric Curved Plotter

I am trying to implement a parametric curve builder on a fragment shader in GLSL.

I managed to make an elementary element by iterating a parameter and drawing a circle for each calculated position.

You can find the (working and commented out) code here .

Here are my questions:

  • I would like to draw this with a line. From what I understood, I see two different ways to do this:

    1. calculating the distance between each pixel and the calculated position inside the loop, accumulate the calculated value in a variable with a floating point, and then draw a curve using a step-by-step function.

      I tried to do this, and it seems that I only calculate the distance for one position t:

      #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);
      
      }
      
    2. By drawing a line segment between each consecutive parameter position

      , , , , .

  • for, ?

: , - VJing,

+4

Source: https://habr.com/ru/post/1674115/


All Articles