POV-Ray : Newsgroups : povray.general : color (pigment) as an absolute function of coordinates : Re: color (pigment) as an absolute function of coordinates Server Time
2 Aug 2024 08:12:15 EDT (-0400)
  Re: color (pigment) as an absolute function of coordinates  
From: Thies Heidecke
Date: 25 Nov 2004 16:28:36
Message: <41a64e84$1@news.povray.org>
>Gert Van den Eynde" <gvd### [at] hotmailcom> schrieb im Newsbeitrag
news:41a35ab0@news.povray.org...
> Gert  Van den Eynde wrote:
>
> hmm, did that and it isn't really clear to me how to proceed. Below is (in
> Octave) my color function. The variable v in the script is to be the
height
> of the height-field (y-value). vmin and vmax are 0 and 1 in the case of a
> height_field, no? How do I put this function in povray and have it used as
> the pigment of my heightfield?

Hi,
i borrowed the average-pigment-idea by Slimes answer to the thread
'3d color function' in povray.newusers which looks like this:

pigment {
  average
  pigment_map {
    [1 function {f_r(x,y,z)} color_map {[0 rgb 0][1 rgb <1,0,0>*3]}]
    [1 function {f_g(x,y,z)} color_map {[0 rgb 0][1 rgb <0,1,0>*3]}]
    [1 function {f_b(x,y,z)} color_map {[0 rgb 0][1 rgb <0,0,1>*3]}]
  }
}

now you need the 3 functions for rgb;
i think the difficulty in converting your function to POV-SDL are the
if-else-constructs. These can be modeled in a function with the
 'select'-function. Your function converted then looks like this:

#declare f_r = function(v)
  {
    select(
      v-0.5,
      0,
      select(
        v-0.75,
        4*v-2,
        1
      )
    )
  };

#declare f_g = function(v)
  {
    select(
      v,
      0,              // v<0
      select(         // v>0
        v-1,
        select(       //   0<v<1
          v-0.25,
          4*v,        //     0<v<0.25
          select(     //     1>v>0.25
            v-0.75,
            1,        //       0.25<v<0.75
            4-4*v     //       1>v>0.75
          )
        ),
        0             //   v>1
      )
    )
  };

#declare f_b = function(v)
  {
    select(
      v-0.25,
      1,
      select(
        v-0.5,
        2-4*v,
        0
      )
    )
  };


of course you can write this in one line if you want, i just
formatted it for better readibility.

For your specific rgb-function though i would do it with the
following functions, which do the same job, just a bit more
elegant:

#declare f_r = function(v) { min(max(4*v-2,0),1) };
#declare f_g = function(v) { min(max(2-abs(4*(v-0.5)),0),1) };
#declare f_b = function(v) { min(max(2-4*v,0),1) };

If you want to avoid the discontinuities at 0.25, 0.5 and 0.75
you'll have to use more smooth functions like the cosine.

> thanks for any tips,
no problem
> gert

Regards,
Thies


Post a reply to this message

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