Re: Mesh performance problem



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
.



Relevant Pages

  • Re: Positioning a mesh????
    ... Let's say that your mesh is a terrain that is essentially a flat surface ... to render your mesh so that the top of the hill is in the middle of your ... your world's coordinate system and the current model's coordinate system. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Z-Buffer problems rendering a Mesh
    ... Zbuffer do you add the corresponding flag in the Device.Clear call (else ... you'll clear only the render target, ... > I am creating a windows app to store and display .x files. ... > TO LOAD THE FILE INTO A MESH: ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Problems in Colorizing Surfaces of 4 Triangles & 1 Quad of A Pyram
    ... Idle time is used to render the scene. ... D3DXVECTOR3 cameraPosition; // the position of the camera ... VOID* pVertices; ... HRESULT CMyD3DApplication::OneTimeSceneInit ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Problems Decoding Video Captured By Digital Camera
    ... Problems Decoding Video Captured By Digital Camera>, ... I took screenshots as I was going along doing all of the above. ... under "Codec Installation Package for Windows Media ... Launch it and do a File | Render Media ...
    (rec.video.desktop)
  • Re: how can I get the cameras name when rendering?
    ... be connnected automatically to rendering camera' message attr. ... scene have 20 cameras to be render, and I can render all cameras in ... automatically between toonshader'attr and camera' message in my mel ... mentioning your customized plugin clears things up. ...
    (comp.graphics.apps.alias)