POV-Ray : Newsgroups : povray.binaries.images : Problem with f_rounded_box function : Re: Problem with f_rounded_box function Server Time
17 May 2024 07:23:25 EDT (-0400)
  Re: Problem with f_rounded_box function  
From: Sebastian H 
Date: 12 Mar 2006 18:39:55
Message: <4414b14b$1@news.povray.org>
Christoph Hormann wrote:
> Sebastian H. wrote:
> 
> That's not what i meant.  You don't need the sqrt() on the faces of the 
> rounded cube - there a simple plane function is sufficient.

Hmm, needs some "if" calls but gives another speed boost of
approx. 8% in the test image.
The function now looks like this.

DBL f_rounded_box(DBL *ptr, unsigned int) // 60
{
   DBL x2, y2, z2, x3, y3, z3;

   x2 = PARAM(1) - PARAM(0);
   y2 = PARAM(2) - PARAM(0);
   z2 = PARAM(3) - PARAM(0);

   x3 = fabs(PARAM_X);
   y3 = fabs(PARAM_Y);
   z3 = fabs(PARAM_Z);

   PARAM_X = (x3 < x2) ? 0 : (x3 - x2);
   PARAM_Y = (y3 < y2) ? 0 : (y3 - y2);
   PARAM_Z = (z3 < z2) ? 0 : (z3 - z2);

   // With coitus interruptus
   if(!PARAM_X)
     {
       if(!PARAM_Y)
	{
	  return (z3 - PARAM(3));
	}
       if(!PARAM_Z)
	{
	  return (y3 - PARAM(2));
	}
     }

   if((!PARAM_Y) && (!PARAM_Z))
     {
       return (x3 - PARAM(1));
     }

   return (sqrt(PARAM_X * PARAM_X + PARAM_Y * PARAM_Y + PARAM_Z * 
PARAM_Z)  - PARAM(0));

}

Now there appear gradients above 1.0 but I could not find
any surface errors so I think a max_gradient of 1.0 is still fine.

If anyone wants to put this code or part of into the official source
feel free.

Sebastian


Post a reply to this message

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