Blender V5.0
draw_color_management.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "GPU_viewport.hh"
10
11#include "BLI_string_utf8.h"
12
13#include "DRW_render.hh"
14
15#include "DNA_space_types.h"
16#include "DNA_view3d_types.h"
17
18#include "BKE_colortools.hh"
19#include "BKE_image.hh"
20#include "BKE_scene.hh"
21
23
24#include "ED_node_c.hh"
25
27
29
35
36static float dither_get(eDRWColorManagementType color_management_type, const Scene &scene)
37{
38 if (ELEM(color_management_type,
41 {
42 return scene.r.dither_intensity;
43 }
44 return 0.0f;
45}
46
48 const View3D &v3d)
49{
50
51 const bool use_workbench = BKE_scene_uses_blender_workbench(&scene);
52 const bool use_scene_lights = V3D_USES_SCENE_LIGHTS(&v3d);
53 const bool use_scene_world = V3D_USES_SCENE_WORLD(&v3d);
54
55 if ((use_workbench && v3d.shading.type == OB_RENDER) || use_scene_lights || use_scene_world) {
57 }
58 if (v3d.shading.type >= OB_MATERIAL) {
60 }
62}
63
65{
66 const Image *image = sima.image;
67
68 /* Use inverse logic as there isn't a setting for `Color & Alpha`. */
69 const eSpaceImage_Flag display_channels_mode = static_cast<eSpaceImage_Flag>(sima.flag);
70 const bool display_color_channel = (display_channels_mode & (SI_SHOW_ALPHA | SI_SHOW_ZBUF)) == 0;
71
72 if (display_color_channel && image && (image->source != IMA_SRC_GENERATED) &&
73 ((image->flag & IMA_VIEW_AS_RENDER) != 0))
74 {
76 }
78}
79
81 const SpaceNode &snode)
82{
83 if ((snode.flag & SNODE_BACKDRAW) && ED_node_is_compositor(&snode)) {
84 const Image *image = BKE_image_ensure_viewer(&bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
85 if ((image->flag & IMA_VIEW_AS_RENDER) == 0) {
87 }
88 }
89
90 const eSpaceNode_Flag display_channels_mode = static_cast<eSpaceNode_Flag>(snode.flag);
91 const bool display_color_channel = (display_channels_mode & SNODE_SHOW_ALPHA) == 0;
92 if (display_color_channel) {
94 }
96}
97
99 const Scene &scene,
100 const View3D *v3d,
101 const SpaceLink *space_data)
102{
103 if (v3d) {
104 return drw_color_management_type_for_v3d(scene, *v3d);
105 }
106 if (space_data) {
107 switch (space_data->spacetype) {
108 case SPACE_IMAGE: {
109 const SpaceImage *sima = reinterpret_cast<const SpaceImage *>(space_data);
111 }
112 case SPACE_NODE: {
113 const SpaceNode *snode = reinterpret_cast<const SpaceNode *>(space_data);
114 return drw_color_management_type_for_space_node(*bmain, *snode);
115 }
116 }
117 }
119}
120
122 const Scene &scene,
123 const eDRWColorManagementType color_management_type)
124{
125 const ColorManagedDisplaySettings *display_settings = &scene.display_settings;
126 ColorManagedViewSettings view_settings;
127
128 switch (color_management_type) {
130 /* For workbench use only default view transform in configuration,
131 * using no scene settings. */
132 BKE_color_managed_view_settings_init(&view_settings, display_settings, nullptr);
133 break;
134 }
136 /* Use only view transform + look and nothing else for lookdev without
137 * scene lighting, as exposure depends on scene light intensity. */
138 BKE_color_managed_view_settings_init(&view_settings, display_settings, nullptr);
140 STRNCPY_UTF8(view_settings.look, scene.view_settings.look);
141 break;
142 }
144 /* Use full render settings, for renders with scene lighting. */
145 view_settings = scene.view_settings;
146 break;
147 }
148 }
149
150 const float dither = dither_get(color_management_type, scene);
151 GPU_viewport_colorspace_set(&viewport, &view_settings, display_settings, dither);
152}
153
155{
156 const Depsgraph *depsgraph = draw_ctx.depsgraph;
157 Main *bmain = DEG_get_bmain(depsgraph);
158
159 const eDRWColorManagementType color_management_type = drw_color_management_type_get(
160 bmain, *draw_ctx.scene, draw_ctx.v3d, draw_ctx.space_data);
161 viewport_settings_apply(viewport, *draw_ctx.scene, color_management_type);
162}
163
164} // namespace blender::draw::color_management
void BKE_color_managed_view_settings_init(ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, const char *view_transform)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:2829
#define STRNCPY_UTF8(dst, src)
#define ELEM(...)
Main * DEG_get_bmain(const Depsgraph *graph)
@ IMA_SRC_GENERATED
@ IMA_VIEW_AS_RENDER
@ IMA_TYPE_COMPOSITE
@ OB_RENDER
@ OB_MATERIAL
eSpaceImage_Flag
@ SI_SHOW_ZBUF
@ SI_SHOW_ALPHA
eSpaceNode_Flag
@ SNODE_BACKDRAW
@ SNODE_SHOW_ALPHA
@ SPACE_NODE
@ SPACE_IMAGE
#define V3D_USES_SCENE_WORLD(v3d)
#define V3D_USES_SCENE_LIGHTS(v3d)
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:487
void GPU_viewport_colorspace_set(GPUViewport *viewport, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float dither)
BPy_StructRNA * depsgraph
static eDRWColorManagementType drw_color_management_type_for_v3d(const Scene &scene, const View3D &v3d)
static eDRWColorManagementType drw_color_management_type_for_space_node(Main &bmain, const SpaceNode &snode)
static float dither_get(eDRWColorManagementType color_management_type, const Scene &scene)
void viewport_color_management_set(GPUViewport &viewport, DRWContext &draw_ctx)
static void viewport_settings_apply(GPUViewport &viewport, const Scene &scene, const eDRWColorManagementType color_management_type)
static eDRWColorManagementType drw_color_management_type_get(Main *bmain, const Scene &scene, const View3D *v3d, const SpaceLink *space_data)
static eDRWColorManagementType drw_color_management_type_for_space_image(const SpaceImage &sima)
View3D * v3d
Depsgraph * depsgraph
Scene * scene
SpaceLink * space_data
float dither_intensity
ColorManagedViewSettings view_settings
struct RenderData r
ColorManagedDisplaySettings display_settings
struct Image * image
View3DShading shading