POV-Ray : Newsgroups : povray.text.scene-files : My favourite isosurface (see p.b.i. for image) : Re: My favourite isosurface (see p.b.i. for image) Server Time
28 Apr 2024 07:52:04 EDT (-0400)
  Re: My favourite isosurface (see p.b.i. for image)  
From: Tor Olav Kristensen
Date: 21 Nov 2003 14:57:40
Message: <3fbe6e34@news.povray.org>
"Alex Kluchikov" <klk### [at] ukrnet> wrote in
news:web.3fbc5805d6b87b52d68d943d0@news.povray.org: 
...
>  Thank you. I'll try to write more quick code. But what is the
>  difference 
> between my and your variants? Why the render time differs so much?
>  May be, standard functions (declared in functions.inc) are faster?
> 
>  I tried to create functions with as little gradient value as
>  possible. For 
> example, let's take sphere:
> 
>  function{x*x+y*y+z*z-1} has max gradient about 2
>  function{pow(x*x+y*y+z*z,1/256)-1} has max gradient about .05 or even
>  less, 
> while looking the same.
> 
> And sometimes it helps to speed up rendering. But I can not
> understand, why the code you've post is so much more faster? It seems
> to me, I need some time to think...


Alex,

What slows down evaluation of a user defined function is how
many operators and function calls it contains.

When the parser has expanded your macros, your function will
look somewhat like I have shown below.

This function now contains calls to 103 internal operators/
functions; +, -, *, /, cos(), sin(), pow(), sqrt() and 13 calls
to a user defined function; radialf().

The function is now compiled into code that POV-Ray uses
while redering your isosurface.

The function(s) I wrote has 35 calls to internal operators/
functions; +, -, *, /, cos(), sin(), atan2(), internal() and
7 calls to user defined functions; f_r(), f_sphere(),
TempFn0(), TempFn1(), TempFn2().

(You can find references to the internal() functions in
"functions.inc")


POV-Ray lacks the possility to use local variables within
user defined functions.

I have found a way to get aroud this limitation:
By using nested function calls to pass (by parameters) "pre-
calculated" values to other user defined functions, so that
they don't have to repeat the calculations.

If you look into the source code for the images at the
povray page on my web-site, you can find more examples on how
to apply this technique. Its' here:

http://home.no/t-o-k/povray

Another thing that increased the rendering speed was to
"crimp" the bounding box of your isosurface.


I hope this helped you a little.


Tor Olav

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// You function as it looks when expanded "by hand".

    function {
      pow(
        pow(
          (sqrt(x*x + z*z) - 1.5)*sin(radialf(x, y, z)*MPI)
         +                      y*cos(radialf(x, y, z)*MPI)
         +0.25,
          2
        )
       +pow(
          (sqrt(x*x + z*z) - 1.5)*cos(radialf(x, y, z)*MPI)
         -                      y*sin(radialf(x, y, z)*MPI),
          2
        ),
        1/64
      )*0.33
     +pow(
        pow(
          (sqrt(x*x + z*z) - 1.5)*sin(radialf(x, y, z)*MPI)
         +                      y*cos(radialf(x, y, z)*MPI)
         -0.125,
         2
        )
       +pow(
          (sqrt(x*x + z*z) - 1.5)*cos(radialf(x, y, z)*MPI)
         -                      y*sin(radialf(x, y, z)*MPI)
         +0.21650635094610966169093079268823,
          2
        ),
        1/64
      )*0.33
      
      +pow(
        pow(
          (sqrt(x*x + z*z) - 1.5)*sin(radialf(x, y, z)*MPI)
         +                      y*cos(radialf(x, y, z)*MPI)
         -0.125,
          2
        )
       +pow(
          (sqrt(x*x + z*z) - 1.5)*cos(radialf(x, y, z)*MPI)
         -                      y*sin(radialf(x, y, z)*MPI)
         -0.21650635094610966169093079268823,
          2
        ),
        1/64
      )*0.33
     -0.945
     +sin(radialf(x, y, z)*10*pi)*0.01
    }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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