Jump to content
  • Advertisement
Sign in to follow this  
Piyush Verma

OpenGL Triangle Strip and Perlin Noise.

This topic is 867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Folks,

 

I am working on an Earth Simulation in OpenGL/GLSL and I've gotten pretty far until now. I was trying to find a way to render Aurora Borealis at the North and the South poles of my planet and I found this blog where the author has done something similar to what I've been trying to do. Specifically, I'm trying to imitate the following image:

 

auroraRibbons.jpg

 

In his version of Aurora Borealis, he creates 2D bands (most probably using triangle strips) and animate them in real-time using perlin noise. I have been trying to achieve this, but the only way I can think of is to:

  • Generate the mesh once for a band.
  • Generate noise each frame for each band and update the vertices.
  • Generate Normals for each band using the updated vertices.
  • Send the new vertices & normals via an OpenGL call to the GPU. 
  • Rinse and repeat.

Now, this method seems super expensive. I was hoping if anyone can suggest a way that could make it possible to introduce the noise to the vertices inside the vertex shader itself and update the normals based on the noise that we just introduced to our vertices. 

 

I apologize that I don't have any code to show for the bands right now, since I am still brainstorming the topic and trying to come up with a most optimal solution for the problem. 

 

I could use some ideas and would really appreciate them. 

Edited by pslayer89

Share this post


Link to post
Share on other sites
Advertisement

generate perlin noise texture. lets say each frame you move the offset (the pixel you read from that texture ) by vec2(acutal_pixel + 1, 0.0);

 

since its perlin noise you should have a smooth move from one pixel to another. now imagine you have a 256 length tri strip ribbon. (and your texture is 256x256 now y dimension on texture reponds to the vertex from the start of the ribbon so vertex at center of the ribbon will read perlintex texel on vec2(time, length(ribbon_start, vertex_pos) / 256.0);

if you define your texture as being repeated you dont need to zero time if it exceeds (1 or 256) this will give you demanded shape that is changed over time. now the thing is

you do that in vertex shader (you read the texel from perlin texture) and move your vertex by perlin tex value * some factor since its from 0..1

Share this post


Link to post
Share on other sites

Instead of step 3/4 you can use geometry shader with either lines or triangles as input primitives. In latter case you can recalculate normals without sending them back to cpu/ram. In former case you may generate bands mesh on the fly. In this case aurora is represented as a concentric line_strips, in vertex shader you animate line vertices with perlin noise and then in geometry shader you generate a triangles and normals.

 

And btw take a note that bands should move along the Earth, i.e. in its polar coordinates.

Share this post


Link to post
Share on other sites

Instead of step 3/4 you can use geometry shader with either lines or triangles as input primitives. In latter case you can recalculate normals without sending them back to cpu/ram. In former case you may generate bands mesh on the fly. In this case aurora is represented as a concentric line_strips, in vertex shader you animate line vertices with perlin noise and then in geometry shader you generate a triangles and normals.

 

And btw take a note that bands should move along the Earth, i.e. in its polar coordinates.

 

I think I get it more or less. About moving the bands along the earth, do you mean that as the earth rotates, the bands should relatively rotate around the poles too? 

Share this post


Link to post
Share on other sites

Also, from what I understand, Geometry shaders store the data of a triangle, and not a mesh. Is it any way possible to calculate or manipulate vertex normals in the geometry shader for smooth shading just like show in the image in the OP? 

Share this post


Link to post
Share on other sites

 

Instead of step 3/4 you can use geometry shader with either lines or triangles as input primitives. In latter case you can recalculate normals without sending them back to cpu/ram. In former case you may generate bands mesh on the fly. In this case aurora is represented as a concentric line_strips, in vertex shader you animate line vertices with perlin noise and then in geometry shader you generate a triangles and normals.

 

And btw take a note that bands should move along the Earth, i.e. in its polar coordinates.

 

I think I get it more or less. About moving the bands along the earth, do you mean that as the earth rotates, the bands should relatively rotate around the poles too? 

 

I meant that every time you offset vertices using Earth tangent you add small error (see right half of a picture bellow). This error may not be too noticable in this case it's fine to use tangents. Otherwise you can either track distance between vertices and center of the Earth, either use polar coordinates to eliminate the errors (see left half)

http://i.imgur.com/oL026VG.png

Also, from what I understand, Geometry shaders store the data of a triangle, and not a mesh. Is it any way possible to calculate or manipulate vertex normals in the geometry shader for smooth shading just like show in the image in the OP? 

You can use adjacency primitives to calculate vertex normals.

In case of line_adjacency primitive driver feeds geometry shader with the following data:

(previous)--->(A)--->(B)--->(next)

Care should be taken with first and last vertices to avoid the gaps in bands due to how OpenGL treats vertices of adjacency primitives.

Share this post


Link to post
Share on other sites

Thanks for replying! I think I get it now about moving the bands along the earth. About the lines_adjacency primitive, I haven't used it before, so I have very little experience with it. Do I have to specify the adjacent vertices in the point list through an index buffer or by specifying GL_LINES_ADJACENCY, OpenGL itself would give me 4 coordinates per primitive? 

Edited by pslayer89

Share this post


Link to post
Share on other sites

Thanks for replying! I think I get it now about moving the bands along the earth. About the lines_adjacency primitive, I haven't used it before, so I have very little experience with it. Do I have to specify the adjacent vertices in the point list through an index buffer or by specifying GL_LINES_ADJACENCY, OpenGL itself would give me 4 coordinates per primitive? 

Sorry for the delay. You dont have to specify adjacent vertices manually (except maybe the first and the last vertices), just specify GL_LINES_ADJACENCY and OpenGL will do the rest.

Share this post


Link to post
Share on other sites

Sorry about the late reply as well. So you're saying my first and the last vertices would actually be actually some dummy value. When the first line adjacency primitive is sent to the geometry shader, it sends it as [v0, v1, v2, v3] where v0 = dummy number. Is that correct? 

 

Also, I looked a bit into perlin noise for vertices. What I couldn't figure out was, how would I animate the vertices with the perlin noise so that it looks smooth? For that, whatever noise is at v0 in the current frame, I was the same noise to be at v1 the next frame, and v1's noise goes to v2 and so on. The starting and end vertices get new noise values each frame. That way I think it would look like a smooth animation.

Edited by pslayer89

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!