POV-Ray : Newsgroups : povray.general : Speed up Boolean Server Time
27 Nov 2024 08:45:21 EST (-0500)
  Speed up Boolean (Message 1 to 8 of 8)  
From: P Brewer
Subject: Speed up Boolean
Date: 8 Feb 2009 20:20:00
Message: <web.498f84077cfd3c13916e2c9f0@news.povray.org>
Are there any tricks to speed up "complex" boolean objects?

I have a hockey puck, with several thousand small prisms cut from the side to
make a knurl texture on the side. I've manually bounded the puck, but POV still
crawls once it starts rendering that surface.

I'm hoping that by altering the way I put the initial objects together, I can
speed it up.

Here is the code I have:

#declare puck_r = .07;

#declare puck_base =
merge{
  cylinder{ <0,0,0> <0,1,0>, 1.5-puck_r }
  cylinder{ <0,puck_r,0> <0,1-puck_r,0>, 1.5 }
  torus{ 1.5-puck_r,puck_r translate puck_r*y }
  torus{ 1.5-puck_r,puck_r translate (1-puck_r)*y }
  }

#declare logo =
height_field{
  png "logo_heightfield.png"
  smooth
  translate -.5
  scale <2.6,-.02,2.6>
  translate <0,0,-.25>
  texture{ frosted_glass }
}

#declare knurl_piece =
prism{
  linear_spline conic_sweep
  1,0,5,
  <-1,-1>, <-1,1>, <1,1>, <1,-1>, <-1,-1>
  rotate 45*y
  scale <1.2,-1,1>
  translate 1*y
  rotate 90*x
  scale .015
  translate -.5*y
  }

#declare counter = 0;
#declare total = 20;
#declare knurl_row =
union{
  #while ( counter < total )
    object{
      knurl_piece
      translate counter/20*y
      }
    #declare counter = counter+1;
  #end
}

#declare knurl_row1 =
intersection{
  cylinder{ <0,-.5+puck_r,0> <0,.5-puck_r,0>, 2 }
  object{ knurl_row }
  }

#declare knurl_row2 =
intersection{
  cylinder{ <0,-.5+puck_r,0> <0,.5-puck_r,0>, 2 }
  object{ knurl_row translate .5/20*y }
  }

#if ( puck_simple = 1 )
        #declare puck =
          object{ puck_base }
#else
        #declare counter = 0;
        #declare total = 360;
        #declare puck =
        difference{
          object{ puck_base }
          union{
          #while ( counter < total )
            object{ knurl_row1 translate -1.50*z rotate counter*y }
            object{ knurl_row2 translate -1.50*z rotate (counter+1)*y }
            #declare counter = counter + 2;
          #end
          translate .5*y
          }
        }
#end

#declare puck_w_logo =
difference{
  object{ puck texture{ heavy_glass } }
  union{
    object{ logo translate 1*y texture{ frosted_glass } }
    object{ logo scale <1,-1,1> texture{ frosted_glass } }
    }
}

#declare glass_puck =
object{
  puck_w_logo
  hollow
  interior{ ior 1.5 }
  translate .01*y
  rotate -40*y
  bounded_by { cylinder { <0,0,0> <0,1.1,0> 1.55 } }
  }


Post a reply to this message

From: P Brewer
Subject: Re: Speed up Boolean
Date: 8 Feb 2009 23:35:01
Message: <web.498fb1829aa695af916e2c9f0@news.povray.org>
Okay, I was able to speed it a lot by doing some condensing in the code and
adding some intermediate manual bounding boxes. I'm guessing that I have it
about as good as I can get it.


Post a reply to this message

From: Chris B
Subject: Re: Speed up Boolean
Date: 9 Feb 2009 04:56:52
Message: <498ffde4$1@news.povray.org>
"P Brewer" <pbj### [at] wowwaycom> wrote in message 
news:web.498f84077cfd3c13916e2c9f0@news.povray.org...
> Are there any tricks to speed up "complex" boolean objects?
>
> I have a hockey puck, with several thousand small prisms cut from the side 
> to
> make a knurl texture on the side. I've manually bounded the puck, but POV 
> still
> crawls once it starts rendering that surface.
>
> I'm hoping that by altering the way I put the initial objects together, I 
> can
> speed it up.

I see you've already achieved a bit of a speed up, but in case you're still 
interested, this does look like a hole cutting problem discussed a few years 
ago.

Mike Williams put together a page describing the problem and a few 
alternative approaches to minimising the slowdown at 
http://www.econym.demon.co.uk/holetut/index.htm.

Regards,
Chris B.


Post a reply to this message

From: P Brewer
Subject: Re: Speed up Boolean
Date: 9 Feb 2009 21:00:00
Message: <web.4990df299aa695af916e2c9f0@news.povray.org>
Thanks! Just what I needed. It's funny how my making small changes to the
hierarchy behind a boolean can make such a big difference in render time...


Post a reply to this message

From: clipka
Subject: Re: Speed up Boolean
Date: 9 Feb 2009 21:30:01
Message: <web.4990e65b9aa695af4e63d9990@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> Mike Williams put together a page describing the problem and a few
> alternative approaches to minimising the slowdown at
> http://www.econym.demon.co.uk/holetut/index.htm.

The solutions are probably good, but the description of the underlying problem
is a bit misleading.

The better bounding that POV can take advantage of in the described scenario is
not applied to unions - it is applied to scene level objects. It only shows in
the described scenario because POV "unwraps" unions to scene level if possible.

For example, the following construction suffers from the very same slowdown as a
difference - simply because the merge prevents the union from being "unwrapped":

    merge {
      union {
        // place a host of cylinders here
      }
    }

The true underlying problem is a totally different one: Due to the inner design
of POV-Ray, objects aren't tested for the *first* intersection with a ray, but
rather *all* intersections. It is only afterwards that the very first of them
is determined.

Whether it is an intersection, a union or a merge, this invariably means that
*all* components have to be tested for intersections. And if the components are
all cylinders, bounding boxes wouldn't win a thing because the effort would be
about the same.

Ironically, the mechanism to test for *all* intersections is required for
objects to work properly in CSG intersections...


Post a reply to this message

From: John VanSickle
Subject: Re: Speed up Boolean
Date: 11 Feb 2009 07:30:45
Message: <4992c4f5$1@news.povray.org>
P Brewer wrote:
> Are there any tricks to speed up "complex" boolean objects?
> 
> I have a hockey puck, with several thousand small prisms cut from the side to
> make a knurl texture on the side. I've manually bounded the puck, but POV still
> crawls once it starts rendering that surface.
> 
> I'm hoping that by altering the way I put the initial objects together, I can
> speed it up.

Make it from a mesh.  This should be easy to do procedurally.  It will 
render very quickly.

Regards,
John


Post a reply to this message

From: Alain
Subject: Re: Speed up Boolean
Date: 11 Feb 2009 12:28:49
Message: <49930ad1$1@news.povray.org>
P Brewer nous illumina en ce 2009-02-08 20:16 -->
> Are there any tricks to speed up "complex" boolean objects?
> 
> I have a hockey puck, with several thousand small prisms cut from the side to
> make a knurl texture on the side. I've manually bounded the puck, but POV still
> crawls once it starts rendering that surface.
> 
> I'm hoping that by altering the way I put the initial objects together, I can
> speed it up.
>
When you remove pieces with a difference, you get all component's bounding boxes 
to overlap. Each is tested against every bounding boxes, ans each components.

Instead of removing small bits, try making the base shape a little smaller, and 
ADD in an union the small prisms to acheive the same aspect.

Even faster, try using some normals. Chances are that the difference will be 
minimal, barely visible, if you can spot a difference.

-- 
Alain
-------------------------------------------------
You know you've been raytracing too long when your idea of a complete computer 
is a fast CPU, lots of RAM, and a means of running POVray.
Aaron Gage a.k.a Slartibartfast


Post a reply to this message

From: P Brewer
Subject: Re: Speed up Boolean
Date: 13 Feb 2009 23:35:00
Message: <web.499649039aa695af916e2c9f0@news.povray.org>
>
> Make it from a mesh.  This should be easy to do procedurally.  It will
> render very quickly.
>
> Regards,
> John

Okay, I went with your plan and went to a mesh. Renders much faster now than
even my best version of the CSG, thanks.


Post a reply to this message

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