POV-Ray : Newsgroups : povray.general : Does layout of triangles affect rendering speed in mesh(2) Server Time
4 Aug 2024 18:17:07 EDT (-0400)
  Does layout of triangles affect rendering speed in mesh(2) (Message 1 to 4 of 4)  
From: idoit
Subject: Does layout of triangles affect rendering speed in mesh(2)
Date: 18 Feb 2003 06:00:09
Message: <web.3e520f0043a9002e5a561bd30@news.povray.org>
Hi,

I'm generating rather large (40 Mb) meshes that consist of transparent and
abient triangles.

As I have limited (280 Mb) of memory in my mashine, it seems like the
computer starts to swap when the generated picture has certain properties.
Please see the "resulting" image below (best viewed in monspace) - the
charactes are actually many small trianges.


      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                                   yyyyyyyyyyyyyy
                                     yyyyyyyyyy
                                       yyyyy
                                        yyy

When rendering the X's the rendering of the picture almost halts (PovRay
gets about 10% of CPU usage at best). When the tracing of the picture
reaches the y's CPU usage is about 90% and rendering goes considerably
faster. I suspect this has to do with how the triangles are layed out
in memory.

Currently my mesh generator lays out the mesh as follows:
#declare triangles = mesh2 {
  vertex_vectors {
    468028,
    <-966, 0.644779, 0>, <-965, 0.644779, 0>, <-964, 0.654999, 0>, .......
    <-965, 0.644779, 1>, <-964, 0.649919, 1>, <-963, 0.648213, 1>, .......
    ........
    <0, 0.644779, 900>, <0, 0.644779, 900>, <0, 0.654999, 900>
    // The X-axis is varied first, then the Z-axis
    .......
   }
  face_indices {
    933156,
    <0, 1, 967>, <967, 1, 968>, <1, 2, 968>, <968, 2, 969>, <2, 3, 969>,
    .......
}


Could someone with intimate knowledge of the PovRay mesh data structures
or other relevant experiences advise me if rendering speed could be
improved by laying out the vertex vectors by iterating over the Z-axis
values first and keeping the X-axis constan as far as possible.

I.E. in pseudo code change:
for (z = 0; z < z_max; z++) for (x = 0; x < x_max; x++)  { print (<x,y,z>)}
to
for (x = 0; x < x_max; z++) for (z = 0; z < z_max; z++)  { print (<x,y,z>,)}

- or is the rendering speed affecte by how face indices are layed out
(not so simple to give an example, but i gues that the layout possibly also
should follow the principles laid out above.
Imporant to know is that the (orthographic) camera is facing parallell with
the Z-axis.

It is of course possible to try different aproaches and change the generator
of the trinagle mesh, but the algorithm is quite involved, and it would save
me a lot of work if someone could, if describe an exact method to lay out
the triangles, atleast give me a hint on what steps (if any!) could be taken
to improve rendering speed when generating meshes.

I will be glad to report my findings, or summarize any result (I will also
report if nothing, other than bying more memory, can be done) and would
allready now like to extend my thanks in advance if someone gives me advice
on how to improve rendering speed.

Also if anything is unclear - don't hesitate to ask (explaining
pictures in 3D is not that easy -  and I may have left out some
crucial information considered "obvious").


Best regards

Jan


Post a reply to this message

From:
Subject: Re: Does layout of triangles affect rendering speed in mesh(2)
Date: 21 Feb 2003 01:21:03
Message: <3e55bde1.895458351@news.povray.org>
On Tue, 18 Feb 2003 05:58:01 EST, "idoit" <ido### [at] tiscalise> wrote:
>Could someone with intimate knowledge of the PovRay mesh data structures
>or other relevant experiences advise me if rendering speed could be
>improved by laying out the vertex vectors by iterating over the Z-axis
>values first and keeping the X-axis constan as far as possible.

It's been some years since I messed with this lets see how much I
remember. POV-Ray allocates storage for each object as it's parsed, in
the order the objects are parsed. Then all objects are traversed to
build the bounding tree. Once rendering the system has to page in as
the objects are referenced, thus locality of reference has a lot to
say in avoiding paging. If the bounding tree doesn't fit in real
storage you're in for a really long trace.

>I.E. in pseudo code change:
>for (z = 0; z < z_max; z++) for (x = 0; x < x_max; x++)  { print (<x,y,z>)}
>to
>for (x = 0; x < x_max; z++) for (z = 0; z < z_max; z++)  { print (<x,y,z>,)}

Should make quite a difference, but reflections and light rays will
cause objects to be referenced 'outside' the area they occupy
on-screen. With 'well-behaved' meshes you can have memory usage up to
4-8 times real memory without much paging, once the bounding tree is
built.

/Erkki


Post a reply to this message

From: idoit
Subject: Re: Does layout of triangles affect rendering speed in mesh(2)
Date: 21 Feb 2003 17:55:07
Message: <web.3e56adbe975bf97f3ddaeab10@news.povray.org>
Thanks Erkki,

I hope to be able to finish the re-coding of my mesh generator this weekend
and i report back.

Best reagrds,

Jan

Erkki.Sondergaard wrote:
>On Tue, 18 Feb 2003 05:58:01 EST, "idoit" <ido### [at] tiscalise> wrote:
>>Could someone with intimate knowledge of the PovRay mesh data structures
>>or other relevant experiences advise me if rendering speed could be
>>improved by laying out the vertex vectors by iterating over the Z-axis
>>values first and keeping the X-axis constan as far as possible.
>
>It's been some years since I messed with this lets see how much I
>remember. POV-Ray allocates storage for each object as it's parsed, in
>the order the objects are parsed. Then all objects are traversed to
>build the bounding tree. Once rendering the system has to page in as
>the objects are referenced, thus locality of reference has a lot to
>say in avoiding paging. If the bounding tree doesn't fit in real
>storage you're in for a really long trace.
>
>>I.E. in pseudo code change:
>>for (z = 0; z < z_max; z++) for (x = 0; x < x_max; x++)  { print (<x,y,z>)}
>>to
>>for (x = 0; x < x_max; z++) for (z = 0; z < z_max; z++)  { print (<x,y,z>,)}
>
>Should make quite a difference, but reflections and light rays will
>cause objects to be referenced 'outside' the area they occupy
>on-screen. With 'well-behaved' meshes you can have memory usage up to
>4-8 times real memory without much paging, once the bounding tree is
>built.
>
>/Erkki
>


Post a reply to this message

From:
Subject: Re: Does layout of triangles affect rendering speed in mesh(2)
Date: 22 Feb 2003 10:10:04
Message: <3e5792e3.67856462@news.povray.org>
On Fri, 21 Feb 2003 17:52:46 EST, "idoit" <ido### [at] tiscalise> wrote:

>Thanks Erkki,
>
>I hope to be able to finish the re-coding of my mesh generator this weekend
>and i report back.

Hope all goes well, but you could test with a simpler mesh. I would
test myself, but with 3/4 GB RAM I rarely have paging problems when
running POV-Ray, and when I do I'm getting close to the 2 GB memory
limit.

/Erkki


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.