POV-Ray : Newsgroups : povray.advanced-users : Finding Pigment / color of an object Server Time
10 Oct 2026 04:02:45 EDT (-0400)
  Finding Pigment / color of an object (Message 1 to 16 of 16)  
From: user
Subject: Finding Pigment / color of an object
Date: 1 Mar 2009 07:57:52
Message: <49aa8650$1@news.povray.org>
Hi,
1) How can I know the pigment/color of a given object ?
2) What is the format of a pigment variable ? How can I extract each 
component ?

	Regards


Post a reply to this message

From: Chris B
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 08:40:47
Message: <49aa905f@news.povray.org>
<use### [at] domaininvalid> wrote in message news:49aa8650$1@news.povray.org...
> Hi,
> 1) How can I know the pigment/color of a given object ?

Hi,

Objects can be multicoloured. POV-Ray pigments can define complex colour 
patterns. The colour of an object is determined by the pigment assigned to 
that object at the particular location on the object you're interested in. 
The eval_pigment function can used to 'read' that colour from any pigment 
that you've assigned to an identifier.

> 2) What is the format of a pigment variable ? How can I extract each 
> component ?

Pigments can be assigned to identifiers in the standard way. You can use 
eval_pigment to determine the colour at a specific location in the pigment. 
The color value returned by the eval_pigment function is a standard rgb 
colour value. You can index individual RGB colour components using the 
identifier suffixes red, green and blue. So something like:

#declare MyPigment = pigment {rgb <0.1,0.2,0.3>}
#declare MyLocation = <1,2,3>;
#declare MyColour = eval_pigment(MyPigment,MyLocation);
#debug concat("Red: ",str(MyColour.red,3,3),"Green: 
",str(MyColour.green,3,3),"Blue: ",str(MyColour.blue,3,3),"\n")

Note, I didn't try running this, so keep your eyes open for syntax errors.

The colour you'll actually get in the rendered image can clearly be very 
different due to many factors, including the colours of any lights and other 
factors controlling the texture applied to the object.

Regards,
Chris B.

ps. It's more usual to see this sort of question on povray.newusers than on 
povray.advanced-users.


Post a reply to this message

From: clipka
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 09:45:00
Message: <web.49aa9eec2533534f2ddf2a340@news.povray.org>
> 1) How can I know the pigment/color of a given object ?

By remembering what you set it to ;)


> 2) What is the format of a pigment variable ? How can I extract each
> component ?

You cannot access the components of a pigment variable (as it may be a pattern)
[*]; however, you can access the r, g and b components of a color variable as
MyColor.x, MyColor.y and MyColor.z, respectively. Similarly, the filter
component can be retrieved as MyColor.t (sic!), while the transmit component
is, to my knowledge, not accessible.

The background behind this is that colors are treated as 5D-vectors, and that
the .x, .y and .z operators work not only on 3D vectors, but on vectors of any
(sufficiently high) dimension; the same goes for the .t operator which was
designed to access the 4th component of a 4D vector, probably originally
intended to represent time (hence the t; ironically, the 4th dimension in a
color vector is the filter component, not the transmit component).

(There are two more such operators, .u and .v, which can be used instead of .x
and .y if desired.)

[* okay, this is not exactly true; in fact you can use a pigment variable in a
pigment function, allowing you to retrieve the color at a given point...]


Post a reply to this message

From: clipka
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 09:50:00
Message: <web.49aaa0122533534f2ddf2a340@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> The eval_pigment function can used to 'read' that colour from any pigment
> that you've assigned to an identifier.

Hum... I live and learn...

> > 2) What is the format of a pigment variable ? How can I extract each
> > component ?
>
> Pigments can be assigned to identifiers in the standard way. You can use
> eval_pigment to determine the colour at a specific location in the pigment.
> The color value returned by the eval_pigment function is a standard rgb
> colour value. You can index individual RGB colour components using the
> identifier suffixes red, green and blue. So something like:

.... and this likewise. So I bet there are .transmit and .filter suffixes
likewise?


> ps. It's more usual to see this sort of question on povray.newusers than on
> povray.advanced-users.

Hey, *I* didn't know these, and I wouldn't consider me a newbie these days ;)


Post a reply to this message

From: Chris B
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 10:19:28
Message: <49aaa780$1@news.povray.org>
"clipka" <nomail@nomail> wrote in message 
news:web.49aaa0122533534f2ddf2a340@news.povray.org...
>> You can index individual RGB colour components using the
>> identifier suffixes red, green and blue. So something like:
>
> .... and this likewise. So I bet there are .transmit and .filter suffixes
> likewise?

Yes. Good guess :-)
The other one of interest is .gray which I guess averages out the rgb values 
(I've never used it).

>
>> ps. It's more usual to see this sort of question on povray.newusers than 
>> on
>> povray.advanced-users.
>
> Hey, *I* didn't know these, and I wouldn't consider me a newbie these days 
> ;)
>

Well I never claimed everyone knew the answer :-)

The general tone of the question led me to think it might be a new user (or 
at least someone new to the newsgroups) and povray.newusers quite often 
attracts more gentle responses. Maybe I'm being over sentitive :o)

Regards,
Chris B.


Post a reply to this message

From: Chris B
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 10:32:30
Message: <49aaaa8e$1@news.povray.org>
"clipka" <nomail@nomail> wrote in message 
news:web.49aa9eec2533534f2ddf2a340@news.povray.org...
>
> you can use a pigment variable in a
> pigment function, allowing you to retrieve the color at a given point...]
>

In fact I think that's how the eval_pigment macro works. If you have a lot 
of points that you need to check it's probably more efficient to define your 
own function once, because calling eval_pigment would redefine the function 
each time.

Regards,
Chris B.


Post a reply to this message

From: user
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 10:47:38
Message: <49aaae1a$1@news.povray.org>
use### [at] domaininvalid a écrit :
> Hi,
> 1) How can I know the pigment/color of a given object ?
> 2) What is the format of a pigment variable ? How can I extract each 
> component ?
> 
>     Regards
thanks you all for all your answers.
I might have been more precise in my question.
Given an object, how can I know its color at a given point ?
I was thinking of a function getColor(obj,position), something like 
min_extent(obj), for example.


Post a reply to this message

From: Chris B
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 11:11:12
Message: <49aab3a0$1@news.povray.org>
<use### [at] domaininvalid> wrote in message news:49aaae1a$1@news.povray.org...
> use### [at] domaininvalid a écrit :
>> Hi,
>> 1) How can I know the pigment/color of a given object ?
>> 2) What is the format of a pigment variable ? How can I extract each 
>> component ?
>>
>>     Regards
> thanks you all for all your answers.
> I might have been more precise in my question.
> Given an object, how can I know its color at a given point ?
> I was thinking of a function getColor(obj,position), something like 
> min_extent(obj), for example.
>


You can assign the pigment to an identifier. Use the identifier to assign 
the pigment to the object and use the same pigment identifier with the 
eval_pigment macro to establish the color at a position of your choosing. 
You can certainly use the min_extent function to retrieve a location if 
that's the position that you want to evaluate.

You should make sure you don't transform the object after assigning the 
declared pigment to it.

Regards,
Chris B.


Post a reply to this message

From: clipka
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 11:25:00
Message: <web.49aab6602533534f2ddf2a340@news.povray.org>
use### [at] domaininvalid wrote:
> I might have been more precise in my question.
> Given an object, how can I know its color at a given point ?
> I was thinking of a function getColor(obj,position), something like
> min_extent(obj), for example.

As far as I know you can't. You can, however, remember the pigment you assigned
to the object, and use that eval_pigment() macro Chris mentioned.

The *apparent* color of an object as seen from point P, however, is yet another
story: You simply cannot do that, as it depends on lighting conditions and - if
the object has a reflective or refractive material - other objects nearby. You'd
need to set up a complete scene, trace it, and use the resulting image in a
pattern function to retrieve individual pixels from it for your main shot.

Is there something specific you intend to do? Maybe there's a different way to
achieve the desired results.


Post a reply to this message

From: user
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 12:07:40
Message: <49aac0dc@news.povray.org>
use### [at] domaininvalid a écrit :
> use### [at] domaininvalid a écrit :
> 
>> Hi,
>> 1) How can I know the pigment/color of a given object ?
>> 2) What is the format of a pigment variable ? How can I extract each 
>> component ?
>>
>>     Regards
> 
> thanks you all for all your answers.
> I might have been more precise in my question.
> Given an object, how can I know its color at a given point ?
> I was thinking of a function getColor(obj,position), something like 
> min_extent(obj), for example.
> 
>     
the problem, is that, as the object is passed as an argument to a macro, 
I have no a priori idea of its color...


Post a reply to this message

From: clipka
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 12:30:00
Message: <web.49aac5ff2533534f2ddf2a340@news.povray.org>
use### [at] domaininvalid wrote:
> the problem, is that, as the object is passed as an argument to a macro,
> I have no a priori idea of its color...

Then, unfortunately, you are lost. Unless you can convince the user to pass the
pigment as a separate parameter.


Post a reply to this message

From: Alain
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 17:15:57
Message: <49ab091d$1@news.povray.org>
use### [at] domaininvalid nous illumina en ce 2009-03-01 10:47 -->
> use### [at] domaininvalid a écrit :
>> Hi,
>> 1) How can I know the pigment/color of a given object ?
>> 2) What is the format of a pigment variable ? How can I extract each 
>> component ?
>>
>>     Regards
> thanks you all for all your answers.
> I might have been more precise in my question.
> Given an object, how can I know its color at a given point ?
> I was thinking of a function getColor(obj,position), something like 
> min_extent(obj), for example.
> 
>     

You can use the trace function to find a point at the surface of an object. If 
you have a texture identifier associated to that object, you can then use 
eval_pigment to get the pigment at that location.

Be wary that if you translate, rotate or scale the object after you assign it 
the texture, the texture will get transformed with the object, but the texture 
evaluated by eval_pigment wont. So, it's best to evaluate the pigment before any 
transformations. The other way, is to trace to an invert transformed point.

-- 
Alain
-------------------------------------------------
When you can't tell the difference between satire and what your opposition 
actually believes, its about time to have a good laugh at it all


Post a reply to this message

From: Kenneth
Subject: Re: Finding Pigment / color of an object
Date: 1 Mar 2009 20:50:01
Message: <web.49ab3a082533534ff50167bc0@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:

>
> The other one of interest is .gray which I guess averages out the rgb values
> (I've never used it).
>

The .gray 'averaging' scheme seems to be full of black magic and voodoo. I've
lately been trying to figure out just *how* it produces its values (armed with
the only formula found in the docs, at "HF_Gray_16"...which offers no real hint
of the underlying computations.) But I'll leave that question for a later post
of its own. All in all, very mysterious!

KW


Post a reply to this message

From: Thomas de Groot
Subject: Re: Finding Pigment / color of an object
Date: 2 Mar 2009 03:03:19
Message: <49ab92c7$1@news.povray.org>
"clipka" <nomail@nomail> schreef in bericht 
news:web.49aaa0122533534f2ddf2a340@news.povray.org...
> "Chris B" <nom### [at] nomailcom> wrote:
>> The eval_pigment function can used to 'read' that colour from any pigment
>> that you've assigned to an identifier.
>
> Hum... I live and learn...
>

It is great to place objects on a surface using a pre-defined image_map to 
determine where you want to put what. For instance, you can write a macro 
like this one:

#macro EvalPig3x(Map,Pos,Object1,Object2,Object3)
  #local Shade = eval_pigment(Map,<Pos.x,0,Pos.z>);
  #if (Shade.red  = 1)
    object {
      Object1
      translate Pos
    }
  #end
  #if (Shade.green = 1)
    object {
      Object2
      translate Pos
    }
  #end
  #if (Shade.blue = )
    object {
      Object3
      translate Pos
    }
  #end
#end


Thomas


Post a reply to this message

From: Bill Pragnell
Subject: Re: Finding Pigment / color of an object
Date: 2 Mar 2009 05:20:01
Message: <web.49abb2852533534f6dd25f0b0@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> > The other one of interest is .gray which I guess averages out the rgb values
> > (I've never used it).
>
> The .gray 'averaging' scheme seems to be full of black magic and voodoo. I've
> lately been trying to figure out just *how* it produces its values (armed with
> the only formula found in the docs, at "HF_Gray_16"...which offers no real hint
> of the underlying computations.) But I'll leave that question for a later post
> of its own. All in all, very mysterious!

The isosurface tutorial page mentions it:

gray value = Red*29.7% + Green*58.9% + Blue*11.4%

and gives a more thorough run-down on colour dot operators. Look here:

http://www.povray.org/documentation/view/3.6.1/73/

and scroll down to 1.3.3.3.7 - "Pigment and noise functions".

Bill


Post a reply to this message

From: Kenneth
Subject: Re: Finding Pigment / color of an object
Date: 3 Mar 2009 09:30:01
Message: <web.49ad3ed52533534ff50167bc0@news.povray.org>
"Bill Pragnell" <bil### [at] hotmailcom> wrote:

> The isosurface tutorial page mentions it:
>
> gray value = Red*29.7% + Green*58.9% + Blue*11.4%
>
> and gives a more thorough run-down on colour dot operators. Look here:
>
> http://www.povray.org/documentation/view/3.6.1/73/
>
> and scroll down to 1.3.3.3.7 - "Pigment and noise functions".
>


Thanks, didn't remember seeing it there.  The .hf operator is intriguing.
Hmm....

KW


Post a reply to this message

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