Add color self-clamp

This commit is contained in:
Jack Andersen 2016-04-03 19:01:27 -10:00
parent 1f7088e5eb
commit 9762710b85
1 changed files with 11 additions and 0 deletions

View File

@ -320,6 +320,17 @@ public:
CColor toGrayscale() CColor toGrayscale()
{ return {sqrtF((r * r + g * g + b * b) / 3), a}; } { return {sqrtF((r * r + g * g + b * b) / 3), a}; }
/**
* @brief Clamps to GPU-safe RGBA values [0,1]
*/
void Clamp()
{
this->r = std::min(1.f, std::max(0.f, this->r));
this->g = std::min(1.f, std::max(0.f, this->g));
this->b = std::min(1.f, std::max(0.f, this->b));
this->a = std::min(1.f, std::max(0.f, this->a));
}
}; };
static inline CColor operator+(float lhs, const CColor& rhs) static inline CColor operator+(float lhs, const CColor& rhs)