POV-Ray : Newsgroups : povray.general : CSG woes Server Time
6 Aug 2024 12:23:50 EDT (-0400)
  CSG woes (Message 1 to 5 of 5)  
From: Tom York
Subject: CSG woes
Date: 6 Apr 2002 07:29:46
Message: <3caeea3a@news.povray.org>
I have a complicated object (a union) in an include file, and 
want to remove lots of small pieces from it. So far, so good. 
I also want to have it render quickly, and I want to do all 
this without altering the code in the include file. In outline, 
I'm using:


POV scene file:

#include "HN_frigate.inc"


difference {
   object { HN_frigate }
      
   // lots of small boxes/cylinders/spheres

   box {...}
   cylinder {...}
   .
   .
   .

   bounded_by {...}
  }


HN_frigate.inc:

#declare HN_frigate = union {
	// many objects

	box {...}
	sphere {...}
	.
	.
	.
	}

I don't want to alter HN_frigate.inc every time I wish 
to difference things from the union in that file. I've 
tried making the small objects into a union, and 
subtracting that from object { HN_frigate } but it's 
no faster. What else could I do to speed this all up, 
without altering the include file? Any illumination 
gratefully received...

Tom


Post a reply to this message

From: Warp
Subject: Re: CSG woes
Date: 6 Apr 2002 07:49:26
Message: <3caeeed5@news.povray.org>
Tom York <tom### [at] compsocmanacuk> wrote:
> I have a complicated object (a union) in an include file, and 
> want to remove lots of small pieces from it. So far, so good. 
> I also want to have it render quickly

  Sorry, not possible. Well, at least not with 'difference'.

  You either suffer from the slow rendering, or you modify the original
object in some other way than a difference CSG.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Tom A 
Subject: Re: CSG woes
Date: 6 Apr 2002 09:53:45
Message: <3CAF0BFA.49A826CE@my-deja.com>
Warp wrote:
> 
> Tom York <tom### [at] compsocmanacuk> wrote:
> > I have a complicated object (a union) in an include file, and
> > want to remove lots of small pieces from it. So far, so good.
> > I also want to have it render quickly
> 
>   Sorry, not possible. Well, at least not with 'difference'.
> 
>   You either suffer from the slow rendering, or you modify the original
> object in some other way than a difference CSG.
> 
> --
>  - Warp -

General question - is difference an expensive operation?  I'm very
comfortable with difference, but there are often other ways to create
things - should I avoid it for performance reasons (if performance is
important)?


-- 
Tom A.

into that pit of cotton-top hell, and let them hippity-hop
all over my vulnerable flesh? - Buffy the Vampire Slayer
Deja mail is gone.  Look for me at raugost at yahoo . com


Post a reply to this message

From: Warp
Subject: Re: CSG woes
Date: 6 Apr 2002 10:00:23
Message: <3caf0d87@news.povray.org>
Tom A. <tar### [at] my-dejacom> wrote:
> General question - is difference an expensive operation?

  It depends. Difference between some objects is usually efficient. The
worst case is, I think, when you have a really complex object (which takes
some time to render) and you cut many small parts out of it by differencing
it with lots of objects. AFAIK this is a sitation where the difference CSG
routine cannot perform too well.

  See also:
http://www.students.tut.fi/~warp/povQandT/miscQandT.html#csgspeed

>  I'm very
> comfortable with difference, but there are often other ways to create
> things - should I avoid it for performance reasons (if performance is
> important)?

  If you are getting really slow render times, then you can think about
alternative ways.
  If the rendering times are ok, then why bother? :)

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Mike Williams
Subject: Re: CSG woes
Date: 6 Apr 2002 11:32:55
Message: <GwbKBDAFKyr8EwzO@econym.demon.co.uk>
Wasn't it Tom A. who wrote:


>General question - is difference an expensive operation?

Differencing a large number of small objects from one large object is
notoriously slow. What happens is that the automatic bounding ends up
being rather unhelpful.

Normally if you've got lots of small objects, POV performs some quick
bound tests for each ray and then only bothers to test those objects for
which the ray hits the bounds. So only a few objects are tested for each
ray.

However, in your case, there's probably only one bounding box, and it's
the size of the large object. POV then ends up testing every object for
every ray.

You can observe the effect by rendering at small size and looking at the
statistics for the numbers of bounds tests and tests for whatever
primitive your difference object is.

You may find that it's possible to slice your large object up into
smaller chunks (e.g. by intersecting several copies of it with a set of
boxes) applying the difference to those chunks and then unioning the
whole thing back together again.

Below is my usual example file of a slab with lots of cylindrical holes
in it. If you set N=20 M=1 then you get one box with 400 cylindrical
holes. render it at 320*240 and the stats say 33611600 cylinder tests.
That's an average of over 437 cylinder tests per ray. If you set N=1
M=20 then you the slab is split into 400 pieces each containing one
hole. Render that and the stats say 16861 cylinder tests. That's 0.2
cylinder tests per ray, and it renders about 107 times faster.

(If your scene contains only the difference object, then you may find
that bounding gets switched off altogether, because POV doesn't think
it's generally worthwhile to bound less than three objects. Forcing
bounding to occur can give a bit of speed improvement in such cases.)




#declare N = 1;   // Each box has N*N holes
#declare M = 20;  // There are M*M boxes

camera {   location  <M*N/2, M*N/2, -50.0>  look_at   <M*N/2, M*N/2, 0>}

sky_sphere { pigment { gradient y color_map { [0.0 color rgb <0,.3,.8>]
[1.0 color rgb 1] }}}

light_source { <-20,50,-20> colour rgb 1}
  
             
// Build a box with N*N cylindrical holes             
#declare Holes = 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
 }
               
// Glue together M*M boxes into one slab               
#declare Slab = union {               
#declare xx=0;
#while (xx < M)
  #declare yy = 0;
  #while (yy < M)
    object {Holes translate <xx*N,yy*N,0>}
    #declare yy = yy + 1;
  #end
  #declare xx=xx+1;
  #end
  pigment {rgb 0.5}
}
  

object {Slab}


Post a reply to this message

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