POV-Ray : Newsgroups : povray.advanced-users : <no subject> Server Time
25 Jul 2024 09:10:23 EDT (-0400)
  <no subject> (Message 1 to 5 of 5)  
From: Bald Eagle
Subject: <no subject>
Date: 3 Jul 2023 19:45:00
Message: <web.64a35d5ec23a6d91f9dae3025979125@news.povray.org>
So, I had some experiments I wanted to try, but I need to make some functions
that are based on other functions.
In order to vary what base function I use, I have to do that with a macro, which
seems to work fine, but I seem to be missing something, either in the creation
syntax or the invocation syntax.


#declare Zero = function (N) {0}
#declare One = function (N) {1}


#macro MakeFunction (Function)
 function {Function (0) + 1}
#end

#declare Two = MakeFunction (One);

#debug concat( "Zero = ", str (Zero (10), 0, 3), "\n")
#debug concat( "One = ", str (One (10), 0, 3), "\n")

#declare Val = Two (10);

#debug concat( "Two = ", str (Val, 0, 3), "\n")

That gets me:

Parse Error: Expected 'numeric expression', ) found instead

I have yet to find a way around that.  Though I could swear that I've done
something similar to this before....


Does anyone have any ideas?



- BW


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: <no subject>
Date: 3 Jul 2023 20:50:00
Message: <web.64a36b886f92e856ba2b3ee089db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I had some experiments I wanted to try, but I need to make some functions
> that are based on other functions.
> In order to vary what base function I use, I have to do that with a macro, which
> seems to work fine, but I seem to be missing something, either in the creation
> syntax or the invocation syntax.
>
>
> #declare Zero = function (N) {0}
> #declare One = function (N) {1}
>
>
> #macro MakeFunction (Function)
>  function {Function (0) + 1}
> #end
>
> #declare Two = MakeFunction (One);
>
> #debug concat( "Zero = ", str (Zero (10), 0, 3), "\n")
> #debug concat( "One = ", str (One (10), 0, 3), "\n")
>
> #declare Val = Two (10);
>
> #debug concat( "Two = ", str (Val, 0, 3), "\n")
>
> That gets me:
>
> Parse Error: Expected 'numeric expression', ) found instead
>
> I have yet to find a way around that.  Though I could swear that I've done
> something similar to this before....
>
>
> Does anyone have any ideas?

Try this:


#macro MakeFunction(Fn)

    function(N) { Fn(0) + 1 }

#end // macro MakeFunction


--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Leroy
Subject: Re: <no subject>
Date: 4 Jul 2023 14:20:00
Message: <web.64a461c46f92e856f47dfe88f712fc00@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I had some experiments I wanted to try, but I need to make some functions
> that are based on other functions.
> In order to vary what base function I use, I have to do that with a macro, which
> seems to work fine, but I seem to be missing something, either in the creation
> syntax or the invocation syntax.
>
>
> #declare Zero = function (N) {0}
> #declare One = function (N) {1}
>
>
> #macro MakeFunction (Function)
>  function {Function (0) + 1}
> #end
>
> #declare Two = MakeFunction (One);
>
> #debug concat( "Zero = ", str (Zero (10), 0, 3), "\n")
> #debug concat( "One = ", str (One (10), 0, 3), "\n")
>
> #declare Val = Two (10);
>
> #debug concat( "Two = ", str (Val, 0, 3), "\n")
>
> That gets me:
>
> Parse Error: Expected 'numeric expression', ) found instead
>
> I have yet to find a way around that.  Though I could swear that I've done
> something similar to this before....
>
Here's a macro that will do what you want maybe.
It returns a function of a function

#macro Sf_Inv(F1) //inverse ground values
  function(x,z){1-F1(x,z)}
#end

use like this:

#declare F1=function(x,z){what ever}
#declare FncA=function(x,z){Sf_Inv(F1)}
#declare B=FncA(6,7);

I took this off a whole list of functions I was playing with a while back.
With this basic syntax you can put togather several functions and values to get
some interesting and hopeful useful functions.
Have Fun!


Post a reply to this message

From: Bald Eagle
Subject: Re: <no subject>
Date: 4 Jul 2023 15:55:00
Message: <web.64a4789f6f92e8561f9dae3025979125@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

> Try this:
>
>
> #macro MakeFunction(Fn)
>
>     function(N) { Fn(0) + 1 }
>
> #end // macro MakeFunction

Ah, yes.   I omitted the function parameters, so it was expecting x, y, z or
something.

That works, thanks.

Of course, when trying to debug some other scene doodle, because math.inc was
squawking at me about VEq, I saw that you already wrote probably exactly what i
needed in the form of fn_Gradient_Directional.

(I'm trying to replicate Shadertoy's / GLSL's fwidth () function):

// fwidth is simply the sum of the absolute values of dfdx and dfdy,
// which signifies the window-space rate of change of the parameter in the x and
y axes, respectively.
// You can determine these by using finite differences

Forward I plod....


- BW


Post a reply to this message

From: Bald Eagle
Subject: Re: <no subject>
Date: 10 Jul 2023 19:30:00
Message: <web.64ac94216f92e8561f9dae3025979125@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> (I'm trying to replicate Shadertoy's / GLSL's fwidth () function):

> Forward I plod....

Well, I didn't really get that to work as well as I planned, since it may only
work with (x, y, z) functions and not my (px, py) functions.

I did manage to daisy-chain a massive pile of functions, follow the daisy-chain
of propagated parser errors, "fix" everything to the point where the code runs
without errors, and gives me --- something.
Not really at all what it's supposed to look like, but it's really square one of
translating a lot of complicated Shadertoy code with lots of magic numbers,
ridiculous equations, and very little in the way of explanatory documentation.

But I have hope that fixing it will be easier than that painful first step of
translating the raw code.  I'm sure I've failed to properly daisy-chain some
functions, so I'll go looking there first.

- BW


Post a reply to this message


Attachments:
Download 'fishscales1.png' (258 KB)

Preview of image 'fishscales1.png'
fishscales1.png


 

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