@@ -600,6 +600,10 @@ inline float toSRGB(float val, float gamma = 2.4f) {
600600 }
601601}
602602
603+ inline nanogui::Vector3f toSRGB (nanogui::Vector3f val, float gamma = 2 .4f ) {
604+ return {toSRGB (val.x (), gamma), toSRGB (val.y (), gamma), toSRGB (val.z (), gamma)};
605+ }
606+
603607inline float toLinear (float val, float gamma = 2 .4f ) {
604608 static constexpr float a = 0 .055f ;
605609 static constexpr float threshold = 0 .04045f ;
@@ -612,6 +616,16 @@ inline float toLinear(float val, float gamma = 2.4f) {
612616 }
613617}
614618
619+ inline nanogui::Vector3f toLinear (nanogui::Vector3f val, float gamma = 2 .4f ) {
620+ return {toLinear (val.x (), gamma), toLinear (val.y (), gamma), toLinear (val.z (), gamma)};
621+ }
622+
623+ inline float applyGamma (float val, float gamma) { return std::copysign (std::pow (std::abs (val), gamma), val); }
624+
625+ inline nanogui::Vector3f applyGamma (nanogui::Vector3f val, float gamma) {
626+ return {applyGamma (val.x (), gamma), applyGamma (val.y (), gamma), applyGamma (val.z (), gamma)};
627+ }
628+
615629int lastError ();
616630int lastSocketError ();
617631std::string errorString (int errorId);
@@ -696,7 +710,7 @@ inline nanogui::Vector3f applyTonemap(nanogui::Vector3f value, float gamma, ETon
696710 nanogui::Vector3f result;
697711 switch (tonemap) {
698712 case ETonemap::Gamma: {
699- result = { std::pow (value. x () , 1 / gamma), std::pow (value. y (), 1 / gamma), std::pow (value. z (), 1 / gamma)} ;
713+ result = applyGamma (value, 1 . 0f / gamma);
700714 break ;
701715 }
702716 case ETonemap::FalseColor: {
0 commit comments