Deforming geometry: Should it be done in vertex shader or in draw loop?

edited May 2016 in GLSL / Shaders

Hello everyone! What I want to do is to generate some geometry and deform it. But I was not sure whether I should be doing the calculations in the vertex shader or simply doing it in the draw loop and pass the parameters to the shader. Doing it in the vertex shader might be trickier for debugging I guess.

So, what approach should I be taking? Does the draw function (loop) run the code in CPU or GPU? Is it handled by Java or OpenGL?

For instance creating a sphere I could do it in two ways: 1. Creating a grid using vertex() calls in the draw loop and then in the vertex shader use the equation of the parametric sphere surface to move these points. 2. Doing the maths in the draw loop for calculating the final position of each point and creating them by calling vertex()

Sorry if I'm confusing you. Thanks.

Answers

  • Depending on the number of vertices, you can get away with draw loop manipulation (this means CPU side). Try it, and if its too slow, you shall need to do it in the vertex shader, either using an equation, or passing the displacement info from the CPU through a texture.

Sign In or Register to comment.