POV-Ray : Newsgroups : povray.general : colors map interpolation : Re: colors map interpolation Server Time 4 Jun 2023 06:34:22 EDT (-0400)
 Re: colors map interpolation
 From: Tor Olav Kristensen Date: 22 Nov 2022 07:15:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637cbc5ef841873aaaf434a689db30a9%40news.povray.org",
"dateCreated": "2022-11-22T12:15:00+00:00",
"datePublished": "2022-11-22T12:15:00+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
kurtz le pirate <kur### [at] gmailcom> wrote:
> On 20/11/2022 21:07, Bald Eagle wrote:
> > "Bald Eagle" <cre### [at] netscapenet> wrote:
> >
> >> Sure - I think you could take something like a gradient pigment pattern, apply
> >> that color mapping to it, and then use that as a function.   Then you could pass
> >> in a space coordinate with a vector component parallel to that gradient, and the
> >> function would return the interpolated color vector as a result.
> >> You would of course, have to write / generate 3 functions - one for the .r, .g,
> >> and .b components.
> >
> >
> >
> > Like this:
> > ...
>
>
> Waouh, impressive !!!
>
> Based on your brilliant example, here is the macro :
> // -------------------------------------------------------------------
> #macro GetColor(thisColorMap, thisEntry)
>  #local index = max(0.0, min(thisEntry, 1.0));
>
>  #local Gradient = pigment { gradient x color_map { thisColorMap } }
>
>  #local R = GradientFunction (index, 0, 0).red;
>  #local G = GradientFunction (index, 0, 0).green;
>  #local B = GradientFunction (index, 0, 0).blue;
>
>  rgb <R, G, B>
> #end
> // -------------------------------------------------------------------
>...

Hi Kurz

I don't know if it was your intention to not extract the filter and
transmit components of the color.

If you write the macro like this:

#macro GetColor(ThisColorMap, ThisEntry)

#local Index = max(0.0, min(ThisEntry, 1.0));
#local Gradient = pigment { gradient x color_map { ThisColorMap } }
#local Color = color GradientFunction(Index, 0, 0);

Color

#end // macro GetColor

- then it will extract all the color components.

You'll also get a faster macro because of only one call to the pigment

The value returned from the pigment function is a rgbft vector, so if all
of the components are of interest then there's no need to disassemble it
and then reassemble it.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k
```