From 04e863d170de38db1ebd15dca189a882b3d3af53 Mon Sep 17 00:00:00 2001 From: Jrius <2261279+Jrius@users.noreply.github.com> Date: Sun, 14 Sep 2025 17:07:38 +0200 Subject: [PATCH] Convert RT light color to sRGB --- korman/exporter/animation.py | 11 ++++++----- korman/exporter/rtlight.py | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/korman/exporter/animation.py b/korman/exporter/animation.py index 345ea621..4c67b45f 100644 --- a/korman/exporter/animation.py +++ b/korman/exporter/animation.py @@ -164,12 +164,12 @@ def _convert_lamp_color_animation(self, name, fcurves, lamp, start, end): self._exporter().report.warn("Cannot animate Lamp color because neither Diffuse nor Specular are enabled") return None - # OK Specular is easy. We just toss out the color as a point3. + # Specular must be converted to sRGB space (gamma correction). def convert_specular_animation(color): if lamp.use_negative: - return map(lambda x: x * -1.0, color) + return map(lambda x: -pow(x, 1 / 2.2), color) else: - return color + return map(lambda x: pow(x, 1 / 2.2), color) color_keyframes, color_bez = self._process_keyframes(color_curves, 3, lamp.color, convert=convert_specular_animation, start=start, end=end) @@ -183,10 +183,11 @@ def convert_specular_animation(color): # Hey, look, it's a third way to process FCurves. YAY! def convert_diffuse_animation(color, energy): + # Remember to convert the color to sRGB. if lamp.use_negative: - proc = lambda x: x * -1.0 * energy[0] + proc = lambda x: -pow(x * energy[0], 1 / 2.2) else: - proc = lambda x: x * energy[0] + proc = lambda x: pow(x * energy[0], 1 / 2.2) return map(proc, color) diffuse_channels = dict(color=3, energy=1) diffuse_defaults = dict(color=lamp.color, energy=lamp.energy) diff --git a/korman/exporter/rtlight.py b/korman/exporter/rtlight.py index 4d0a441d..c6e1afda 100644 --- a/korman/exporter/rtlight.py +++ b/korman/exporter/rtlight.py @@ -122,13 +122,14 @@ def export_rtlight(self, so, bo): # Light color nonsense # Please note that these calculations are duplicated in the AnimationConverter + # Also, Blender lighting is done in linear space, whereas Plasma still uses gamma space, so convert the color to sRGB. energy = bl_light.energy if bl_light.use_negative: - diff_color = [(0.0 - i) * energy for i in bl_light.color] - spec_color = [(0.0 - i) for i in bl_light.color] + diff_color = [(0.0 - pow(i * energy, 1 / 2.2)) for i in bl_light.color] + spec_color = [(0.0 - pow(i, 1 / 2.2)) for i in bl_light.color] else: - diff_color = [i * energy for i in bl_light.color] - spec_color = [i for i in bl_light.color] + diff_color = [pow(i * energy, 1 / 2.2) for i in bl_light.color] + spec_color = [pow(i, 1 / 2.2) for i in bl_light.color] diff_str = "({:.4f}, {:.4f}, {:.4f})".format(*diff_color) diff_color.append(energy)