How do you efficently change a vertex's location?

Started by
2 comments, last by ET3D 16 years, 6 months ago
About 3 years ago, I was messing around with directx 9 and I decided to impelement a program I had done many decades earlier, something that took hours to do which could easily be done in real time now. Basically this program renders 'surface' like water that has waves and ripples going through it. Anyhow, this program recomputed a grid of vertexes every frame and this grid was like 100x100 or even 400x400. Recently I leanred that modifying the vertex buff directly is bad, and you should use a matrix transform instead. However, I only know how to apply a matrix transform against a polygon, not a vertex. Imagine a triangle and I just want adjust the Y value of each vertex, how can I do that without running through the vertex buffer and accesing each Y component individually? Is there some faster way apply a bumpmap of sorts, or a heightmap of sorts that is dynamically changing then just editing each vertex's Y coordinate?
Advertisement
Use a vertex shader. There are plenty of examples of "wave" effects with them, even a couple in the SDK.
If you're working with a newer video card that supports reading textures in the vertex shader, you could read from a height map and perform displacement mapping. There was a feature on the technique used for doing this in the game Pacific Fighters over on Gamasutra. Of course you don't need to use a texture, and you could modify the position in the vertex shader in a number ways (like arrays of shader constants).

Otherwise you can modify the vertices directly in vertex buffer via locking, you just have to be careful of how you do it. If you lock a buffer that the GPU is dependent upon for rendering, you will cause a stall and your performance will suffer. However if you double-buffer things, you may be able to avoid a stall.
On ATI cards you can also use the R2VB option (render to vertex buffer). Check the ATI SDK for examples.

This topic is closed to new replies.

Advertisement