POV-Ray : Newsgroups : povray.beta-test : Function weirdness : Re: Function weirdness Server Time
31 Jul 2024 00:35:07 EDT (-0400)
  Re: Function weirdness  
From: Mike Williams
Date: 19 Sep 2001 02:43:43
Message: <$hFUlAA7zDq7EwRs@econym.demon.co.uk>
Wasn't it Slime who wrote:
>Yeah, it makes sense now... I wish there were some way to force the function
>to store a value just so that the same value doesn't have to be calculated
>multiple times. That could speed up rendering, probably. I ended up doing
>this for my function:
>
>    function { sqrt((x/scalex)^2+(y/scaley)^2+(z/scalez)^2)/baseradius +
>     f_noise3d(x/sqrt((x/scalenx)^2+(y/scaleny)^2+(z/scalenz)^2)*noisedetail
>+ rndx,
>         y/sqrt((x/scalenx)^2+(y/scaleny)^2+(z/scalenz)^2)*noisedetail +
>rndy,
>         z/sqrt((x/scalenx)^2+(y/scaleny)^2+(z/scalenz)^2)*noisedetail +
>rndz
>     )*noiseamnt-1
>    }

You can certainly write it more clearly as 

#declare F = function{sqrt((x/scalenx)^2+(y/scaleny)^2+(z/scalenz)^2)}
#declare G = function{sqrt((x/scalex)^2 +(y/scaley)^2 +(z/scalez)^2)}

function { G(x,y,z)/baseradius 
   + f_noise3d(x/F(x,y,z)*noisedetail + rndx,         
               y/F(x,y,z)*noisedetail + rndy,
               z/F(x,y,z)*noisedetail + rndz
   )*noiseamnt-1
}

This way it's easier to read, takes just about the same amount of time,
produces exactly the same output, and crashes in exactly the same place
when you try to divide by zero at the origin.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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