POV-Ray : Newsgroups : povray.general : Slow CSG : Re: Slow CSG Server Time
7 Aug 2024 13:16:52 EDT (-0400)
  Re: Slow CSG  
From: Mike Williams
Date: 13 Sep 2001 16:28:23
Message: <Uj4+1HAGZRo7Ewlc@econym.demon.co.uk>
Wasn't it Arnold the Aardvark who wrote:
>I created a shape by using the difference between a torus
>and a union of many cylinders. This renders very slowly.
>If I render the union of cylinders as the object it is much,
>much faster. I am using bound_by.
>
>Are there any other optimisations I can use for the difference?

What happens is that when you do the union, POV can put a tight bounding
box around each cylinder, so for each ray it only has to perform
cylinder tests for the few cylinders that that particular ray comes
close to.

When you do a difference, POV can't use the bounding boxes in the same
way. For each ray it ends up performing cylinder tests for every single
cylinder. You can see the effects of this if you look at the stats in
the message window. You'll find that there are a *huge* number of
cylinder tests, of which only a very small percentage were successful.
Whereas the union has about the same number of successful tests but a
much lower number of unsuccessful ones.

I did a scene a while ago with hundreds of small cylindrical holes in a
flat slab (rather than a torus) and experimented with cutting the slab
into smaller pieces with just a few holes in each piece. It turned out
that the rendering was fastest when each piece was so small that it
contained only one hole.

The following one large slab took 62 times as long to render as 400
pieces with one hole in each.

#declare N = 20;   
// One large slab with N*N holes
#declare Slab1 = difference
 {                         
 box {<-0.5,-0.5,-0.5>,<N-0.5,N-0.5,0.5>}       
 #declare xx = 0;
 #while (xx < N)
   #declare yy = 0;
   #while (yy < N)
        cylinder {<xx,yy,-1>,<xx,yy,1>,0.3}
     #declare yy = yy+1;
   #end
   #declare xx=xx+1;
 #end
 }



// Declare a small box with one hole
#declare Box = difference
 {
 box {<-0.5,-0.5,-0.5>,<0.5,0.5,0.5>}                    
 cylinder {<0,0,-1>,<0,0,1>,0.3}
 }
// Glue together N*N boxes into one slab
// so it looks like one slab with N*N holes
#declare Slab = union {               
#declare xx=0;
#while (xx < N)
  #declare yy = 0;
  #while (yy < N)
    object {Box translate <xx,yy,0>}
    #declare yy = yy + 1;
  #end
  #declare xx=xx+1;
  #end
}


The one-large-slab version made over 70 million cylinder tests of which
0.4% were successful. The 400-small-pieces version made 27 thousand
cylinder tests of which 31% were successful. 

The resulting images are identical.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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