POV-Ray : Newsgroups : povray.general : Function returns 3d vector Server Time
28 Nov 2024 14:47:14 EST (-0500)
  Function returns 3d vector (Message 1 to 3 of 3)  
From: Ben Chambers
Subject: Function returns 3d vector
Date: 21 Nov 2006 02:51:34
Message: <4562b006@news.povray.org>
I'm certain this has been asked before, but I can't seem to find it (or 
figure it out from the docs).

All of my user defined functions return a float value.  How can I write 
a function that returns a 3d vector?

The context is simply a pigment block.  What I want is something like this:

#declare f1=...
#declare f2=...
#declare f3=...
pigment {color rgb <f1(x,y,z), f2(x,y,z), f3(x,y,z)>]

Of course, I'd be happy declaring only 1 function if it allowed me this 
functionality (no pun intended!).

...Chambers


Post a reply to this message

From: Mike Williams
Subject: Re: Function returns 3d vector
Date: 21 Nov 2006 04:26:41
Message: <Q7xXBFAZQsYFFwuV@econym.demon.co.uk>
Wasn't it Ben Chambers who wrote:
>I'm certain this has been asked before, but I can't seem to find it (or 
>figure it out from the docs).
>
>All of my user defined functions return a float value.  How can I write 
>a function that returns a 3d vector?
>
>The context is simply a pigment block.  What I want is something like this:
>
>#declare f1=...
>#declare f2=...
>#declare f3=...
>pigment {color rgb <f1(x,y,z), f2(x,y,z), f3(x,y,z)>]
>
>Of course, I'd be happy declaring only 1 function if it allowed me this 
>functionality (no pun intended!).

The docs for 3.6 say:

  3.2.1.6.5  Declaring User-Defined Color Functions

  Right now you may only declare color functions using one of the 
  special function types. The only supported type is the pigment 
  function.

What you can do is have three separate pigments, each generated from one
function, and average them

#declare R = pigment {function {f1(x,y,z)}
   colour_map{[0 rgb 0][1 rgb <3,0,0>]}}

#declare G = pigment {function {f2(x,y,z)}
   colour_map{[0 rgb 0][1 rgb <0,3,0>]}}

#declare B = pigment {function {f3(x,y,z)}
   colour_map{[0 rgb 0][1 rgb <0,0,3>]}}

sphere {0,1
  pigment {average
    pigment_map {
      [1 R]
      [1 G]
      [1 B]
    }
  }
}

By averaging three pigments that are on different colour channels, the
brightness gets divided by 3. That's why we triple the brightness. 
E.g. if the output colour of a particular pixel is white, we'd get that
by the fact that (<3,0,0> + <0,3,0> + <0,0,3>)/3 = <1,1,1>.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Ben Chambers
Subject: Re: Function returns 3d vector
Date: 21 Nov 2006 05:38:39
Message: <4562d72f$1@news.povray.org>
Never mind, I figured it out.  Code below ;)

...Chambers


#declare f1=...
#declare f2=...
#declare f3=...

#declare p1=pigment{f1(x,y,z) color_map {[0 color rgb 0][1 color rgb x*3]}
#declare p2=pigment{f2(x,y,z) color_map {[0 color rgb 0][1 color rgb y*3]}
#declare p3=pigment{f3(x,y,z) color_map {[0 color rgb 0][1 color rgb z*3]}

#declare p_final = pigment {
  average
  pigment_map {
   [1 p1]
   [1 p2]
   [1 p3]
  }
}


Post a reply to this message

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