Re: Mesh performance problem
- From: Stephan Rose <kermos@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 15 Jan 2006 03:41:09 +0100
On 14 Jan 2006 15:45:26 -0800, "Marko Sladoljev" <masla@xxxxxx> wrote:
>
>My application generate 3D terrain with about 100 000 triangles. It
>worked pretty fast while it was rendered by:
>
> Device.DrawIndexedPrimitives(...)
>
>Because of inersect determination possibility, now I render it using
>Mesh:
>
> Mesh.DrawSubset(0);
>
>And now it worked much slower. Is there a way to increase performance
>and still using a Mesh?
>I tried with Mesh.OptimizeInPlace, but with no result.
Out of curiosity, are you drawing all 100k vertices with one single
DrawPrimitive call? Or better question, do you have all 100k vertices
in that mesh object? If so, bad idea.
Realistically speaking, you can see maybe 1,000-3,000 vertices of your
entire terrain that end up in the viewing frustrum. Maybe a lil more
if the grid is really dense...but my past terrain engine had figures
in that range. So lets pick a high number. Lets say you end up with
5,000 vertices in your cameras viewing frustum that need to be
rendered. That is 95,000 vertices that do NOT need to be rendered.
Fastest way to render a vertex is to not render it.
If you dump all 100k vertices into a draw primitive call (which
essentially is what DrawSubset is doing with some additional overhead
your initial method didnt have, hence the slowdown), this is gonna be
really slow as each of those 95k vertices has to be rejected one by
one.
My first suggestion would be, ditch the D3DX Mesh.
Second, learn how to write a quad tree (best choice over octree in my
opinion for a terrain). A quadtree allows you to reject huge amounts
of vertices very fast via very simple bounding box tests. Google on
it, many tutorials on the subject out there. I will be happy to
elaborate on it some though if needed.
And as far as your intersect goes, that too is really easy. Learn how
to do a simple triangle -> ray intersect. Again, plenty tutorials on
that to be found via google. Then, for your terrain, now all you have
to do is take your camera X, Z position, cast a ray straight down
(0,-1,0), use your quad-tree to narrow it down to a small subset of
triangles (based on camera position), test ray against those triangles
and voila...you now have the exact height of your terrain at your
current camera / object whatever location. If needed for a 1st person
camera, add the appropriate height to the Y value to bring camera to
eye level. Done.
Stephan
.
- References:
- Mesh performance problem
- From: Marko Sladoljev
- Mesh performance problem
- Prev by Date: Mesh performance problem
- Next by Date: Re: Mesh performance problem
- Previous by thread: Mesh performance problem
- Next by thread: Re: Mesh performance problem
- Index(es):
Relevant Pages
|