0

I have a flat surface drawn with a single fullscreen GL_QUAD.

I want to deform this surface at each point specified by my GL_Texture2D, preferably through some kind of shader.

In my mind, black could correspond to flat and white could correspond to a hill.

I want to have about 4 million points on my terrain and update them at each step in my program.

How would I use a geometry shader to do this? Is a shader able to generate new veritices?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mikhail
  • 7,749
  • 11
  • 62
  • 136
  • 4
    Can you restructure your question so that it's not answerable with a simple "yes" or "no"? – Robert Harvey Aug 13 '13 at 19:36
  • I don't see how this is related to any programming language other than GLSL; remove the c++ tag. – DanielKO Aug 13 '13 at 20:56
  • 2
    Are you using OpenGL 4.0 or higher? If you are, then it sounds like you should be using tessellation shaders (not a geometry shader) to do what you want. – GuyRT Aug 14 '13 at 10:53
  • 1
    I don't see why you would need a geometry shader. Just use a vertex shader as @jozxyqk suggested. If you really want to modify the vertex coordinates at each step, i.e. save the calculations done in the vertex shader, have a look at transform feedback. – Gigo Aug 16 '13 at 02:47

1 Answers1

2

The simplest way would be to generate a large triangle strip grid, upload it to a VBO and draw it, using the vertex shader to alter just the up coordinate. The vertex shader can also generate normals from the heightmap (or supply a normal map), which then get passed to the fragment shader for lighting.

To avoid storing a huge amount of data for the vertices, use glVertexID to generate the vertex positions from scratch in the vertex shader. Don't bind any buffers, simply call glDrawArrays(GL_TRIANGLE_STRIP, 0, lots).

As GuyRT mentioned, a tessellation shader would be good too and allow you to vary the tessellation detail based on the camera's distance to the mesh. This would be more work though.

jozxyqk
  • 16,424
  • 12
  • 91
  • 180