POV-Ray : Newsgroups : povray.general : color (pigment) as an absolute function of coordinates Server Time
15 Nov 2024 05:19:44 EST (-0500)
  color (pigment) as an absolute function of coordinates (Message 1 to 5 of 5)  
From: Gert  Van den Eynde
Subject: color (pigment) as an absolute function of coordinates
Date: 22 Nov 2004 06:35:13
Message: <41a1cef1@news.povray.org>
Hi all,

Is there a good way to have the pigment dependent on the absolute (x,y,z)
position? I want to create a height-field and a sphere where the pigment is
determined as a function of the <x,y,z,> vector....

thanks,
gert


Post a reply to this message

From: Thies Heidecke
Subject: Re: color (pigment) as an absolute function of coordinates
Date: 22 Nov 2004 08:52:28
Message: <41a1ef1c@news.povray.org>
"Gert Van den Eynde" <gvd### [at] hotmailcom> schrieb im Newsbeitrag
news:41a1cef1@news.povray.org...
> Hi all,
Hi,

> Is there a good way to have the pigment dependent on the absolute (x,y,z)
> position? I want to create a height-field and a sphere where the pigment
is
> determined as a function of the <x,y,z,> vector....
As a first short answer, have a look at the POV-Documentation at
  '3.4.11.15  Function as pattern'
If you have more questions feel free to ask!

> thanks,
> gert

Regards,
Thies


Post a reply to this message

From: Gert  Van den Eynde
Subject: Re: color (pigment) as an absolute function of coordinates
Date: 22 Nov 2004 10:10:30
Message: <41a20166@news.povray.org>
Thies Heidecke wrote:

> "Gert Van den Eynde" <gvd### [at] hotmailcom> schrieb im Newsbeitrag
> news:41a1cef1@news.povray.org...
>> Hi all,
> Hi,
> 
>> Is there a good way to have the pigment dependent on the absolute (x,y,z)
>> position? I want to create a height-field and a sphere where the pigment
> is
>> determined as a function of the <x,y,z,> vector....
> As a first short answer, have a look at the POV-Documentation at
>   '3.4.11.15  Function as pattern'
> If you have more questions feel free to ask!

thanks, missed that one. 

note to self: rtmom (read the manual once more)

bye,
gert


Post a reply to this message

From: Gert  Van den Eynde
Subject: Re: color (pigment) as an absolute function of coordinates
Date: 23 Nov 2004 10:43:44
Message: <41a35ab0@news.povray.org>
Gert  Van den Eynde wrote:

> Thies Heidecke wrote:
> 
>> "Gert Van den Eynde" <gvd### [at] hotmailcom> schrieb im Newsbeitrag
>> news:41a1cef1@news.povray.org...
>>> Hi all,
>> Hi,
>> 
>>> Is there a good way to have the pigment dependent on the absolute
>>> (x,y,z) position? I want to create a height-field and a sphere where the
>>> pigment
>> is
>>> determined as a function of the <x,y,z,> vector....
>> As a first short answer, have a look at the POV-Documentation at
>>   '3.4.11.15  Function as pattern'
>> If you have more questions feel free to ask!
> 
> thanks, missed that one.
> 
> note to self: rtmom (read the manual once more)

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?

thanks for any tips,
gert 

function [r,g,b] = mapcolor(v,vmin,vmax)

if (v < vmin),
    v = vmin;
end

if (v > vmax),
    v = vmax;
end

dv = vmax-vmin;

r = 1; g = 1; b = 1;

if (v < (vmin + 0.25 * dv)),
    r = 0.0;
    g = 4.0*(v-vmin)/dv;
elseif (v < (vmin + 0.5*dv)),
    r = 0.0;
    b = 1.0+4.0*(vmin+0.25*dv-v)/dv;
elseif (v < (vmin +0.75*dv)),
    r = 4.0*(v-vmin-0.5*dv)/dv;
    b = 0.0;
else
    g = 1.0+4.0*(vmin+0.75*dv-v)/dv;
    b = 0.0;
end


Post a reply to this message

From: Thies Heidecke
Subject: Re: color (pigment) as an absolute function of coordinates
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.