Skip to content

Commit bfe5a25

Browse files
committed
Add a note about sRGB colors on the Tinting and Recoloring page
See #73
1 parent 24c5160 commit bfe5a25

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

programming/render-attributes/tinting-and-recoloring.rst

+35
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,41 @@ medium-blue color. As you can see, the ``setColor`` completely replaces the
112112
vertex colors. The one on the right bas been ``setColorScale`` ed to the same
113113
medium-blue color, but this only tints the model.
114114

115+
A Note about Color Spaces
116+
-------------------------
117+
118+
All colors that Panda3D expects are floating-point values between 0.0 and 1.0.
119+
Panda3D performs no correction or color space conversion before writing them
120+
into the framebuffer. This means that if you are using a linear workflow (ie.
121+
you are have set ``framebuffer-srgb`` in Config.prc or are using a
122+
post-processing filter that converts the rendered image to sRGB), all colors
123+
are specified in "linearized sRGB" instead of gamma-encoded sRGB. Applying a
124+
color obtained from a color picker is no longer as simple as dividing by 255!
125+
126+
An easy way to correct existing colors when switching to a linear workflow is
127+
to apply a 2.2 gamma. This is a good approximation for the sRGB transform
128+
function:
129+
130+
.. code-block:: python
131+
132+
model1.setColor(LColor(0.6, 0.5, 0.3, 1) ** 2.2)
133+
134+
A better method is to use the sRGB conversion functions that Panda3D provides.
135+
For example, to apply the ``#51C2C6`` color, you can do as follows:
136+
137+
.. code-block:: python
138+
139+
from panda3d.core import decode_sRGB_float
140+
141+
model1.setColor(
142+
decode_sRGB_float(0x51),
143+
decode_sRGB_float(0xC2),
144+
decode_sRGB_float(0xC6),
145+
)
146+
147+
If you are not using a linear workflow, or don't know what that is, you don't
148+
need to worry about this for now.
149+
115150
Related Classes
116151
---------------
117152

0 commit comments

Comments
 (0)