POV-Ray : Newsgroups : povray.general : colors map interpolation : Re: colors map interpolation Server Time
28 Mar 2024 14:42:36 EDT (-0400)
  Re: colors map interpolation  
From: Tor Olav Kristensen
Date: 22 Nov 2022 07:15:00
Message: <web.637cbc5ef841873aaaf434a689db30a9@news.povray.org>
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 GradientFunction = function { pigment { Gradient } }
>
>  #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 GradientFunction = function { pigment { Gradient } };
    #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
function instead of three.

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


Post a reply to this message

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