POV-Ray : Newsgroups : povray.unofficial.patches : Being able to call DLLs/SOs as user defined functions Server Time
4 Dec 2024 02:56:56 EST (-0500)
  Being able to call DLLs/SOs as user defined functions (Message 1 to 8 of 8)  
From: Mircode
Subject: Being able to call DLLs/SOs as user defined functions
Date: 20 Nov 2010 09:20:01
Message: <web.4ce7d82a3d7366653f6f52ea0@news.povray.org>
Hi there!

I am very unhappy with the unflexibility of user defined functions. Recursion is
not allowed, loops can not be implemented, the only way to branch is the select
function, which is very unhandy and I am not sure whether POV-Ray still
evaluates all branches and after that selects.

Furthermore I would like to be able to write to files from inside a function
during render time, not just while parsing.

(Please correct me if anything I said is wrong and actually possible)

The best way I see for a maximum of flexibility while maintaining (or even
enhancing) render performance would be the ability of including external
functions, defined in DLL libraries (or the Mac/Linux equivalents).

One could even think of a new type of surface where POV-Ray does not try to find
the isosurface of a 3D-function itself but hands the start point and the
direction vector of a ray to a function and expects the intersection point.

In my opinion this would be a great feature for POV-Ray, enhancing its (already
amazing) versatility a lot. And I think the implementation can't be that
difficult.

My problem is, that I have neither patience nor time to become familiar with the
POV-Ray source and implement this feature myself.

I hope that someone who already knows the source likes my idea and implements
it.

Peas out!


Post a reply to this message

From: Warp
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 20 Nov 2010 09:27:49
Message: <4ce7dae3@news.povray.org>
Mircode <Mircode> wrote:
> I am very unhappy with the unflexibility of user defined functions. Recursion is
> not allowed, loops can not be implemented, the only way to branch is the select
> function, which is very unhandy and I am not sure whether POV-Ray still
> evaluates all branches and after that selects.

  Actually recursive functions are allowed (at least they are in pov3.6).
You can eg. implement the Mandelbrot pattern as a user-defined function
(wihtout using the 'mandel' pattern, naturally). I have done that in the
past as a proof-of-concept.

-- 
                                                          - Warp


Post a reply to this message

From: Mircode
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 20 Nov 2010 14:35:00
Message: <web.4ce8220dfa289b23f6f52ea0@news.povray.org>
Oh, you are right, I tried it again, recursion is possible. I was so sure that
it was not...
I know that I can't say "When I tried it last time, it didn't work." But I could
swear...

When I tried to implement an isosurface approach for a menger sponge, I got a
warning that recursion is not allowed, so I copied and pasted the function for
each recursion level.

But that was only one aspect. Ok, loops can be implemented with recursion, too.
But still, the programming tools that are offered in user defined functions are
very limited and unhandy and being able to include DLLs would add the whole
mightiness of c++ into that tool box.


Post a reply to this message

From: bugman
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 19 Apr 2011 11:45:00
Message: <web.4dadad69fa289b21d1576610@news.povray.org>
I would really like to see this. As far as I know, it is not possible.

Here is some sample code demonstrating a very simple Mandelbrot using the
'mandel' pattern:
camera{orthographic location <-0.5,0,-1.5> look_at <-0.5,0,0> angle 90}
plane{z,0 pigment{mandel 100} finish{ambient 1}}

Here is my weak attempt to create a Mandelbrot set using user-defined functions:
camera{orthographic location <-0.5,0,-1.5> look_at <-0.5,0,0> angle 90}
#declare norm=function(x,y) {x*x+y*y};
#declare fx=function(x,y) {x*x-y*y};
#declare fy=function(x,y) {2*x*y};
#declare Mandelbrot=function(x,y)
{norm(fx(fx(x,y)+x,fy(x,y)+y)+x,fy(fx(x,y)+x,fy(x,y)+y)+y)};
plane{z,0 pigment{function{Mandelbrot(x,y)}} finish{ambient 1}}

I am using PovRay 3.6.1

If indeed it is possible to render Mandelbrot sets in POV-Ray as user-defined
functions, then it should also be possible to render Mandelbulb-type fractals as
isosurfaces in POV-Ray.

I really like Mircode's idea of implementing a method to call DLLs/SOs as user
defined functions. This would open the door for users to explore all kinds of
amazing isosurfaces.

Does anyone know if MegaPov supports anything like this?


Post a reply to this message

From: Warp
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 19 Apr 2011 12:05:29
Message: <4dadb2c9@news.povray.org>
bugman <nomail@nomail> wrote:
> I would really like to see this. As far as I know, it is not possible.

  Your example code has no recursion. Obviously it cannot produce the
Mandelbrot set without one. Try this:

//-------------------------------------------------------------------
#declare MaxIter = 32;

#declare MandelIteration = function(Re, Im, Zr, Zi, n)
{ select(n < MaxIter & Zr*Zr + Zi*Zi < 4, 0, n / MaxIter,
         MandelIteration(Re, Im,
                         Zr*Zr - Zi*Zi + Re,
                         2*Zr*Zi + Im,
                         n+1)) };

#declare Mandel = function { MandelIteration(x, y, 0, 0, 0) };

camera { location -z*3 look_at 0 }

box
{ <-3, -3, 0>, <3, 3, .1>
  pigment
  { function { Mandel(x, y, z) }
    color_map
    { [0 rgb 0]
      [1 rgb 1]
    }
  }
  finish { ambient 1 }
}
//-------------------------------------------------------------------

-- 
                                                          - Warp


Post a reply to this message

From: bugman
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 19 Apr 2011 13:50:01
Message: <web.4dadcb21fa289b21d1576610@news.povray.org>
Yay! After some further thought, I finally got it to work. This is very cool! I
had to cheat by using the 'sum' function to simulate an 'if' statement:
camera{orthographic location <-0.5,0,-1.5> look_at <-0.5,0,0> angle 90}
#declare imax=24;
#declare f=function(i,x,y,xc,yc)
{sum(j,(i+1)/imax,1,f(i+1,x*x-y*y+xc,2*x*y+yc,xc,yc))+sum(j,1,i/imax,sqrt(x*x+y*y))};
plane{z,0 pigment{function{f(0,0,0,x,y)}} finish{ambient 1}}


Post a reply to this message

From: bugman
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 19 Apr 2011 18:05:01
Message: <web.4dae068efa289b21d1576610@news.povray.org>
Thank you Warp. For some reason, I did not get your reply until after I posted
my last message. Anyway, that 'select' function is just the thing I've been
looking for. Using this approach, I was able to render a Mandelbulb in PovRay.
The following code is not very efficient, but it's an interesting demonstration.
Try it out!:

//runtime: 4 minutes, image size: 320x240
camera{location <-2.5,5,5> look_at <-0.5,0,0.25> up z sky z angle 25}
light_source{20*z,1}
#declare f=function(i,x,y,z,xc,yc,zc) {select(i>0 & x*x+y*y+z*z<4, 0,
sqrt(x*x+y*y+z*z),
f(i-1,(x*x-y*y)*(1-z*z/(x*x+y*y))+xc,2*x*y*(1-z*z/(x*x+y*y))+yc,-2*z*sqrt(x*x+y*y)+zc,xc,yc,zc))};
isosurface{function{f(24,x,y,z,x,y,z)-2} threshold 0 max_gradient 10
contained_by{sphere{<-0.5,0,0>,2}} pigment{rgb 1}}

In the process, I discovered something strange and evil about POV-Ray functions.
If I declare any helper functions before my 'f' function, everything goes
haywire. I'm not sure why this is, but it took me quite a while to discover this
problem.


Post a reply to this message

From: clipka
Subject: Re: Being able to call DLLs/SOs as user defined functions
Date: 29 Apr 2011 14:46:01
Message: <4dbb0769$1@news.povray.org>
Am 19.04.2011 17:42, schrieb bugman:

> I really like Mircode's idea of implementing a method to call DLLs/SOs as user
> defined functions. This would open the door for users to explore all kinds of
> amazing isosurfaces.
>
> Does anyone know if MegaPov supports anything like this?

Yes: I know for sure it doesn't.


Post a reply to this message

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