Blender V4.3
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
9#include "draw_manager_c.hh"
10
11#include "DRW_render.hh"
12
13#include "GPU_batch.hh"
14#include "GPU_framebuffer.hh"
15#include "GPU_matrix.hh"
16#include "GPU_texture.hh"
17
18#include "DNA_space_types.h"
19#include "DNA_view3d_types.h"
20
21#include "BKE_colortools.hh"
22#include "BKE_image.hh"
23
25
26#include "ED_node_c.hh"
27
29
31
37
38static float dither_get(eDRWColorManagementType color_management_type, const Scene &scene)
39{
40 if (ELEM(color_management_type,
43 {
44 return scene.r.dither_intensity;
45 }
46 return 0.0f;
47}
48
50 const View3D &v3d)
51{
52
53 const bool use_workbench = BKE_scene_uses_blender_workbench(&scene);
54 const bool use_scene_lights = V3D_USES_SCENE_LIGHTS(&v3d);
55 const bool use_scene_world = V3D_USES_SCENE_WORLD(&v3d);
56
57 if ((use_workbench && v3d.shading.type == OB_RENDER) || use_scene_lights || use_scene_world) {
59 }
60 if (v3d.shading.type >= OB_MATERIAL) {
62 }
64}
65
67{
68 const Image *image = sima.image;
69
70 /* Use inverse logic as there isn't a setting for `Color & Alpha`. */
71 const eSpaceImage_Flag display_channels_mode = static_cast<eSpaceImage_Flag>(sima.flag);
72 const bool display_color_channel = (display_channels_mode & (SI_SHOW_ALPHA | SI_SHOW_ZBUF)) == 0;
73
74 if (display_color_channel && image && (image->source != IMA_SRC_GENERATED) &&
75 ((image->flag & IMA_VIEW_AS_RENDER) != 0))
76 {
78 }
80}
81
83 const SpaceNode &snode)
84{
85 if ((snode.flag & SNODE_BACKDRAW) && ED_node_is_compositor(&snode)) {
86 const Image *image = BKE_image_ensure_viewer(&bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
87 if ((image->flag & IMA_VIEW_AS_RENDER) == 0) {
89 }
90 }
91
92 const eSpaceNode_Flag display_channels_mode = static_cast<eSpaceNode_Flag>(snode.flag);
93 const bool display_color_channel = (display_channels_mode & SNODE_SHOW_ALPHA) == 0;
94 if (display_color_channel) {
96 }
98}
99
101 const Scene &scene,
102 const View3D *v3d,
103 const SpaceLink *space_data)
104{
105 if (v3d) {
106 return drw_color_management_type_for_v3d(scene, *v3d);
107 }
108 if (space_data) {
109 switch (space_data->spacetype) {
110 case SPACE_IMAGE: {
111 const SpaceImage *sima = static_cast<const SpaceImage *>(
112 static_cast<const void *>(space_data));
114 }
115 case SPACE_NODE: {
116 const SpaceNode *snode = static_cast<const SpaceNode *>(
117 static_cast<const void *>(space_data));
118 return drw_color_management_type_for_space_node(*bmain, *snode);
119 }
120 }
121 }
123}
124
126 const Scene &scene,
127 const eDRWColorManagementType color_management_type)
128{
129 const ColorManagedDisplaySettings *display_settings = &scene.display_settings;
130 ColorManagedViewSettings view_settings;
131
132 switch (color_management_type) {
134 /* For workbench use only default view transform in configuration,
135 * using no scene settings. */
136 BKE_color_managed_view_settings_init_render(&view_settings, display_settings, nullptr);
137 break;
138 }
140 /* Use only view transform + look and nothing else for lookdev without
141 * scene lighting, as exposure depends on scene light intensity. */
142 BKE_color_managed_view_settings_init_render(&view_settings, display_settings, nullptr);
143 STRNCPY(view_settings.view_transform, scene.view_settings.view_transform);
144 STRNCPY(view_settings.look, scene.view_settings.look);
145 break;
146 }
148 /* Use full render settings, for renders with scene lighting. */
149 view_settings = scene.view_settings;
150 break;
151 }
152 }
153
154 const float dither = dither_get(color_management_type, scene);
155 GPU_viewport_colorspace_set(&viewport, &view_settings, display_settings, dither);
156}
157
159{
160 const DRWContextState *draw_ctx = DRW_context_state_get();
161 const Depsgraph *depsgraph = draw_ctx->depsgraph;
162 Main *bmain = DEG_get_bmain(depsgraph);
163
164 const eDRWColorManagementType color_management_type = drw_color_management_type_get(
165 bmain, *draw_ctx->scene, draw_ctx->v3d, draw_ctx->space_data);
166 viewport_settings_apply(viewport, *draw_ctx->scene, color_management_type);
167}
168
169} // namespace blender::draw::color_management
170
171/* -------------------------------------------------------------------- */
179
180void DRW_transform_none(GPUTexture *tex)
181{
183
186
187 /* Draw as texture for final render (without immediate mode). */
188 blender::gpu::Batch *geom = DRW_cache_fullscreen_quad_get();
190 GPU_batch_uniform_4f(geom, "color", 1.0f, 1.0f, 1.0f, 1.0f);
191 GPU_batch_texture_bind(geom, "image", tex);
192
193 GPU_batch_draw(geom);
194
196}
197
void BKE_color_managed_view_settings_init_render(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:2777
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define ELEM(...)
Main * DEG_get_bmain(const Depsgraph *graph)
@ IMA_SRC_GENERATED
@ IMA_TYPE_COMPOSITE
@ IMA_VIEW_AS_RENDER
@ 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:523
#define GPU_batch_texture_bind(batch, name, tex)
Definition GPU_batch.hh:316
void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, eGPUBuiltinShader shader_id)
void GPU_batch_draw(blender::gpu::Batch *batch)
#define GPU_batch_uniform_4f(batch, name, x, y, z, w)
Definition GPU_batch.hh:303
void GPU_matrix_identity_projection_set()
void GPU_matrix_identity_set()
@ GPU_SHADER_3D_IMAGE_COLOR
void GPU_texture_unbind(GPUTexture *texture)
void GPU_viewport_colorspace_set(GPUViewport *viewport, ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float dither)
const Depsgraph * depsgraph
blender::gpu::Batch * DRW_cache_fullscreen_quad_get()
void DRW_viewport_colormanagement_set(GPUViewport *viewport)
void DRW_transform_none(GPUTexture *tex)
const DRWContextState * DRW_context_state_get()
void drw_state_set(DRWState state)
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
static eDRWColorManagementType drw_color_management_type_for_v3d(const Scene &scene, const View3D &v3d)
static void viewport_color_management_set(GPUViewport &viewport)
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)
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)
Depsgraph * depsgraph
SpaceLink * space_data
struct Image * image
View3DShading shading