From 13f00ca79d0dadb47ae8d88498f459d9aef7dd01 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 9 Aug 2016 14:49:03 -0500 Subject: [PATCH] adds toLinear and toGamma helper functions for ColorF, uses the former in adjusting lights. --- Engine/source/core/color.h | 13 +++++++++++++ .../lighting/advanced/advancedLightBinManager.cpp | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Engine/source/core/color.h b/Engine/source/core/color.h index 1fa5d7676..aaf4f16e7 100644 --- a/Engine/source/core/color.h +++ b/Engine/source/core/color.h @@ -104,6 +104,9 @@ class ColorF (alpha >= 0.0f && alpha <= 1.0f); } void clamp(); + ColorF toLinear() const; + ColorF toGamma() const; + static const ColorF ZERO; static const ColorF ONE; static const ColorF WHITE; @@ -462,6 +465,16 @@ inline void ColorF::clamp() alpha = 0.0f; } +inline ColorF ColorF::toLinear() const +{ + return ColorF(mPow(red, 2.2f), mPow(green, 2.2f), mPow(blue, 2.2f), alpha); +} + +inline ColorF ColorF::toGamma() const +{ + return ColorF(mPow(red, 1.0f / 2.2f), mPow(green, 1.0f / 2.2f), mPow(blue, 1.0f / 2.2f), alpha); +} + //------------------------------------------------------------------------------ //-------------------------------------- INLINES (ColorI) // diff --git a/Engine/source/lighting/advanced/advancedLightBinManager.cpp b/Engine/source/lighting/advanced/advancedLightBinManager.cpp index bec9afb8a..5e7259b3a 100644 --- a/Engine/source/lighting/advanced/advancedLightBinManager.cpp +++ b/Engine/source/lighting/advanced/advancedLightBinManager.cpp @@ -681,7 +681,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light F32 lumiance = mDot(*((const Point3F *)&lightInfo->getColor()), colorToLumiance ); col.alpha *= lumiance; - matParams->setSafe( lightColor, col ); + matParams->setSafe( lightColor, col.toLinear() ); matParams->setSafe( lightBrightness, lightInfo->getBrightness() ); switch( lightInfo->getType() ) @@ -697,7 +697,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light // the vector light. This prevents a divide by zero. ColorF ambientColor = renderState->getAmbientLightColor(); ambientColor.alpha = 0.00001f; - matParams->setSafe( lightAmbient, ambientColor ); + matParams->setSafe( lightAmbient, ambientColor.toLinear() ); // If no alt color is specified, set it to the average of // the ambient and main color to avoid artifacts. @@ -711,7 +711,7 @@ void AdvancedLightBinManager::LightMaterialInfo::setLightParameters( const Light lightAlt = (lightInfo->getColor() + renderState->getAmbientLightColor()) / 2.0f; ColorF trilightColor = lightAlt; - matParams->setSafe(lightTrilight, trilightColor); + matParams->setSafe(lightTrilight, trilightColor.toLinear()); } break;