Duncan Champney

10-10-2008, 05:32 AM

In my app, I have a shape that is a rectangular height map (a 3D projection of a 2D fractal image)

The user interface allows the user to zoom, pan, and rotate the shape.

I need to be able to calculate the closest and furthest Z value for my shape after it has been panned/zoomed/rotated (in other words, after applying the model view matrix.) The value I calculate doesn't have to be exact, but should be close.

I would prefer not to have to render the entire shape to calculate this value, since the shape can have millions of vertexes. (My app supports height maps of 4000x4000 vertexes, and a typical hight map has 800x800 vertexes)

I'm thinking of cutting my height map into a grid of rectangles (say 20x20 rectangles), and finding the maximum and minimum Z value for each rectangle. I would then build a grid of bounding cubes that would enclose my shape. I'd store the vertexes of these bounding cubes in an array. (preferably as a vertex buffer object stored in video memory.)

When I need to calculate my min and max Z values, I would:

-Set up my model view matrix for the current display settings

-Create a copy of my array of bounding cube vertexes (probably a VBO)

-Apply the model view matrix to my array of vertexes

-Find the largest and smallest Z value in the resulting array of vertexes.

Some questions:

-How do I create a copy of a VBO without transferring it back and forth to main memory?

-How do I multiply the vertexes in my VBO by the model view matrix and store the results back to the video memory, using the GPU, not the CPU?

-How do I find the largest and smallest values in a VBO, again using the GPU and without transferring the data back to main memory?

I'm guessing that the answer to all 3 questions is to write a shader program. However I've never tackled shader programming. This seems like it would involve a pretty steep learning curve, all to calculate 2 Z values.

Is there a simpler way?

The user interface allows the user to zoom, pan, and rotate the shape.

I need to be able to calculate the closest and furthest Z value for my shape after it has been panned/zoomed/rotated (in other words, after applying the model view matrix.) The value I calculate doesn't have to be exact, but should be close.

I would prefer not to have to render the entire shape to calculate this value, since the shape can have millions of vertexes. (My app supports height maps of 4000x4000 vertexes, and a typical hight map has 800x800 vertexes)

I'm thinking of cutting my height map into a grid of rectangles (say 20x20 rectangles), and finding the maximum and minimum Z value for each rectangle. I would then build a grid of bounding cubes that would enclose my shape. I'd store the vertexes of these bounding cubes in an array. (preferably as a vertex buffer object stored in video memory.)

When I need to calculate my min and max Z values, I would:

-Set up my model view matrix for the current display settings

-Create a copy of my array of bounding cube vertexes (probably a VBO)

-Apply the model view matrix to my array of vertexes

-Find the largest and smallest Z value in the resulting array of vertexes.

Some questions:

-How do I create a copy of a VBO without transferring it back and forth to main memory?

-How do I multiply the vertexes in my VBO by the model view matrix and store the results back to the video memory, using the GPU, not the CPU?

-How do I find the largest and smallest values in a VBO, again using the GPU and without transferring the data back to main memory?

I'm guessing that the answer to all 3 questions is to write a shader program. However I've never tackled shader programming. This seems like it would involve a pretty steep learning curve, all to calculate 2 Z values.

Is there a simpler way?