Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Color saturation in GLSL

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 Synthetix   Members   

192
Like
0Likes
Like

Posted 05 July 2013 - 09:12 AM

I need a way to saturate (not desaturate) colors in a GLSL shader. There's code all over the place for desaturating an image. Example:

vec3 desaturate(vec3 color, float amount)
{
    vec3 gray = vec3(dot(vec3(0.2126,0.7152,0.0722), color));
    return vec3(mix(color, gray, amount));
}

Many suggest converting RGB to HSV space before increasing saturation. However, I don't need to change hue, only saturation. If I pass negative values to the above function, it indeed appears to saturate the image. Is there anything technically wrong about doing it this way? Am I trying to take a dangerous shortcut here?



#2 apatriarca   Members   

2354
Like
0Likes
Like

Posted 05 July 2013 - 01:47 PM

That code first computes a "grayscale color" from the input color (using the formula for Luma used in hdtv it seems) and then linearly interpolate between the input color and the grayscale color. Using that formula with negative amount you may get some component of the color greater than one. Depending on your needs you may want to clamp the result.


Edited by apatriarca, 05 July 2013 - 01:49 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.