Skip to content

Commit e4886e6

Browse files
JriusHoikas
authored andcommitted
Convert RT light color to sRGB
1 parent 57d10db commit e4886e6

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

korman/exporter/animation.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ def _convert_lamp_color_animation(self, name, fcurves, lamp, start, end):
164164
self._exporter().report.warn("Cannot animate Lamp color because neither Diffuse nor Specular are enabled")
165165
return None
166166

167-
# OK Specular is easy. We just toss out the color as a point3.
167+
# Specular must be converted to sRGB space (gamma correction).
168168
def convert_specular_animation(color):
169169
if lamp.use_negative:
170-
return map(lambda x: x * -1.0, color)
170+
return map(lambda x: -pow(x, 1 / 2.2), color)
171171
else:
172-
return color
172+
return map(lambda x: pow(x, 1 / 2.2), color)
173173
color_keyframes, color_bez = self._process_keyframes(color_curves, 3, lamp.color,
174174
convert=convert_specular_animation,
175175
start=start, end=end)
@@ -183,10 +183,11 @@ def convert_specular_animation(color):
183183

184184
# Hey, look, it's a third way to process FCurves. YAY!
185185
def convert_diffuse_animation(color, energy):
186+
# Remember to convert the color to sRGB.
186187
if lamp.use_negative:
187-
proc = lambda x: x * -1.0 * energy[0]
188+
proc = lambda x: -pow(x * energy[0], 1 / 2.2)
188189
else:
189-
proc = lambda x: x * energy[0]
190+
proc = lambda x: pow(x * energy[0], 1 / 2.2)
190191
return map(proc, color)
191192
diffuse_channels = dict(color=3, energy=1)
192193
diffuse_defaults = dict(color=lamp.color, energy=lamp.energy)

korman/exporter/rtlight.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ def export_rtlight(self, so, bo):
122122

123123
# Light color nonsense
124124
# Please note that these calculations are duplicated in the AnimationConverter
125+
# Also, Blender lighting is done in linear space, whereas Plasma still uses gamma space, so convert the color to sRGB.
125126
energy = bl_light.energy
126127
if bl_light.use_negative:
127-
diff_color = [(0.0 - i) * energy for i in bl_light.color]
128-
spec_color = [(0.0 - i) for i in bl_light.color]
128+
diff_color = [(0.0 - pow(i * energy, 1 / 2.2)) for i in bl_light.color]
129+
spec_color = [(0.0 - pow(i, 1 / 2.2)) for i in bl_light.color]
129130
else:
130-
diff_color = [i * energy for i in bl_light.color]
131-
spec_color = [i for i in bl_light.color]
131+
diff_color = [pow(i * energy, 1 / 2.2) for i in bl_light.color]
132+
spec_color = [pow(i, 1 / 2.2) for i in bl_light.color]
132133

133134
diff_str = "({:.4f}, {:.4f}, {:.4f})".format(*diff_color)
134135
diff_color.append(energy)

0 commit comments

Comments
 (0)