POV-Ray : Newsgroups : povray.advanced-users : Function logic? Server Time
28 Jul 2024 18:20:20 EDT (-0400)
  Function logic? (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: Tim Nikias
Subject: Function logic?
Date: 6 Dec 2004 09:33:11
Message: <41b46da7$1@news.povray.org>
Could someone explain to me, why I have to include an #if-switch into my
macro?

First, the explanation of the macro:
I'm building a function that I later use for a heightfield. As the
heightfield is generated from the xy-plane, I need to align the pigment
which I "build" on the xz-plane for better visualization in my head, but I
have removed that part from the macro for simplification. I have made
"pigment-stamps" for the steps, and just position a step, feed it to the
macro, and it multiplies the original snow-field with the new step, and
voila! I've got another footprint in the snow. The old snow-function is
replaced with the new one, all temporary function-conversions released via
#undef and I'm prepared for the next print (or snowball ;-).

So, here's the Macro:
#macro Add2SnowFunction(_Pigment1)
  #ifndef (_SnowAdded) #declare _SnowAdded = 0; #end
  #declare _Temp1Function = function{pigment{_Pigment1}}
  #if (_SnowAdded=0)
    #declare _Temp2Function = function{SnowFunction(x,y,z).x *
_Temp1Function(x,y,z).x}
  #else
    #declare _Temp2Function = function{SnowFunction(x,y,z) *
_Temp1Function(x,y,z).x}
  #end
  #undef SnowFunction
  #declare SnowFunction = _Temp2Function;
  #undef _Temp1Function
  #undef _Temp2Function
  #declare _SnowAdded = 1;
#end

Now to the problem: Why is it that I have to put a ".x" after the function
the first time I use it, but not afterwards? Fact is, if I don't use it the
first time, I get an error message, and if I use it every time, I get an
error message. Hence, I need to write a check into my Macro to look if it
has already been called once. And even with this switch, if I decide to
modify the function "by hand" (without the use of the macro) the switch
won't work. And #ifdef doesn't do the job, obviously, #ifdef tells me that
SnowFunction is declared, be it first time of use or 100th time of use, so
it's no help. Explanations or a better, working, ingenious way for the
switch appreciated.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Mike Williams
Subject: Re: Function logic?
Date: 6 Dec 2004 11:28:02
Message: <NWhr5BAxhItBFw36@econym.demon.co.uk>
Wasn't it Tim Nikias who wrote:

>Now to the problem: Why is it that I have to put a ".x" after the function
>the first time I use it, but not afterwards?

There are two sorts of functions, ordinary functions and pigment
functions. When you evaluate a pigment function you get a colour rather
than a value. 

POV doesn't currently allow you to perform arithmetic on pigment
functions, but you can choose one of the components of the pigment
function, by adding ".red" (or, equivalently ".x") to convert it into an
ordinary function.

Somewhere outside your macro you must have declared SnowFunction to
initially be a pigment function, but when you redeclare it you are
making it into an ordinary function.

Once you've performed that conversion, you've not got a pigment function
any more, so appending ".x" to the result is wrong.

What you need to change is the original declaration of Snowfunction,
which is somewhere outside your macro. Stick a ".x" on that declaration
and you'll be working with non-pigment functions throughout.


To make things even better, you could try rewriting the whole thing to
use patterns instead of pigments. The code will probably be simpler and
the processing more efficient without those unwanted .blue and .green
channels.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tim Nikias
Subject: Re: Function logic?
Date: 6 Dec 2004 11:56:37
Message: <41b48f45$1@news.povray.org>
> SNIPPED Function-Pigment/Pattern-Issue

Ah, thank you, now I understand. It does make sense after all... ;-)

> To make things even better, you could try rewriting the whole thing to
> use patterns instead of pigments. The code will probably be simpler and
> the processing more efficient without those unwanted .blue and .green
> channels.

Care to give a small starter with how to use patterns with functions? What I
do now is simply use a pattern and use a colormap ranging from rgb 0 to rgb
1, but not just {[0 rgb 0][1 rgb 1]}, so I'm not sure if that is possible
with just patterns.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Tim Nikias
Subject: Re: Function logic?
Date: 6 Dec 2004 12:15:41
Message: <41b493bd$1@news.povray.org>
> What you need to change is the original declaration of Snowfunction,
> which is somewhere outside your macro. Stick a ".x" on that declaration
> and you'll be working with non-pigment functions throughout.

Another thing: Where exactly do I put that ".x"? I've got
#declare Snow_Pig_Turb = pigment{bozo color_map{[0 rgb 1][1 rgb .85]}}
#declare SnowFunction = function{pigment{Snow_Pig_Turb}}

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Mike Williams
Subject: Re: Function logic?
Date: 6 Dec 2004 13:26:03
Message: <jEBA9BAwPKtBFwS8@econym.demon.co.uk>
Wasn't it Tim Nikias who wrote:
>> SNIPPED Function-Pigment/Pattern-Issue
>
>Ah, thank you, now I understand. It does make sense after all... ;-)
>
>> To make things even better, you could try rewriting the whole thing to
>> use patterns instead of pigments. The code will probably be simpler and
>> the processing more efficient without those unwanted .blue and .green
>> channels.
>
>Care to give a small starter with how to use patterns with functions? What I
>do now is simply use a pattern and use a colormap ranging from rgb 0 to rgb
>1, but not just {[0 rgb 0][1 rgb 1]}, so I'm not sure if that is possible
>with just patterns.

Patterns naturally produce a value in the range 0 to 1. The colour map
specifies what colours correspond to those values.
So by using {[0 rbg <0,0,0>][1 rgb <1,1,1>]} and then using only the red
channel (.x) you actually just get back the value that the pattern
returned in the fist place.

So if you had something like

#declare F1=function {
  pigment {
   granite turbulence 1 
   colour_map {[0 rgb 0][1 rgb 1]}
  }
}
#declare F2 = function {F1(x,y,z).x}


You can, instead, write just

#declare F2=function {
  pattern {
    granite turbulence 1
  }
}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Mike Williams
Subject: Re: Function logic?
Date: 6 Dec 2004 13:28:15
Message: <$0FHxEAjSKtBFwyl@econym.demon.co.uk>
Wasn't it Tim Nikias who wrote:
>> What you need to change is the original declaration of Snowfunction,
>> which is somewhere outside your macro. Stick a ".x" on that declaration
>> and you'll be working with non-pigment functions throughout.
>
>Another thing: Where exactly do I put that ".x"? I've got
>#declare Snow_Pig_Turb = pigment{bozo color_map{[0 rgb 1][1 rgb .85]}}
>#declare SnowFunction = function{pigment{Snow_Pig_Turb}}

I think you need to add an extra step

#declare Snow_Pig_Turb = pigment{bozo color_map{[0 rgb 1][1 rgb .85]}}
#declare Pig_Function = function{pigment{Snow_Pig_Turb}}
#declare SnowFunction = function{Pig_Function(x,y,z).x}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tim Nikias
Subject: Re: Function logic?
Date: 6 Dec 2004 17:19:10
Message: <41b4dade$1@news.povray.org>
> Patterns naturally produce a value in the range 0 to 1. The colour map
> specifies what colours correspond to those values.
> So by using {[0 rbg <0,0,0>][1 rgb <1,1,1>]} and then using only the red
> channel (.x) you actually just get back the value that the pattern
> returned in the fist place.

Yes, I knew that. Perhaps I phrased my question wrong.
When I use a color_map like this:
color_map{[0 rgb .5][.4 rgb .9][.6 rgb .2][1 rgb 0]}

How could I achieve that when using just the pattern? Is that even possible?

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Tim Nikias
Subject: Re: Function logic?
Date: 6 Dec 2004 17:20:59
Message: <41b4db4b$1@news.povray.org>
> I think you need to add an extra step
>
> #declare Snow_Pig_Turb = pigment{bozo color_map{[0 rgb 1][1 rgb .85]}}
> #declare Pig_Function = function{pigment{Snow_Pig_Turb}}
> #declare SnowFunction = function{Pig_Function(x,y,z).x}

Thanks, this works nicely. Should have come to that conclusion by myself,
but once you get someone telling you how to do things, you trust them... :-)

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Alain
Subject: Re: Function logic?
Date: 6 Dec 2004 17:26:21
Message: <41b4dc8d$1@news.povray.org>
Mike Williams nous apporta ses lumieres ainsi en ce 2004-12-06 13:27... :

>Wasn't it Tim Nikias who wrote:
>  
>
>>>What you need to change is the original declaration of Snowfunction,
>>>which is somewhere outside your macro. Stick a ".x" on that declaration
>>>and you'll be working with non-pigment functions throughout.
>>>      
>>>
>>Another thing: Where exactly do I put that ".x"? I've got
>>#declare Snow_Pig_Turb = pigment{bozo color_map{[0 rgb 1][1 rgb .85]}}
>>#declare SnowFunction = function{pigment{Snow_Pig_Turb}}
>>    
>>
>
>I think you need to add an extra step
>
>#declare Snow_Pig_Turb = pigment{bozo color_map{[0 rgb 1][1 rgb .85]}}
>#declare Pig_Function = function{pigment{Snow_Pig_Turb}}
>#declare SnowFunction = function{Pig_Function(x,y,z).x}
>
>  
>
Acording to the documentation spotted is identical to bozo, without a 
default colour_map. Try:
#declare Pat_Function = function{pattern{spotted}}
#declare SnowFunction = function{Pat_Function(x,y,z) * 0.15 +0.85}// 
limit to the 0.85 to 1 range

Alain


Post a reply to this message

From: Christoph Hormann
Subject: Re: Function logic?
Date: 6 Dec 2004 17:30:03
Message: <cp2m89$t61$1@chho.imagico.de>
Tim Nikias wrote:
> 
> Yes, I knew that. Perhaps I phrased my question wrong.
> When I use a color_map like this:
> color_map{[0 rgb .5][.4 rgb .9][.6 rgb .2][1 rgb 0]}
> 
> How could I achieve that when using just the pattern? Is that even possible?

No but you can use a spline function (which would also allow smooth 
curves while a color map is always piecewise linear).

Use of spline functions is explained in Mike's isosurface tutorial AFAIK.

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 23 Sep. 2004 _____./\/^>_*_<^\/\.______


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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