POV-Ray : Newsgroups : povray.binaries.tutorials : Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial Server Time
22 Dec 2024 10:43:23 EST (-0500)
  Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial (Message 1 to 10 of 22)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Cousin Ricky
Subject: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 18 Apr 2024 16:44:36
Message: <66218634$1@news.povray.org>
THE ISSUE

What is gamma, why should assumed_gamma be set to 1, and how should we
use the sRGB keywords introduced with POV-Ray 3.7?

In the real world, a 1,600 lumen lamp emits twice as much light as an
800 lumen lamp, and a 40% gray object reflects half as much light as an
80% gray object.  To render this reality, POV-Ray must use linear color.
 Setting global_settings { assumed_gamma 1 } accomplishes this goal, and
has been the recommended setting since POV-Ray 3.7.

The problem is that our perceptions are non-linear, and our monitors and
software often reflect that non-linearity.  Gamma is the measure of this
non-linearity.  Typically, RGB colors are specified with the non-linear
sRGB standard, so in order for them to look correct with assumed_gamma
1, they must be decoded to a linear format.  This is what the sRGB
series of keywords (srgb, srgbf, srgbt, and srgbft) does[1].

In addition, many scene files written prior to POV-Ray 3.7 failed to
specify an assumed_gamma, so the resulting image defaulted to whatever
gamma was used by the computer--usually 2.2, which is similar to sRGB.
When rendered with POV-Ray 3.7, these scenes look pale and washed out.
The quick fix is to specify global_settings { assumed_gamma 2.2 }, but
if you wish to put in the work to make the scene physically realistic,
the new keywords can help.

However, confusion often arises over the use of these keywords.

HOW TO USE THE sRGB KEYWORDS

The first thing to remember is that POV-Ray has *one* and only *one*
color format.  The srgb keyword does not create a different kind of
color than the rgb keyword; it simply interprets its argument
differently.  When you #declare a color, the resulting variable has no
memory of which keyword was used to declare it.

The second thing to remember is that the keywords in the sRGB series
decode from sRGB to linear, not the other way around!

It is also important to remember that the entire expression following
the keyword is evaluated before the conversion is applied; and that the
standard sRGB function is defined for the domain 0...1.

Here is the general sequence for usage of these keywords:

  1. Set global_settings { assumed_gamma 1 } *before* using any of the
     keywords.

  2. An sRGB triplet that comes from a color picker, eyedropper tool,
     or published Web source is typically in the range <0,0,0> ...
     <255,255,255>.  These are byte triplets.  However, POV-Ray does not
     use byte triplets; these must be divided by 255 to bring them into
     the range <0,0,0> ... <1,1,1>.  This *must* be done first thing,
     and is the *only* math that should ever be done at this stage,
     though it may be combined with step 3.  If the color is specified
     in percentages, of course you would divide by 100 instead of 255.

  3. #declare (or #local) the color with the srgb keyword.  The
     resulting identifier contains a linear color.  *If and only if* no
     additional math is required, you may skip the #declare/#local and
     use the srgb directly in a pigment or light_source.

  4. Now, do whatever additional math you need on the identifier.  You
     may do this in a pigment or light_source or wherever.

If your color is from colors.inc, then you *must* skip step 2, because
these colors are already within <0,0,0> ... <1,1,1>.  For these colors,
you should use the srgbft keyword in step 3, because they are already
declared with filter and transmit components.

If your color comes from function eval_pigment(), you must skip steps 2
*and* 3.  Such colors are already within POV-Ray's working space, and
starting with POV-Ray 3.7, this includes image maps.

EXAMPLES

Example 1: the Dutch flag.  Steps 2 & 3 are combined.  Since no
additional math is required on the colors, there is no need to declare
them as identifiers.

  pigment
  { gradient y color_map
    { [1/3 srgb <32, 71, 133> / 255] // Steps 2 & 3
      [1/3 White]
      [2/3 White]
      [2/3 srgb <170, 28, 38> / 255] // Steps 2 & 3
    }
  }

Example 2: an orange light.  Since this example doesn't use a byte
triplet, step 2 is unnecessary.

  #declare C = srgb <1, 0.5, 0>; // This must be declared separately!
                                 // (step 3)
  #declare Ld = 100;
  #declare Fd = 1;
  light_source
  { <100, 50, 0>,
    C * (1 + pow (Ld/Fd, 2)) / 2 // Step 4: math is applied to
                                 // identifier C
    fade_power 2
    fade_distance Fd
  }

EPILOGUE

Linear color applies only to the tracing phase. The output command line
options Display_Gamma and File_Gamma should remain at their default sRGB
setting. The gamma option for image maps should normally be left
unspecified.

RESOURCES

This tutorial, plus discussion links and the scene file for the image,
can be found at: https://github.com/CousinRicky/POV-Gamma-sRGB

---
[1] Technically, these keywords convert an sRGB-specified color to match
whatever assumed_gamma you are using.  Using assumed_gamma 1 means they
will convert to linear.

---
Copyright (C) 2024 Richard Callwood III, CC-BY-SA 4.0.


Post a reply to this message


Attachments:
Download 'gamma-srgb.jpg' (12 KB) Download 'gamma-srgb.pov.zip' (1 KB)

Preview of image 'gamma-srgb.jpg'
gamma-srgb.jpg

From: yesbird
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 19 Apr 2024 08:36:08
Message: <66226538$1@news.povray.org>
On 18/04/2024 23:44, Cousin Ricky wrote:
> THE ISSUE
> 
> What is gamma, why should assumed_gamma be set to 1, and how should we
> use the sRGB keywords introduced with POV-Ray 3.7?

Thanks, Cousin.
This question was always interesting to me - very clean and detailed
explanation.
--
YB


Post a reply to this message

From: kurtz le pirate
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 19 Apr 2024 09:37:57
Message: <662273b5$1@news.povray.org>
On 18/04/2024 22:44, Cousin Ricky wrote:
> THE ISSUE
> 
> ...
> 
> EXAMPLES
> 
> Example 1: the Dutch flag.  Steps 2 & 3 are combined.  Since no
> additional math is required on the colors, there is no need to declare
> them as identifiers.
> 
>   pigment
>   { gradient y color_map
>     { [1/3 srgb <32, 71, 133> / 255] // Steps 2 & 3
>       [1/3 White]
>       [2/3 White]
>       [2/3 srgb <170, 28, 38> / 255] // Steps 2 & 3
>     }
>   }
> 

Red, white and blue... it's more the flag of the Netherlands than of
Germany, isn't it?


Apart from that, a very good and useful explanation.
It's always good to get back to basics.




-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Cousin Ricky
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 19 Apr 2024 10:27:13
Message: <66227f41$1@news.povray.org>
On 2024-04-19 09:37 (-4), kurtz le pirate wrote:
>>
>> Example 1: the Dutch flag.  [snip]
> 
> Red, white and blue... it's more the flag of the Netherlands than of
> Germany, isn't it?

At least in English, "Dutch" means "of the Netherlands."  It does not
mean "Deutsch," although the words have a common etymology.

(To confuse things, there's also Pennsylvania Dutch, which *is* a
dialect of German, but that is another matter.)


Post a reply to this message

From: kurtz le pirate
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 19 Apr 2024 11:48:04
Message: <66229234$1@news.povray.org>
On 19/04/2024 16:27, Cousin Ricky wrote:
> On 2024-04-19 09:37 (-4), kurtz le pirate wrote:
>>>
>>> Example 1: the Dutch flag.  [snip]
>>
>> Red, white and blue... it's more the flag of the Netherlands than of
>> Germany, isn't it?
> 
> At least in English, "Dutch" means "of the Netherlands."  It does not
> mean "Deutsch," although the words have a common etymology.
> 
> (To confuse things, there's also Pennsylvania Dutch, which *is* a
> dialect of German, but that is another matter.)
> 

I read too fast and my English is really bad.
Sorry :(





-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Thomas de Groot
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 20 Apr 2024 02:23:41
Message: <66235f6d$1@news.povray.org>
Op 18/04/2024 om 22:44 schreef Cousin Ricky:
> THE ISSUE
> 
> What is gamma, why should assumed_gamma be set to 1, and how should we
> use the sRGB keywords introduced with POV-Ray 3.7?
> 
> [snip]
> ---
> Copyright (C) 2024 Richard Callwood III, CC-BY-SA 4.0.

Excellent! Thank you very much indeed!

[Real Life: so much to do; so little time... :(  ]

-- 
Thomas


Post a reply to this message

From: jr
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 22 Apr 2024 12:05:00
Message: <web.66268a94b1d4fdc11686e436cde94f1@news.povray.org>
hi,

Cousin Ricky <ric### [at] yahoocom> wrote:
> ...
> The first thing to remember is that POV-Ray has *one* and only *one*
> color format.  The srgb keyword does not create a different kind of
> color than the rgb keyword; it simply interprets its argument
> differently.  ...

(belated) thanks.

so, the "take away" is to not mix RGB types and 's' variants in the same scene ?
 and use RGB types only if values, due to arithmetic, may go "out of range" ?

(a sort of "conclusion" with recommendation would have been ideal)


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 22 Apr 2024 13:20:00
Message: <web.66269bd5b1d4fdc1b959fb4725979125@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> Cousin Ricky <ric### [at] yahoocom> wrote:
> > ...
> > The first thing to remember is that POV-Ray has *one* and only *one*
> > color format.  The srgb keyword does not create a different kind of
> > color than the rgb keyword; it simply interprets its argument
> > differently.  ...
>
> (belated) thanks.
>
> so, the "take away" is to not mix RGB types and 's' variants in the same scene ?
>  and use RGB types only if values, due to arithmetic, may go "out of range" ?
>
> (a sort of "conclusion" with recommendation would have been ideal)
>
>
> regards, jr.

WHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!

'Round and 'round we go, when we'll stop NOBODY KNOWS!!!!!

https://news.povray.org/web.64b18904b039fa5d1f9dae3025979125%40news.povray.org









Can we do gamma again?  Oh please oh please oh please.....     ;)


Post a reply to this message

From: ingo
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 23 Apr 2024 01:25:00
Message: <web.662744bab1d4fdc117bac71e8ffb8ce3@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> Can we do gamma again?  Oh please oh please oh please.....     ;)

Maybe our Cousin can add a simple demo what srgb input results in what rgb being
used?

#version 3.8;
global_settings{ assumed_gamma 1.0 }

#for (i,0,1,0.1)
  #declare c = srgb i;
  #debug concat(str(i,0,2)," : ",vstr(3,c,", ",0,2), "\n")
#end

maybe add splines to it to show the relationship.

or the relation with gamma in photography how exposure time and development time
influence gamma while having the same min and max density as a result. And how
you can play with photographic paper to compensate for gamma errors a bit or use
it for artistic expression, kind of changing assumed_gamma .... sorry, got
carried a way, thoughts of red lights and darkrooms


ingo


Post a reply to this message

From: Thomas de Groot
Subject: Re: Gamma and the sRGB Keywords in POV-Ray 3.7: a Tutorial
Date: 23 Apr 2024 02:19:42
Message: <662752fe$1@news.povray.org>
Op 22/04/2024 om 19:18 schreef Bald Eagle:
> 
> WHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!
> 
> 'Round and 'round we go, when we'll stop NOBODY KNOWS!!!!!
> 
> https://news.povray.org/web.64b18904b039fa5d1f9dae3025979125%40news.povray.org
> 
> 
> 
> Can we do gamma again?  Oh please oh please oh please.....     ;)
> 

<large grin>

I imagine that hell is paved with white hot gamma, rgb, and srgb slabs....

-- 
Thomas


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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