Skip to content

Commit 5fab87d

Browse files
committed
Redo "colors looking different" bit on Blender page
I think it's now clearer what's going on and what can be done about it
1 parent 8c419d0 commit 5fab87d

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

pipeline/converting-from-blender.rst

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,55 @@ Why do my colors look different in Panda3D?
127127
-------------------------------------------
128128

129129
It is important to note that Blender uses a linear workflow, meaning all colors
130-
are converted from the sRGB color encoding to the "linearized sRGB" color space
131-
before being used for lighting and blending. After the render process, the
132-
colors in the framebuffer are converted back to sRGB for display on the screen.
133-
134-
Panda3D by default does not perform any color conversion, meaning that all the
135-
input colors are rendered as-is into the window. However, this can mean that
136-
colors defined in Blender will not appear the same way in Panda3D, as they have
137-
not undergone the same color conversion as Blender performs.
138-
139-
If you use blend2bam in conjunction with the panda3d-simplepbr package, this
140-
will be handled for you automatically. Otherwise, you will need to configure
141-
Panda3D to also use the linear workflow. This requires two steps:
142-
143-
#. Set your textures to use the ``Texture.F_srgb`` or ``Texture.F_srgb_alpha``
144-
texture format, which automatically linearizes the colors before they are
145-
used in the rendering process. This should only be done on color textures,
146-
not on other types of texture maps.
147-
#. Tell Panda3D to ask the graphics driver for an "sRGB framebuffer", which
148-
causes the GPU to automatically convert colors back to sRGB before they are
149-
displayed on the monitor. This is achieved by enabling ``framebuffer-srgb``
150-
in Config.prc, or by adding a post-processing filter as described in
151-
:ref:`common-image-filters`.
130+
sampled from textures are converted from the sRGB gamma encoding to the
131+
"linearized sRGB" color space before being used for lighting and blending.
132+
After the render process, the colors in the framebuffer are converted back to
133+
gamma-encoded sRGB for display on the screen. This results in more natural
134+
lighting and blending, because these calculations happen in a linear domain.
135+
For more reading about this topic, see
136+
`this article from "GPU Gems" <https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear>`__.
137+
138+
By default, blend2bam and panda3d-gltf enable the gamma-correction feature on
139+
textures by setting their format to :cpp:enum:`Texture::F_srgb` or
140+
:cpp:enum:`Texture::F_srgb_alpha`, but the second step of converting the colors
141+
back to sRGB at the end of the rendering process needs to be explicitly enabled
142+
in the application. If this is not done, the texture colors will look incorrect.
143+
144+
If you use the panda3d-simplepbr package, this step is enabled automatically.
145+
Otherwise, you will need to configure Panda3D to enable sRGB gamma correction.
146+
This can be done by asking the graphics driver for an "sRGB framebuffer", which
147+
causes the GPU to automatically convert colors back to sRGB before they are
148+
displayed on the monitor. This is achieved by enabling ``framebuffer-srgb true``
149+
in Config.prc, or by adding a post-processing filter as described in
150+
:ref:`common-image-filters`.
151+
152+
If you do not want to use the linearized workflow, despite its benefits, you can
153+
tell blend2bam not to mark the textures as being sRGB-encoded, meaning that they
154+
are read without gamma correction. To do this, use the ``--no-srgb`` flag.
155+
156+
If you do wish to use the linearized workflow, but have other models or textures
157+
that you wish to integrate into the same application, it is important to set
158+
their texture to use the sRGB format as well so that they do not appear too
159+
bright. This can be done with the following code:
160+
161+
.. only:: python
162+
163+
.. code-block:: python
164+
165+
for tex in model.find_all_textures():
166+
if tex.num_components == 4:
167+
tex.set_format(Texture.F_srgb_alpha)
168+
else:
169+
tex.set_format(Texture.F_srgb)
170+
171+
.. only:: cpp
172+
173+
.. code-block:: cpp
174+
175+
for (Texture *tex : model.find_all_textures()) {
176+
if (Texture::has_alpha(tex->get_format())) {
177+
tex->set_format(Texture::F_srgb_alpha);
178+
} else {
179+
tex->set_format(Texture::F_srgb);
180+
}
181+
}

0 commit comments

Comments
 (0)