Archived

This topic is now archived and is closed to further replies.

TtDTtW

Drawing Patches

Recommended Posts

Heyyo. I''m a math major recently getting into graphical simulations, and came across an issue (sorry, seems a habit to have a short bio in your first post)... Anyway, I''m doing just a brute force terrain generation algo using a Perlin Noise generated texture and some basic Linear to figure the normals. Now, when I load this into a vertex buffer it seems to me that I''m doing it very inefficiently. Since I''m rendering every pixel with 6 Vertices, every pixel in my height map is being used by about 6 different triangles. So if I want to dynmically change this height I have to update the vb in about 6 seperate places. So I was reading on Terrain generation and they keep mentioning these NxN size patches and drawing those, meaning every point is represented by one vertex in a square grid type layout, which would be very easy to update. But now for the life of me I can''t find out how to draw these said "Patches". Guessing it''s an easy topic since everywhere else seems to think it''s common knowledge... Anyway, thanks in advance. -Ciao

Share this post


Link to post
Share on other sites
Perhaps I'm not understanding what you're asking, but... I'll try anyway. Sorry if it's not what you're looking for.

In OpenGL (and I assume DX has a similar mechanism), you can use something called index arrays to do your drawing. Basically, you have an array of points (a grid of points, if you prefer), which corresponds to your mesh.

You then create a separate array of indicies. Basically, this array is used to instruct the library on which verticies it should pick out of your mesh and draw. So, for example, if you had a 8x8 grid of points and you wanted to draw a triangle mesh from it, your grid would look something like the following, where each coordinate is composed of your x, y and z coordinates:

coordinate56, coordinate57, coordinate58 ... coordinate63
... ... ... ... ...
coordinate08, coordinate09, coordinate10 ... coordinate15
coordinate00, coordinate01, coordinate02 ... coordinate07

and your index array would look something like:

{ 0, 8, 1, /*first triangle*/ 1, 8, 9, /*second triangle*/ ... }

Or if your graphics library supported triangle strips, you might have an index array like:

{ 0, 8, 1, 9, 2, 10 ... 7, 15 } for each row.

This way, you only have to update each vertex in one place, and as long as you use the same index array, your mesh will draw properly. You would have to figure out what function calls are necessary in the graphics library you are using in order to use this method.

Is this even remotely like what you are asking?

[edited by - null_void on April 4, 2004 7:13:44 PM]

Share this post


Link to post
Share on other sites
Nope, but thanks.

Indexed Buffers as I can understand are used for things such as drawing the same VB at different locations.

How to explain... hmm... Guess I really can''t give a better explanation... It would be a higher order primtive since I''m defining the mesh by points and not triangles persay, and I''m leaving the graphics card to figure out where the traingles go.

I think in the Documentation there''s a NPatch or a RectPatch, but they don''t give much explanation on how it works.

Sorry, bad at getting my thoughts on paper.

Share this post


Link to post
Share on other sites
Oh well. Sorry, then. If you''re not talking about NURBS or vertex arrays then I guess I''m just not understanding you, but I''m sure that''s a failing on my part. I hope someone else can give you a hand.

Share this post


Link to post
Share on other sites
Heh, actually, NURBS were along the right track. I figured it out (well, more or less figured it wasn''t possible and I had to write it myself...) but anyway, learning a little about nurbs helped smooth it out a little. Thanks.

Share this post


Link to post
Share on other sites