[Cg1] Re: RGB Clamp function

Pascal Grittmann s9pagrit at stud.uni-saarland.de
Sun Oct 30 12:05:17 CET 2016


The sole purpose of the clamp() function is to prepare color values  
for output on a monitor.

The color values stored in the Color class measure the amount of light  
incident on a pixel (or surface point).
Because our system is supposed to be physically correct, there is of  
course no maximum value. In real life, light sources can be  
arbitrarily bright (think of the difference between a lightbulb and  
the sun).
Hence, you definitely do not want to clamp your color values after  
every operation, as that would yield incorrect results.

However, a monitor can only depict colors in the range 0-1, as it does  
have a maximum brightness (determined by the brightness of the  
backlight). Hence, the colors are clamped before outputting them in a  
file (or in your GUI if you do the bonus assignment), and NOWHERE ELSE.

Best,
Pascal

Zitat von Ahmed Abbas <Ahmed.a.mirza at hotmail.com>:

> Assume we have:
>
>
>
>               Resultant color = c1 + c2 – c3;
>
>
>
> Here it can happen that the result of c1 + c2 overflows, however,  
> subtracting c3 brings it back to normal. However, if we use clamp  
> while adding c1 and c2, the original value from which c3 would have  
> been subtracted has been altered and the resultant color would not  
> be the one we wanted. So I think they should be separate, and if we  
> want to validate the resultant color we can probably do something  
> like this:
>
>
>
>               Resultant color = clamp(c1 + c2 – c3);
>
>
>
> Cheers,
>
> Ahmed.
>
>
>
> From: Noshaba Cheema<mailto:s8nochee at stud.uni-saarland.de>
> Sent: Saturday, October 29, 2016 11:03 PM
> To: cg1 at cg.uni-saarland.de<mailto:cg1 at cg.uni-saarland.de>
> Subject: [Cg1] Re: RGB Clamp function
>
>
>
> I am very confused now. So should they be separate now or not?
>
> Quoting Nils Lipp <nlipp at hotmail.de>:
>
>> As I said once (i think it was on another "thread"), I would use it
>> almsot as in the short bit of code presented
>>
>> When I add/subtract 2 colors and go over the boundaries for our RGB
>> values (whatever those are, probably 0-1?),  I can use clamp( ) to
>> either just set values >1 to 1 and values <0 to 0, or scale all
>> values so that they are all in the 0-1 range.
>>
>>
>> ________________________________
>> From: Cg1 <cg1-bounces at cg.uni-saarland.de> on behalf of Arsène
>> Pérard-Gayot <perard at cg.uni-saarland.de>
>> Sent: Saturday, October 29, 2016 8:00 PM
>> To: cg1 at cg.uni-saarland.de
>> Subject: [Cg1] Re: [Assignment 1] implementation of equals/unequals  
>> operation
>>
>> Hello,
>>
>> Just a few remarks. I see that you are sharing code in your mail.
>> Please do not do it beyond a few lines of code (what you copied is
>> fine, for instance).
>>
>> This also means no public repository (on GitHub or GitLab, etc...).
>> Use git only with private repos (you have some for free as a student
>> on GitHub, otherwise use BitBucket).
>>
>> Now, considering your question, think a bit about how the exercises
>> are formulated: We ask you to implement operations like +, -, *,
>> etc... And we ask you to implement *separately* a "clamp" function.
>> Where do you see that we ask you to combine the two?
>>
>> Best regards,
>>    Arsène Pérard-Gayot
>>
>> Noshaba Cheema <s8nochee at stud.uni-saarland.de> a écrit :
>>
>>> Ok, so I guess this also means that we probably shouldn't implement
>>> the RGB operations like this:
>>>
>>> RGBColor operator+(const RGBColor& c) const {
>>>     return RGBColor(r + c.r, g + c.g, b + c.b).clamp();
>>> }
>>>
>>> but rather without the clamp()?
>>>
>>> Quoting Pascal Grittmann <s9pagrit at stud.uni-saarland.de>:
>>>
>>>> Hi,
>>>>
>>>> You should not use any kind of epsilon value here. The == and !=
>>>> operators for vectors are usually only used to detect special cases
>>>> (e.g. the zero vector), hence you only need (and want) exact
>>>> comparisons.
>>>>
>>>> Best,
>>>> Pascal Grittmann
>>>>
>>>> Zitat von Noshaba Cheema <s8nochee at stud.uni-saarland.de>:
>>>>
>>>>> Hello,
>>>>>
>>>>> should we check for the epsilon range in the equals/unequals
>>>>> operations or implement them naively?
>>>>>
>>>>> _______________________________________________
>>>>> Cg1 mailing list
>>>>> Cg1 at cg.uni-saarland.de
>>>>> http://mail.cg.uni-saarland.de/mailman/listinfo/cg1
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Cg1 mailing list
>>>> Cg1 at cg.uni-saarland.de
>>>> http://mail.cg.uni-saarland.de/mailman/listinfo/cg1
>>>
>>>
>>>
>>> _______________________________________________
>>> Cg1 mailing list
>>> Cg1 at cg.uni-saarland.de
>>> http://mail.cg.uni-saarland.de/mailman/listinfo/cg1
>>
>>
>>
>> Best regards,
>>    Arsène Pérard-Gayot
>>
>> _______________________________________________
>> Cg1 mailing list
>> Cg1 at cg.uni-saarland.de
>> http://mail.cg.uni-saarland.de/mailman/listinfo/cg1
>
>
>
> _______________________________________________
> Cg1 mailing list
> Cg1 at cg.uni-saarland.de
> http://mail.cg.uni-saarland.de/mailman/listinfo/cg1





More information about the Cg1 mailing list