Take the 2-minute tour ×

recently I'm trying to implement an algorithm to generate vine in real time. I kinda know how to do it on cpu, but I want to use GPU to accomplish this. I was thinking of geometry shader, but it looks like geometry shader executes in primitive scale, meaning it will perform the exact same functionality on every primitive, which is not what I expect.

Here is conceptually how my vine growing algorithm works. pick any point on an object mesh as the root point, the vine growing algorithm generates a series of points(representing the vine) according to previous points produced. Positions of points are influenced by such factors as gravity, adhesion and distance to triangle faces. Every point must be in the same side as the normal of triangle face.

How can I do this on GPU? Thanks a lot.

share|improve this question
"I kinda know how to do it on the CPU" To be honest, I don't think that's good enough. You should first flesh out the algorithm. If you use glm for data types like points, it's going to be very easy to convert it to GLSL. Theoretically. However, computing the distance of a point to an entire mesh is probably not going to happen in a shader. What kind of geometry do you want the vine to grow on? A wall, a pole, a tree? The complexity of that geometry is going to affect which parts of the algorithm you can put into shaders. –  Andreas Haferburg Jun 23 '13 at 9:32
any normal mesh, after some research I think gpu is not suited for my case. thank you. –  Norwizki Jun 24 '13 at 19:32
add comment

1 Answer

If you want to do something like this, that doesn't map well to the regular rendering pipeline, in glsl; your best bet is to use compute shaders (if you don't need to implement this in glsl, you may also want to take a look at OpenCL or CUDA as possible alternatives, though note that CUDA in vendor-locked to NVIDIA GPUs) in this case you can use it to generate the vine geometry using whatever method you had planned; then render the vines as normal in a second pass.

Note that this is only a good idea if your vine generation algorithm maps well to the massively parallel nature of a GPU. If your algorithm is inherently serial, then using the CPU to generate the geometry will likely yield better results.

share|improve this answer
Thank you, I now know that gpu works in parallel which is not suit for my case. –  Norwizki Jun 24 '13 at 19:35
@Norwizki I think part of what you want to do actually is well suited for the GPU. If you have a line segment representing the stem, you could use a geometry shader to generate the geometry of the stem and the leaves. Only generating the stem itself should probably happen on the CPU. –  Andreas Haferburg Jun 24 '13 at 19:42
@AndreasHaferburg but I want to simulate the "growing" animation of the vine, in which case I need to generate stem one by one. how should I control geometry shader to do that? –  Norwizki Jun 25 '13 at 20:05
@Norwizki He's saying you can generate all of the stem "skeleton", which would just be a bunch of line segments on the CPU using the serial algorithm, then send those line segments to the GPU, and blow them up into more intricate geometry in the geometry shader. –  MikeMx7f Jun 26 '13 at 18:44
add comment

Your Answer


