POV-Ray : Newsgroups : povray.advanced-users : Color function : Re: Color function Server Time
28 Jul 2024 14:24:35 EDT (-0400)
  Re: Color function  
From: val
Date: 20 Apr 2005 10:55:00
Message: <web.42666bf1d92a7201238336500@news.povray.org>
"PM 2Ring" <nomail@nomail> wrote:
> Here's one possibility below. You may also like to know that POV can cope
> with negative colour values. I'll post a relevant example soon.
>
>
> //Make a color_map from a0 to a1
> #macro CMRange(a0, a1)color_map{[0 a0][1 a1]}#end
>
> //Make a color_map from Black to a
> #macro CMFull(a)CMRange(rgb 0, a)#end
>
> #declare TestPig = pigment{hexagon rgb<1 .9 .5>, rgb <.85 .5 .6>, rgb <0 0
> ..8>}
>
> #declare f_Pig = function{pigment{TestPig}}
>
> //Turn a pigment function into a real-live pigment!
> #declare PigRGB =
> pigment{
>   average
>   pigment_map {
>     [1 function{f_Pig(x,y,z).red} CMFull(red 3)]
>     [1 function{f_Pig(x,y,z).green} CMFull(green 3)]
>     [1 function{f_Pig(x,y,z).blue} CMFull(blue 3)]
>   }
> }
>
> cylinder{
>   -.1*y, .1*y, 3
>
>   pigment{
>     PigRGB
>     //TestPig
>   }
> }
>
> //---------------------------------------------------------

Thanks. It works! It took me a couple of days to realize that
the function should span in RGB components:

#declare fun_x = function { color_x*max(0, (sx*(x-px) + sy*(y-py) +
sz*(z-pz))/raio) + color_x*amb  }
#declare fun_y = function { color_y*max(0, (sx*(x-px) + sy*(y-py) +
sz*(z-pz))/raio) + color_y*amb  }
#declare fun_z = function { color_z*max(0, (sx*(x-px) + sy*(y-py) +
sz*(z-pz))/raio) + color_z*amb  }

#declare PigRGB =
pigment{
  average
  pigment_map {
    [1 function{fun_x(x,y,z)} color_map{[0 rgb 0][1 red 3]}]
    [1 function{fun_y(x,y,z)} color_map{[0 rgb 0][1 green 3]}]
    [1 function{fun_z(x,y,z)} color_map{[0 rgb 0][1 blue 3]}]
  }
}

// create a sphere shape
sphere {
  pos        // center of sphere <X Y Z>
  raio       // radius of sphere
  pigment{ PigRGB }
  finish { ambient 1 diffuse 0 }
}


Val


Post a reply to this message

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