Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Trouble plotting a particular equation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Intern Contributor
    Join Date
    Sep 2016
    Posts
    75

    Trouble plotting a particular equation

    I'm trying to plot the following equation : y = random( floor(uv.x) ):


    figure 1

    I've tried other equations and they work just fine:






    The problem starts when I try equations with steep angles like y = random(floor(uv.x)), they get their horizontal lines cut off



    The color gets cut off at a certain angle.



    I'm not sure what I'm doing wrong, but this is what I've tried so far:

    Code :
    out vec4 color;
     
    float Random(in float x) {
        return fract(sin(x) * 1e4);
    }
     
    void main () {
     
        vec2 uv     = gl_FragCoord.xy/ screen.xy;
        vec2 ndc    = vec2(uv.x * 2.0 - 1.0, uv.y * 2.0 - 1.0);
        uv.x        *= screen.x / screen.y;
     
        uv -= 0.5;  // -0.5 <-> 0.5
        uv *= 5.0;  // Zoom Out, if not we don't see much
     
        vec4 final = vec4(0.0);
        final.a = 1.0;
     
        float i = floor(uv.x); // Integer Coords
        float f = fract(uv.x); // Fractional Coords
     
        // Calculate Graph
     
        // This Works
        // float u = f * f * (3.0 - 2.0 * f );
        // float x = mix(Random(i), Random(i + 1.0), u);
     
        float x = Random(i); // No horizontal Lines :(
        float y = uv.y;
     
        // Plot
        float blur = 0.01;
        final.r = smoothstep(x - blur, x, y); // bottom
        final.r -= smoothstep(x - blur, x, y - blur);
     
        color = final;  
     
    }

    I'm clearly not understanding something :/ I re-edited the entire question with new and shorter code. As always, thanks!
    Last edited by hashbrown; 11-09-2017 at 11:14 AM. Reason: Updated Question, closer to the solution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •