Blender  V3.3
draw_color_management.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. */
3 
8 #include "draw_manager.h"
9 
10 #include "DRW_render.h"
11 
12 #include "GPU_batch.h"
13 #include "GPU_framebuffer.h"
14 #include "GPU_matrix.h"
15 #include "GPU_texture.h"
16 
17 #include "DNA_space_types.h"
18 #include "DNA_view3d_types.h"
19 
20 #include "BKE_colortools.h"
21 
22 #include "IMB_colormanagement.h"
23 
24 #include "draw_color_management.h"
25 
27 
29  ViewTransform = 0,
32 };
33 
34 static float dither_get(eDRWColorManagementType color_management_type, const Scene &scene)
35 {
36  if (ELEM(color_management_type,
39  return scene.r.dither_intensity;
40  }
41  return 0.0f;
42 }
43 
45  const View3D &v3d)
46 {
47 
48  const bool use_workbench = BKE_scene_uses_blender_workbench(&scene);
49  const bool use_scene_lights = V3D_USES_SCENE_LIGHTS(&v3d);
50  const bool use_scene_world = V3D_USES_SCENE_WORLD(&v3d);
51 
52  if ((use_workbench && v3d.shading.type == OB_RENDER) || use_scene_lights || use_scene_world) {
54  }
55  if (v3d.shading.type >= OB_MATERIAL) {
57  }
59 }
60 
62 {
63  Image *image = sima.image;
64 
65  /* Use inverse logic as there isn't a setting for `Color And Alpha`. */
66  const eSpaceImage_Flag display_channels_mode = static_cast<eSpaceImage_Flag>(sima.flag);
67  const bool display_color_channel = (display_channels_mode & (SI_SHOW_ALPHA | SI_SHOW_ZBUF)) == 0;
68 
69  if (display_color_channel && image && (image->source != IMA_SRC_GENERATED) &&
70  ((image->flag & IMA_VIEW_AS_RENDER) != 0)) {
72  }
74 }
75 
77 {
78  const eSpaceNode_Flag display_channels_mode = static_cast<eSpaceNode_Flag>(snode.flag);
79  const bool display_color_channel = (display_channels_mode & SNODE_SHOW_ALPHA) == 0;
80  if (display_color_channel) {
82  }
84 }
85 
87  const View3D *v3d,
88  const SpaceLink *space_data)
89 {
90  if (v3d) {
92  }
93  if (space_data) {
94  switch (space_data->spacetype) {
95  case SPACE_IMAGE: {
96  const SpaceImage *sima = static_cast<const SpaceImage *>(
97  static_cast<const void *>(space_data));
99  }
100  case SPACE_NODE: {
101  const SpaceNode *snode = static_cast<const SpaceNode *>(
102  static_cast<const void *>(space_data));
104  }
105  }
106  }
108 }
109 
110 static void viewport_settings_apply(GPUViewport &viewport,
111  const Scene &scene,
112  const eDRWColorManagementType color_management_type)
113 {
114  const ColorManagedDisplaySettings *display_settings = &scene.display_settings;
115  ColorManagedViewSettings view_settings;
116 
117  switch (color_management_type) {
119  /* For workbench use only default view transform in configuration,
120  * using no scene settings. */
121  BKE_color_managed_view_settings_init_render(&view_settings, display_settings, nullptr);
122  break;
123  }
125  /* Use only view transform + look and nothing else for lookdev without
126  * scene lighting, as exposure depends on scene light intensity. */
127  BKE_color_managed_view_settings_init_render(&view_settings, display_settings, nullptr);
129  STRNCPY(view_settings.look, scene.view_settings.look);
130  break;
131  }
133  /* Use full render settings, for renders with scene lighting. */
134  view_settings = scene.view_settings;
135  break;
136  }
137  }
138 
139  const float dither = dither_get(color_management_type, scene);
140  GPU_viewport_colorspace_set(&viewport, &view_settings, display_settings, dither);
141 }
142 
144 {
145  const DRWContextState *draw_ctx = DRW_context_state_get();
146 
147  const eDRWColorManagementType color_management_type = drw_color_management_type_get(
148  *draw_ctx->scene, draw_ctx->v3d, draw_ctx->space_data);
149  viewport_settings_apply(viewport, *draw_ctx->scene, color_management_type);
150 }
151 
152 } // namespace blender::draw::color_management
153 
154 /* -------------------------------------------------------------------- */
159 {
161 }
162 
164 {
166 
169 
170  /* Draw as texture for final render (without immediate mode). */
173  GPU_batch_uniform_4f(geom, "color", 1.0f, 1.0f, 1.0f, 1.0f);
174  GPU_batch_texture_bind(geom, "image", tex);
175 
176  GPU_batch_draw(geom);
177 
179 }
180 
void BKE_color_managed_view_settings_init_render(struct ColorManagedViewSettings *settings, const struct ColorManagedDisplaySettings *display_settings, const char *view_transform)
bool BKE_scene_uses_blender_workbench(const struct Scene *scene)
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
#define ELEM(...)
@ IMA_VIEW_AS_RENDER
@ IMA_SRC_GENERATED
@ OB_RENDER
@ OB_MATERIAL
eSpaceImage_Flag
@ SI_SHOW_ZBUF
@ SI_SHOW_ALPHA
eSpaceNode_Flag
@ SNODE_SHOW_ALPHA
@ SPACE_NODE
@ SPACE_IMAGE
#define V3D_USES_SCENE_WORLD(v3d)
#define V3D_USES_SCENE_LIGHTS(v3d)
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
GPUBatch
Definition: GPU_batch.h:78
#define GPU_batch_texture_bind(batch, name, tex)
Definition: GPU_batch.h:161
void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id)
Definition: gpu_batch.cc:287
void GPU_batch_draw(GPUBatch *batch)
Definition: gpu_batch.cc:223
#define GPU_batch_uniform_4f(batch, name, x, y, z, w)
Definition: GPU_batch.h:148
void GPU_matrix_identity_projection_set(void)
Definition: gpu_matrix.cc:154
void GPU_matrix_identity_set(void)
Definition: gpu_matrix.cc:168
@ GPU_SHADER_2D_IMAGE_COLOR
Definition: GPU_shader.h:217
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
void GPU_texture_unbind(GPUTexture *tex)
Definition: gpu_texture.cc:472
void GPU_viewport_colorspace_set(GPUViewport *viewport, ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings, float dither)
Definition: gpu_viewport.c:213
Scene scene
GPUBatch * DRW_cache_fullscreen_quad_get(void)
Definition: draw_cache.c:356
void DRW_viewport_colormanagement_set(GPUViewport *viewport)
void DRW_transform_none(GPUTexture *tex)
const DRWContextState * DRW_context_state_get(void)
void drw_state_set(DRWState state)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
static eDRWColorManagementType drw_color_management_type_for_v3d(const Scene &scene, const View3D &v3d)
static void viewport_color_management_set(GPUViewport &viewport)
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(const Scene &scene, const View3D *v3d, const SpaceLink *space_data)
static eDRWColorManagementType drw_color_management_type_for_space_node(const SpaceNode &snode)
static eDRWColorManagementType drw_color_management_type_for_space_image(const SpaceImage &sima)
struct Scene * scene
Definition: DRW_render.h:979
struct SpaceLink * space_data
Definition: DRW_render.h:977
struct View3D * v3d
Definition: DRW_render.h:976
float dither_intensity
ColorManagedViewSettings view_settings
struct RenderData r
ColorManagedDisplaySettings display_settings
struct Image * image
View3DShading shading