Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:32:53+00:00 2026-05-28T18:32:53+00:00

So I have a sort of zigzag pattern, as shown below. , which is

  • 0

So I have a sort of zigzag pattern, as shown below.ZigZag Pattern, which is created by the following fragment shader:

uniform float time;
varying vec2 texture_coord;
void main()
{
    float wav[10] = float[10](0,.1,.2,.1,0,-.1,-.2,-.1,0,.1);
    //gl_FragColor = gl_Color;
    float mod_time = mod(time, 1);
    float x_pos = mod(texture_coord.x, 1.1);
    float x_pos2 = x_pos * 10;
    int index = int(x_pos2);
    if(texture_coord.y < .5 + wav[index])
        gl_FragColor = vec4(.7,.3,.3,1.0);
    else
        gl_FragColor = vec4(.3,.3,.3,1.0);
}

which I would like to animate by having the zigzag move upwards.

My question is, how would I do this, considering that I’m using an array to create the offset from the median? I’m not exactly sure how I would adjust the array so that in the next animation step, the array looks like (.1,.2,.1,0,-.1,-.2,-.1,0,.1)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:32:54+00:00Added an answer on May 28, 2026 at 6:32 pm

    There are 2 ways you could do it. You can either animate the offset into the array (probably the easiest) or you can animate the array itself. You’re already passing in a time parameter, so you could use that, like so:

    if (texture_coord.y < 0.5 + wav [ (index + (mod_time * 10)) % 10 ]) // Note you may have to calculate the "%" operator yourself
    ... etc. ...
    

    Or you could pass in the array. To pass in an array, you simply get the uniform location of the first element of the array, and increment it for later values. So in your source code, you could do this:

    Fragment Shader:

    uniform float wav [ 10 ];
    ... rest of fragment shader ...
    

    Source Code:

    wavLoc = glGetUniformLocation (program, "wav");
    offset++; // This starts at 0 and is incremented on each frame you want to advance the pattern
    for (int i = 0; i < 10; i++)
    {
        glUniform1f (wavLoc + i, wavePattern [ (i + offset) % 10 ]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to sort a number of integers, which can have values between 30.000.000
I have a sort of plug-in model in which various complex user controls are
I have sort of a philosophical question, which also need to consider the performance
Suppose I have this sort of HTML from which I need to select text2
I have to sort the following array objects in either ascending or descending order.
I'm teaching myself Scala and I have sort of a philosophical question. Is pattern
I have some sort of ... xml document as below : <file src=136090000-136100000> <member
I have a sort of sidebar on my website, which has to scroll down
I have a sort function which was working fine but then I tried to
I have sort of an imagemap, which is basically a lot of absolutely positioned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.