Blender V5.3
eevee_lookdev.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "BLI_rect.hh"
11
12#include "BKE_image.hh"
13#include "BKE_image_gpu.hh"
14#include "BKE_lib_id.hh"
15#include "BKE_node.hh"
18#include "BKE_studiolight.h"
19
20#include "NOD_shader.h"
21
23
24#include "GPU_material.hh"
25#include "GPU_texture.hh"
26
27#include "draw_cache.hh"
28#include "draw_view_data.hh"
29
30#include "eevee_instance.hh"
31
32namespace blender::eevee {
33
34/* -------------------------------------------------------------------- */
37
39{
40 /* Create a dummy World data block to hold the nodetree generated for studio-lights. */
41 world = BKE_id_new_nomain<blender::World>("Lookdev");
42
43 using namespace bke;
44
45 bNodeTree &ntree = *world->nodetree;
46 /* Note: We can rename directly safely because #world is not part of any bmain. */
47 BLI_strncpy(ntree.id.name + 2, "Lookdev World Nodetree", MAX_NAME - 2);
48
49 bNode &coordinate = *node_add_static_node(nullptr, ntree, SH_NODE_TEX_COORD);
50 bNodeSocket &generated_sock = *node_find_socket(coordinate, SOCK_OUT, "Generated"_ustr);
51
53 bNodeSocket &transform_in = *node_find_socket(transform, SOCK_IN, "Vector"_ustr);
54 bNodeSocket &transform_out = *node_find_socket(transform, SOCK_OUT, "Vector"_ustr);
55 NodeShaderVectTransform &nodeprop = *static_cast<NodeShaderVectTransform *>(transform.storage);
57 xform_socket_ = &nodeprop.convert_to;
58
59 node_add_link(ntree, coordinate, generated_sock, transform, transform_in);
60
61 /* Flip Y axis because of compatibility axis flipping inside the vector transform node. */
62 bNode &flip_y_mul = *node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_MATH);
64 auto &flip_y_value_out = *node_find_socket(flip_y_mul, SOCK_OUT, "Vector"_ustr);
65 auto &flip_y_value_in0 = *static_cast<bNodeSocket *>(BLI_findlink(&flip_y_mul.inputs, 0));
66 auto &flip_y_value_in1 = *static_cast<bNodeSocket *>(BLI_findlink(&flip_y_mul.inputs, 1));
67 flip_y_socket_ = static_cast<bNodeSocketValueVector *>(flip_y_value_in1.default_value);
68 flip_y_socket_->value[0] = 1.0f;
69 flip_y_socket_->value[1] = 1.0f;
70 flip_y_socket_->value[2] = 1.0f;
71
72 node_add_link(ntree, transform, transform_out, flip_y_mul, flip_y_value_in0);
73
74 bNode &rotate_x = *node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_ROTATE);
76 auto &rotate_x_vector_in = *node_find_socket(rotate_x, SOCK_IN, "Vector"_ustr);
77 auto &rotate_x_vector_angle = *node_find_socket(rotate_x, SOCK_IN, "Angle"_ustr);
78 auto &rotate_x_out = *node_find_socket(rotate_x, SOCK_OUT, "Vector"_ustr);
79 rotation_x_socket_ =
80 &static_cast<bNodeSocketValueFloat *>(rotate_x_vector_angle.default_value)->value;
81
82 node_add_link(ntree, flip_y_mul, flip_y_value_out, rotate_x, rotate_x_vector_in);
83
84 bNode &rotate_z = *node_add_static_node(nullptr, ntree, SH_NODE_VECTOR_ROTATE);
86 auto &rotate_z_vector_in = *node_find_socket(rotate_z, SOCK_IN, "Vector"_ustr);
87 auto &rotate_z_vector_angle = *node_find_socket(rotate_z, SOCK_IN, "Angle"_ustr);
88 auto &rotate_z_out = *node_find_socket(rotate_z, SOCK_OUT, "Vector"_ustr);
89 angle_socket_ = static_cast<bNodeSocketValueFloat *>(rotate_z_vector_angle.default_value);
90
91 node_add_link(ntree, rotate_x, rotate_x_out, rotate_z, rotate_z_vector_in);
92
93 /* Discard the previous processing if we are rendering light probes. */
94
95 bNode &light_path = *node_add_static_node(nullptr, ntree, SH_NODE_LIGHT_PATH);
96 bNodeSocket &is_camera_out = *node_find_socket(light_path, SOCK_OUT, "Is Camera Ray"_ustr);
97
98 bNode &path_mix = *node_add_static_node(nullptr, ntree, SH_NODE_MIX);
99 NodeShaderMix &path_mix_data = *static_cast<NodeShaderMix *>(path_mix.storage);
100 path_mix_data.data_type = SOCK_VECTOR;
101 path_mix_data.factor_mode = NODE_MIX_MODE_UNIFORM;
102 path_mix_data.clamp_factor = false;
103 auto &path_mix_out = *node_find_socket(path_mix, SOCK_OUT, "Result_Vector"_ustr);
104 auto &path_mix_fac = *static_cast<bNodeSocket *>(BLI_findlink(&path_mix.inputs, 0));
105 auto &path_mix_in0 = *static_cast<bNodeSocket *>(BLI_findlink(&path_mix.inputs, 4));
106 auto &path_mix_in1 = *static_cast<bNodeSocket *>(BLI_findlink(&path_mix.inputs, 5));
107
108 node_add_link(ntree, light_path, is_camera_out, path_mix, path_mix_fac);
109 node_add_link(ntree, coordinate, generated_sock, path_mix, path_mix_in0);
110 node_add_link(ntree, rotate_z, rotate_z_out, path_mix, path_mix_in1);
111
112 bNode &environment = *node_add_static_node(nullptr, ntree, SH_NODE_TEX_ENVIRONMENT);
113 environment_node_ = &environment;
114 NodeTexImage *environment_storage = static_cast<NodeTexImage *>(environment.storage);
115 auto &environment_vector_in = *node_find_socket(environment, SOCK_IN, "Vector"_ustr);
116 auto &environment_out = *node_find_socket(environment, SOCK_OUT, "Color"_ustr);
117
118 node_add_link(ntree, path_mix, path_mix_out, environment, environment_vector_in);
119
120 bNode &background = *node_add_static_node(nullptr, ntree, SH_NODE_BACKGROUND);
121 auto &background_out = *node_find_socket(background, SOCK_OUT, "Background"_ustr);
122 auto &background_color_in = *node_find_socket(background, SOCK_IN, "Color"_ustr);
123 intensity_socket_ = static_cast<bNodeSocketValueFloat *>(
124 node_find_socket(background, SOCK_IN, "Strength"_ustr)->default_value);
125
126 node_add_link(ntree, environment, environment_out, background, background_color_in);
127
129 auto &output_in = *node_find_socket(output, SOCK_IN, "Surface"_ustr);
130
131 node_add_link(ntree, background, background_out, output, output_in);
132 node_set_active(ntree, output);
134
135 /* Create a dummy image data block to hold GPU textures generated by studio-lights. */
136 image = BKE_id_new_nomain<blender::Image>("Lookdev");
137 image->type = IMA_TYPE_IMAGE;
138 image->source = IMA_SRC_GENERATED;
139 ImageTile *base_tile = BKE_image_get_tile(image, 0);
140 base_tile->gen_x = 1;
141 base_tile->gen_y = 1;
142 base_tile->gen_type = IMA_GENTYPE_BLANK;
143 copy_v4_fl(base_tile->gen_color, 0.0f);
144 /* TODO: This works around the issue that the first time the texture is accessed the image would
145 * overwrite the set GPU texture. A better solution would be to use image data-blocks as part of
146 * the studio-lights, but that requires a larger refactoring. */
147 if (gpu::Texture *tex = BKE_image_acquire_gpu_texture(image, &environment_storage->iuser)) {
148 GPU_texture_free(tex);
149 }
150}
151
153{
154 BKE_id_free(nullptr, &image->id);
155 BKE_id_free(nullptr, &world->id);
156}
157
158bool LookdevWorld::sync(const LookdevParameters &new_parameters)
159{
160 const bool parameters_changed = assign_if_different(parameters_, new_parameters);
161
162 if (parameters_changed) {
163 intensity_socket_->value = parameters_.intensity;
164
165 BKE_image_assign_gpu_texture(image, nullptr);
166 environment_node_->id = nullptr;
167
168 StudioLight *sl = BKE_studiolight_find(parameters_.hdri.c_str(),
170 if (sl) {
173 if (texture != nullptr) {
176 environment_node_->id = &image->id;
177 }
178 }
179
180 if (parameters_.camera_space) {
181 *xform_socket_ = SHD_VECT_TRANSFORM_SPACE_CAMERA;
182 flip_y_socket_->value[0] = 1.0f;
183 flip_y_socket_->value[1] = -1.0f;
184 flip_y_socket_->value[2] = 1.0f;
185 *rotation_x_socket_ = -M_PI / 2.0f;
186 }
187 else {
188 *xform_socket_ = SHD_VECT_TRANSFORM_SPACE_WORLD;
189 flip_y_socket_->value[0] = 1.0f;
190 flip_y_socket_->value[1] = 1.0f;
191 flip_y_socket_->value[2] = 1.0f;
192 *rotation_x_socket_ = 0.0f;
193 }
194 }
195
196 /* This isn't part of the main update check to avoid updating the probe capture.
197 * This should only update the Nodetree UBO. */
198 const bool rotation_changed = assign_if_different(angle_socket_->value, new_parameters.rot_z);
199
200 if (rotation_changed || parameters_changed) {
201 /* Propagate changes to nodetree. */
202 GPU_material_free(&world->gpumaterial);
203 }
204 return parameters_changed;
205}
206
208
209/* -------------------------------------------------------------------- */
213
215
217{
218 for (gpu::Batch *batch : sphere_lod_) {
220 }
221}
222
223gpu::Batch *LookdevModule::sphere_get(const SphereLOD level_of_detail)
224{
225 BLI_assert(level_of_detail >= SphereLOD::LOW && level_of_detail < SphereLOD::MAX);
226
227 /* GCC 14.x and newer trigger an array-bounds warning without this. */
228#if (defined(__GNUC__) && (__GNUC__ >= 14) && !defined(__clang__))
229 [[assume((level_of_detail >= 0) && (level_of_detail < SphereLOD::MAX))]];
230#endif
231
232 if (sphere_lod_[level_of_detail] != nullptr) {
233 return sphere_lod_[level_of_detail];
234 }
235
236 int lat_res;
237 int lon_res;
238 switch (level_of_detail) {
239 case 2:
240 lat_res = 80;
241 lon_res = 60;
242 break;
243 case 1:
244 lat_res = 64;
245 lon_res = 48;
246 break;
247 default:
248 case 0:
249 lat_res = 32;
250 lon_res = 24;
251 break;
252 }
253
254 GPUVertFormat format = {0};
255 GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
256 GPU_vertformat_attr_add(&format, "nor", gpu::VertAttrType::SFLOAT_32_32_32);
257 struct Vert {
258 float x, y, z;
259 float nor_x, nor_y, nor_z;
260 };
261
262 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
263 int v_len = (lat_res - 1) * lon_res * 6;
264 GPU_vertbuf_data_alloc(*vbo, v_len);
265
266 const float lon_inc = 2 * M_PI / lon_res;
267 const float lat_inc = M_PI / lat_res;
268 float lon, lat;
269
270 int v = 0;
271 lon = 0.0f;
272
273 auto sphere_lat_lon_vert = [&](float lat, float lon) {
274 Vert vert;
275 vert.nor_x = vert.x = sinf(lat) * cosf(lon);
276 vert.nor_y = vert.y = cosf(lat);
277 vert.nor_z = vert.z = sinf(lat) * sinf(lon);
278 GPU_vertbuf_vert_set(vbo, v, &vert);
279 v++;
280 };
281
282 for (int i = 0; i < lon_res; i++, lon += lon_inc) {
283 lat = 0.0f;
284 for (int j = 0; j < lat_res; j++, lat += lat_inc) {
285 if (j != lat_res - 1) { /* Pole */
286 sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
287 sphere_lat_lon_vert(lat + lat_inc, lon);
288 sphere_lat_lon_vert(lat, lon);
289 }
290 if (j != 0) { /* Pole */
291 sphere_lat_lon_vert(lat, lon + lon_inc);
292 sphere_lat_lon_vert(lat + lat_inc, lon + lon_inc);
293 sphere_lat_lon_vert(lat, lon);
294 }
295 }
296 }
297
298 sphere_lod_[level_of_detail] = GPU_batch_create_ex(
299 GPU_PRIM_TRIS, vbo, nullptr, GPU_BATCH_OWNS_VBO);
300 return sphere_lod_[level_of_detail];
301}
302
303void LookdevModule::init(const rcti *visible_rect)
304{
305 visible_rect_ = *visible_rect;
306 is_camera_view_ = inst_.is_viewport() && inst_.rv3d && (inst_.rv3d->persp == RV3D_CAMOB);
307 use_reference_spheres_ = inst_.is_viewport() && inst_.overlays_enabled() &&
308 inst_.use_lookdev_overlay();
309
310 if (use_reference_spheres_) {
311 const int2 extent_dummy(1);
314 dummy_cryptomatte_tx_.ensure_2d(gpu::TextureFormat::SFLOAT_32_32_32_32, extent_dummy, usage);
315 dummy_aov_color_tx_.ensure_2d_array(
316 gpu::TextureFormat::SFLOAT_16_16_16_16, extent_dummy, 1, usage);
317 dummy_aov_value_tx_.ensure_2d_array(gpu::TextureFormat::SFLOAT_16, extent_dummy, 1, usage);
318 }
319
320 if (inst_.is_viewport()) {
321 const blender::View3DShading &shading = inst_.v3d->shading;
322 bool use_viewspace_lighting = (shading.flag & V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION) != 0;
323 if (assign_if_different(use_viewspace_lighting_, use_viewspace_lighting)) {
324 inst_.sampling.reset();
325 }
326 if (assign_if_different(studio_light_rotation_z_, shading.studiolight_rot_z)) {
327 inst_.sampling.reset();
328 }
329 }
330}
331
332float LookdevModule::calc_viewport_scale()
333{
334 const float scale = BLI_rcti_size_x(&visible_rect_) / (2000.0f * UI_SCALE_FAC);
335 const float min_scale = is_camera_view_ ? 0.0f : 0.5f;
336 return clamp_f(scale, min_scale, 1.0f);
337}
338
339LookdevModule::SphereLOD LookdevModule::calc_level_of_detail(const float viewport_scale)
340{
341 float res_scale = clamp_f(
342 (U.lookdev_sphere_size / 400.0f) * viewport_scale * UI_SCALE_FAC, 0.1f, 1.0f);
343
344 if (res_scale > 0.7f) {
345 return LookdevModule::SphereLOD::HIGH;
346 }
347 if (res_scale > 0.25f) {
348 return LookdevModule::SphereLOD::MEDIUM;
349 }
350 return LookdevModule::SphereLOD::LOW;
351}
352
353static int calc_sphere_extent(const float viewport_scale)
354{
355 const int sphere_radius = U.lookdev_sphere_size * UI_SCALE_FAC * viewport_scale;
356 return max_ii(sphere_radius * 2, 4);
357}
358
360{
361 if (!use_reference_spheres_) {
362 return;
363 }
364 const float viewport_scale = calc_viewport_scale();
365 const int2 extent = int2(calc_sphere_extent(viewport_scale));
366
367 const gpu::TextureFormat color_format = gpu::TextureFormat::SFLOAT_16_16_16_16;
368
369 for (int index : IndexRange(num_spheres)) {
370 if (spheres_[index].color_tx_.ensure_2d(color_format, extent)) {
371 /* Request redraw if the light-probe were off and the sampling was already finished. */
372 if (inst_.is_viewport() && inst_.sampling.finished_viewport()) {
373 inst_.sampling.reset();
374 }
375 }
376
377 spheres_[index].framebuffer.ensure(GPU_ATTACHMENT_NONE,
378 GPU_ATTACHMENT_TEXTURE(spheres_[index].color_tx_));
379 }
380
381 const Camera &cam = inst_.camera;
382 float sphere_distance = cam.data_get().clip_near;
383 int2 display_extent = inst_.film.display_extent_get();
384 float pixel_radius = View::screen_pixel_radius(
385 cam.data_get().wininv, cam.is_perspective(), display_extent);
386
387 if (cam.is_perspective()) {
388 pixel_radius *= sphere_distance;
389 }
390
391 this->sphere_radius_ = (extent.x / 2) * pixel_radius;
392 this->sphere_position_ = cam.position() -
393 cam.forward() * (sphere_distance + this->sphere_radius_);
394
395 float4x4 model_m4 = float4x4(float3x3(cam.data_get().viewmat));
396 model_m4.location() = this->sphere_position_;
397 model_m4 = math::scale(model_m4, float3(this->sphere_radius_));
398
399 ResourceHandleRange handle = inst_.manager->resource_handle(model_m4);
400 gpu::Batch *geom = sphere_get(calc_level_of_detail(viewport_scale));
401
402 sync_pass(spheres_[0].pass, geom, inst_.materials.metallic_mat, handle);
403 sync_pass(spheres_[1].pass, geom, inst_.materials.diffuse_mat, handle);
404 sync_display();
405}
406
407void LookdevModule::sync_pass(PassSimple &pass,
408 gpu::Batch *geom,
410 ResourceHandleRange res_handle)
411{
412 pass.init();
413 pass.clear_color_depth_stencil(float4(0.0, 0.0, 0.0, 1.0), inst_.film.depth.clear_value, 0);
414
416
418 mat, mat->nodetree, MAT_PIPE_FORWARD, MAT_GEOM_MESH, false, inst_.materials.default_surface);
419 pass.state_set(state);
420 pass.material_set(*inst_.manager, gpumat, false, inst_.anisotropic_filtering);
422 pass.bind_resources(inst_.uniform_data);
423 pass.bind_resources(inst_.lights);
424 pass.bind_resources(inst_.shadows);
425 pass.bind_resources(inst_.volume.result);
426 pass.bind_resources(inst_.sampling);
427 pass.bind_resources(inst_.hiz_buffer.front);
428 pass.bind_resources(inst_.volume_probes);
429 pass.bind_resources(inst_.sphere_probes);
430 pass.bind_resources(inst_.planar_probes);
431 pass.draw(geom, res_handle, 0);
432}
433
434void LookdevModule::sync_display()
435{
436 PassSimple &pass = display_ps_;
437
438 const float2 viewport_size = inst_.draw_ctx->viewport_size_get();
441 pass.init();
442 pass.state_set(state);
444 pass.push_constant("viewportSize", viewport_size);
445 pass.push_constant("invertedViewportSize", 1.0f / viewport_size);
446 pass.push_constant("anchor", int2(visible_rect_.xmax, visible_rect_.ymin));
447 pass.bind_texture("metallic_tx", &spheres_[0].color_tx_);
448 pass.bind_texture("diffuse_tx", &spheres_[1].color_tx_);
449
450 pass.draw_procedural(GPU_PRIM_TRIS, 2, 6);
451}
452
454{
455 if (!use_reference_spheres_) {
456 return;
457 }
458
459 inst_.volume_probes.set_view(view);
460 inst_.sphere_probes.set_view(view);
461
462 if (assign_if_different(inst_.pipelines.data.use_monochromatic_transmittance, bool32_t(true))) {
463 inst_.uniform_data.pipeline.push_update();
464 }
465
466 for (Sphere &sphere : spheres_) {
467 sphere.framebuffer.bind();
468 inst_.manager->submit(sphere.pass, view);
469 }
470}
471
473{
474 if (!inst_.is_viewport() || !inst_.use_studio_light()) {
475 return;
476 }
477
478 AxisAngle axis_angle_rotation(AxisSigned::Z_NEG, studio_light_rotation_z_);
479 float4x4 rotation = math::from_rotation<float4x4>(axis_angle_rotation);
480 if (use_viewspace_lighting_) {
482 rotation = inst_.camera.data_get().viewinv * math::from_rotation<float4x4>(target) * rotation;
483 }
484
485 if (assign_if_different(last_rotation_matrix_, rotation)) {
486 rotate_world_probe_data(inst_.sphere_probes.octahedral_probes_texture(),
487 inst_.sphere_probes.world_sphere_probe().atlas_coord,
488 inst_.sphere_probes.spherical_harmonics_buf(),
489 inst_.world.sunlight,
490 rotation);
491 }
492}
493
495{
496 if (!use_reference_spheres_) {
497 return;
498 }
499
500 BLI_assert(inst_.is_viewport());
501
502 DefaultFramebufferList *dfbl = inst_.draw_ctx->viewport_framebuffer_list_get();
503 /* The viewport of the framebuffer can be modified when border rendering is enabled. */
506 inst_.manager->submit(display_ps_);
507}
508
510 Texture &in_sphere_probe,
511 const SphereProbeAtlasCoord &atlas_coord,
514{
515 SphereProbeUvArea read_coord = atlas_coord.as_sampling_coord();
516 SphereProbePixelArea write_coord_mip0 = atlas_coord.as_write_coord(0);
517 SphereProbePixelArea write_coord_mip1 = atlas_coord.as_write_coord(1);
518 SphereProbePixelArea write_coord_mip2 = atlas_coord.as_write_coord(2);
519 SphereProbePixelArea write_coord_mip3 = atlas_coord.as_write_coord(3);
520 SphereProbePixelArea write_coord_mip4 = atlas_coord.as_write_coord(4);
521
522 if (world_sphere_probe_.ensure_2d_array(gpu::TextureFormat::SPHERE_PROBE_FORMAT,
523 in_sphere_probe.size().xy(),
524 1,
526 nullptr,
527 5))
528 {
529 GPU_texture_mipmap_mode(world_sphere_probe_, true, true);
530 world_sphere_probe_.ensure_mip_views();
531 }
532
533 PassSimple pass = {__func__};
534 pass.init();
535 pass.shader_set(inst_.shaders.static_shader_get(LOOKDEV_COPY_WORLD));
536 pass.push_constant("read_coord_packed", reinterpret_cast<int4 *>(&read_coord));
537 pass.push_constant("write_coord_mip0_packed", reinterpret_cast<int4 *>(&write_coord_mip0));
538 pass.push_constant("write_coord_mip1_packed", reinterpret_cast<int4 *>(&write_coord_mip1));
539 pass.push_constant("write_coord_mip2_packed", reinterpret_cast<int4 *>(&write_coord_mip2));
540 pass.push_constant("write_coord_mip3_packed", reinterpret_cast<int4 *>(&write_coord_mip3));
541 pass.push_constant("write_coord_mip4_packed", reinterpret_cast<int4 *>(&write_coord_mip4));
542 pass.push_constant("lookdev_rotation", float4x4::identity());
543 pass.bind_texture("in_sphere_tx", in_sphere_probe);
544 pass.bind_image("out_sphere_mip0", world_sphere_probe_.mip_view(0));
545 pass.bind_image("out_sphere_mip1", world_sphere_probe_.mip_view(1));
546 pass.bind_image("out_sphere_mip2", world_sphere_probe_.mip_view(2));
547 pass.bind_image("out_sphere_mip3", world_sphere_probe_.mip_view(3));
548 pass.bind_image("out_sphere_mip4", world_sphere_probe_.mip_view(4));
549 pass.bind_ssbo("in_sh", in_volume_probe);
550 pass.bind_ssbo("out_sh", world_volume_probe_);
551 pass.bind_ssbo("in_sun", in_sunlight); /* Note only the 1st member of the array is read. */
552 pass.bind_ssbo("out_sun", world_sunlight_);
553 int3 dispatch_size = int3(
554 int2(math::divide_ceil(int2(write_coord_mip0.extent), int2(SPHERE_PROBE_REMAP_GROUP_SIZE))),
555 1);
556 pass.dispatch(dispatch_size);
557
558 inst_.manager->submit(pass);
559
560 last_rotation_matrix_ = float4x4::identity();
561}
562
563/* This is called as soon as possible inside the frame drawing and tag world probe volume
564 * to update. Volume probe update is the only thing that needs to be triggered to make sure the SH
565 * are copied to all volume probes. Sphere probes are already updated by this function. */
567 Texture &dst_sphere_probe,
568 const SphereProbeAtlasCoord &atlas_coord,
571 float4x4 &rotation)
572{
573 SphereProbeUvArea read_coord = atlas_coord.as_sampling_coord();
574 SphereProbePixelArea write_coord_mip0 = atlas_coord.as_write_coord(0);
575 SphereProbePixelArea write_coord_mip1 = atlas_coord.as_write_coord(1);
576 SphereProbePixelArea write_coord_mip2 = atlas_coord.as_write_coord(2);
577 SphereProbePixelArea write_coord_mip3 = atlas_coord.as_write_coord(3);
578 SphereProbePixelArea write_coord_mip4 = atlas_coord.as_write_coord(4);
579
580 PassSimple pass = {__func__};
581 pass.init();
582 pass.shader_set(inst_.shaders.static_shader_get(LOOKDEV_COPY_WORLD));
583 pass.push_constant("read_coord_packed", reinterpret_cast<int4 *>(&read_coord));
584 pass.push_constant("write_coord_mip0_packed", reinterpret_cast<int4 *>(&write_coord_mip0));
585 pass.push_constant("write_coord_mip1_packed", reinterpret_cast<int4 *>(&write_coord_mip1));
586 pass.push_constant("write_coord_mip2_packed", reinterpret_cast<int4 *>(&write_coord_mip2));
587 pass.push_constant("write_coord_mip3_packed", reinterpret_cast<int4 *>(&write_coord_mip3));
588 pass.push_constant("write_coord_mip4_packed", reinterpret_cast<int4 *>(&write_coord_mip4));
589 pass.push_constant("lookdev_rotation", rotation);
590 pass.bind_texture("in_sphere_tx", &world_sphere_probe_);
591 pass.bind_image("out_sphere_mip0", dst_sphere_probe.mip_view(0));
592 pass.bind_image("out_sphere_mip1", dst_sphere_probe.mip_view(1));
593 pass.bind_image("out_sphere_mip2", dst_sphere_probe.mip_view(2));
594 pass.bind_image("out_sphere_mip3", dst_sphere_probe.mip_view(3));
595 pass.bind_image("out_sphere_mip4", dst_sphere_probe.mip_view(4));
596 pass.bind_ssbo("in_sh", world_volume_probe_);
597 pass.bind_ssbo("out_sh", dst_volume_probe);
598 pass.bind_ssbo("in_sun", world_sunlight_);
599 pass.bind_ssbo("out_sun", dst_sunlight);
600 int3 dispatch_size = int3(
601 int2(math::divide_ceil(int2(write_coord_mip0.extent), int2(SPHERE_PROBE_REMAP_GROUP_SIZE))),
602 1);
603 pass.dispatch(dispatch_size);
604
605 inst_.manager->submit(pass);
606 /* Tag world to update the SH stored in the volume probe atlas.
607 * If any volume probe is visible, this will reupload the baked data.
608 * This is the costly part of this feature. */
609 inst_.volume_probes.update_world_irradiance();
610}
611
613
614/* -------------------------------------------------------------------- */
617
622
624{
626
627 if (v3d == nullptr) {
628 return;
629 }
630
631 const blender::View3DShading &shading = v3d->shading;
634 if (!show_scene_world) {
635 rot_z = shading.studiolight_rot_z;
637 blur = shading.studiolight_blur;
641 }
642}
643
645{
646 return hdri == other.hdri && working_space == other.working_space &&
647 background_opacity == other.background_opacity && blur == other.blur &&
649 camera_space == other.camera_space;
650}
651
653{
654 return !(*this == other);
655}
656
658
659} // namespace blender::eevee
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_VECTOR_ROTATE
#define SH_NODE_TEX_COORD
#define SH_NODE_VECTOR_MATH
#define SH_NODE_TEX_ENVIRONMENT
#define SH_NODE_VECT_TRANSFORM
#define SH_NODE_BACKGROUND
#define SH_NODE_MIX
#define SH_NODE_LIGHT_PATH
#define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE
#define M_PI
#define MAX_NAME
Definition DNA_defs.h:63
#define UI_SCALE_FAC
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition GPU_batch.hh:199
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
int32_t bool32_t
#define output
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
constexpr IndexRange()=default
constexpr StringRefNull()
int3 size(int miplvl=0) const
gpu::Texture * mip_view(int miplvl)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
Definition draw_pass.hh:976
void bind_resources(U &resources)
Definition draw_pass.hh:459
void shader_set(gpu::Shader *shader)
void material_set(Manager &manager, GPUMaterial *material, bool deferred_texture_loading=false, GPUSamplerFiltering anisotropic_filtering=GPU_SAMPLER_FILTERING_DEFAULT)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void bind_image(const char *name, gpu::Texture *image)
void dispatch(int group_len)
void state_set(DRWState state, int clip_plane_count=0)
void clear_color_depth_stencil(float4 color, float depth, uint8_t stencil)
void push_constant(const char *name, const float &data)
void bind_ssbo(const char *name, gpu::StorageBuf *buffer)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
Definition draw_pass.hh:906
const float3 & forward() const
const float3 & position() const
const CameraData & data_get() const
bool is_perspective() const
struct blender::eevee::Film::DepthState depth
struct blender::eevee::HiZBuffer::@342214352322061324133130050175232001060230260232 front
A running instance of the engine.
VolumeProbeModule volume_probes
SphereProbeModule sphere_probes
const DRWContext * draw_ctx
GPUSamplerFiltering anisotropic_filtering
PlanarProbeModule planar_probes
UniformDataModule uniform_data
void store_world_probe_data(Texture &in_sphere_probe, const SphereProbeAtlasCoord &atlas_coord, StorageBuffer< SphereProbeHarmonic, true > &in_volume_probe, UniformArrayBuffer< LightData, 2 > &in_sunlight)
void rotate_world_probe_data(Texture &dst_sphere_probe, const SphereProbeAtlasCoord &atlas_coord, StorageBuffer< SphereProbeHarmonic, true > &dst_volume_probe, UniformArrayBuffer< LightData, 2 > &dst_sunlight, float4x4 &rotation)
void init(const rcti *visible_rect)
bool sync(const LookdevParameters &new_parameters)
blender::Material * default_surface
GPUMaterial * material_shader_get(blender::Material *blender_mat, bNodeTree *nodetree, eMaterialPipeline pipeline_type, eMaterialGeometry geometry_type, bool deferred_compilation, blender::Material *default_mat)
gpu::Shader * static_shader_get(eShaderType shader_type)
static float screen_pixel_radius(const float4x4 &wininv, bool is_perspective, const int2 &extent)
Definition draw_view.cc:349
struct blender::eevee::VolumeModule::@235034362354336005016350043217325022302275164354 result
#define RBUFS_UTILITY_TEX_SLOT
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
float3x3 scale(float3x3 mat, float2 scale)
const int state
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
Definition node.cc:4283
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4638
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
void node_set_active(bNodeTree &ntree, bNode &node)
Definition node.cc:5484
detail::Pass< command::DrawCommandBuf > PassSimple
static int calc_sphere_extent(const float viewport_scale)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
MatT from_rotation(const RotationT &rotation)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
VecBase< int32_t, 4 > int4
bool assign_if_different(T &old_value, T &&new_value)
void BKE_studiolight_ensure_flag(StudioLight *sl, int flag)
void BKE_image_assign_gpu_texture(Image *image, gpu::Texture *texture)
Definition image_gpu.cc:737
ImageTile * BKE_image_get_tile(Image *ima, int tile_number)
MINLINE void copy_v4_fl(float r[4], float f)
MINLINE int max_ii(int a, int b)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION
@ V3D_SHADING_SCENE_WORLD_RENDER
struct StudioLight * BKE_studiolight_find(const char *name, int flag)
VecBase< float, 4 > float4
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
void GPU_material_free(ListBaseT< LinkData > *gpumaterial)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_framebuffer_viewport_reset(gpu::FrameBuffer *fb)
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
@ DRW_STATE_CULL_BACK
Definition draw_state.hh:45
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:57
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:31
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:38
MatBase< float, 3, 3 > float3x3
void BKE_id_free(Main *bmain, void *idv)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void GPU_vertbuf_vert_set(gpu::VertBuf *verts, uint v_idx, const void *data)
void BKE_ntree_update_without_main(bNodeTree &tree)
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1617
@ SHD_VECT_TRANSFORM_SPACE_WORLD
@ SHD_VECT_TRANSFORM_SPACE_CAMERA
@ NODE_MIX_MODE_UNIFORM
void GPU_texture_free(gpu::Texture *texture)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
@ NODE_VECTOR_MATH_MULTIPLY
gpu::Texture * BKE_image_acquire_gpu_texture(Image *image, ImageUser *iuser)
Definition image_gpu.cc:732
VecBase< float, 3 > float3
const char * IMB_colormanagement_working_space_get()
MINLINE float clamp_f(float value, float min, float max)
void GPU_texture_ref(gpu::Texture *texture)
void vert(const int vert_id, float4 &position)
#define sinf
#define cosf
float2 viewport_size_get() const
char name[258]
Definition DNA_ID.h:433
eImageGenType gen_type
NodeShaderMixMode factor_mode
eNodeSocketDatatype data_type
gpu::Texture * equirect_radiance_gputexture
eView3DShading_Flag flag
View3DShading shading
ListBaseT< bNodeSocket > inputs
bool operator==(const LookdevParameters &other) const
bool operator!=(const LookdevParameters &other) const
SphereProbePixelArea as_write_coord(int mip_lvl) const
SphereProbeUvArea as_sampling_coord() const