Blender V5.3
eevee_pipeline.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#include "BLI_bounds.hh"
14#include "GPU_capabilities.hh"
15
16#include "eevee_instance.hh"
17#include "eevee_pipeline.hh"
18#include "eevee_shadow.hh"
19
20#include "GPU_debug.hh"
21
22#include "draw_common.hh"
23
24namespace blender::eevee {
25
26/* -------------------------------------------------------------------- */
31
33 const float background_opacity,
34 const float background_blur)
35{
36 Manager &manager = *inst_.manager;
37 RenderBuffers &rbufs = inst_.render_buffers;
38
39 clear_ps_.init();
40 clear_ps_.state_set(DRW_STATE_WRITE_COLOR);
41 clear_ps_.shader_set(inst_.shaders.static_shader_get(RENDERPASS_CLEAR));
42 /* RenderPasses & AOVs. Cleared by background (even if bad practice). */
43 clear_ps_.bind_image("rp_color_img", &rbufs.rp_color_tx);
44 clear_ps_.bind_image("rp_value_img", &rbufs.rp_value_tx);
45 clear_ps_.bind_image("rp_cryptomatte_img", &rbufs.cryptomatte_tx);
46 /* Required by validation layers. */
47 clear_ps_.bind_resources(inst_.cryptomatte);
48 clear_ps_.bind_resources(inst_.uniform_data);
49 clear_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
50 /* To allow opaque pass rendering over it. */
51 clear_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
52
53 world_ps_.init();
56 world_ps_.material_set(manager, gpumat, false, inst_.anisotropic_filtering);
57 world_ps_.push_constant("world_opacity_fade", background_opacity);
58 world_ps_.push_constant("world_background_blur", square_f(background_blur));
59 SphereProbeData &world_data = *static_cast<SphereProbeData *>(&inst_.light_probes.world_sphere_);
60 world_ps_.push_constant("world_coord_packed", reinterpret_cast<int4 *>(&world_data.atlas_coord));
61 world_ps_.bind_texture("utility_tx", inst_.pipelines.utility_tx);
62 /* RenderPasses & AOVs. */
63 world_ps_.bind_image("rp_color_img", &rbufs.rp_color_tx);
64 world_ps_.bind_image("rp_value_img", &rbufs.rp_value_tx);
65 world_ps_.bind_image("rp_cryptomatte_img", &rbufs.cryptomatte_tx);
66 /* Required by validation layers. */
67 world_ps_.bind_resources(inst_.cryptomatte);
68 world_ps_.bind_resources(inst_.uniform_data);
69 world_ps_.bind_resources(inst_.sampling);
70 world_ps_.bind_resources(inst_.sphere_probes);
71 world_ps_.bind_resources(inst_.volume_probes);
72 world_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
73 /* To allow opaque pass rendering over it. */
74 world_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
75}
76
78{
79 inst_.manager->submit(clear_ps_, view);
80}
81
83{
84 GPU_framebuffer_bind(combined_fb);
85 inst_.manager->submit(world_ps_, view);
86}
87
89
90/* -------------------------------------------------------------------- */
93
95{
96 const int2 extent(1);
99 dummy_cryptomatte_tx_.ensure_2d(gpu::TextureFormat::SFLOAT_32_32_32_32, extent, usage);
100 dummy_renderpass_tx_.ensure_2d(gpu::TextureFormat::SFLOAT_16_16_16_16, extent, usage);
101 dummy_aov_color_tx_.ensure_2d_array(gpu::TextureFormat::SFLOAT_16_16_16_16, extent, 1, usage);
102 dummy_aov_value_tx_.ensure_2d_array(gpu::TextureFormat::SFLOAT_16, extent, 1, usage);
103
104 PassSimple &pass = cubemap_face_ps_;
105 pass.init();
107
108 Manager &manager = *inst_.manager;
109 pass.material_set(manager, gpumat, false, inst_.anisotropic_filtering);
110 pass.push_constant("world_opacity_fade", 1.0f);
111 pass.push_constant("world_background_blur", 0.0f);
112 pass.push_constant("world_coord_packed", int4(0.0f));
113 pass.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
114 pass.bind_image("rp_normal_img", dummy_renderpass_tx_);
115 pass.bind_image("rp_light_img", dummy_renderpass_tx_);
116 pass.bind_image("rp_diffuse_color_img", dummy_renderpass_tx_);
117 pass.bind_image("rp_specular_color_img", dummy_renderpass_tx_);
118 pass.bind_image("rp_emission_img", dummy_renderpass_tx_);
119 pass.bind_image("rp_cryptomatte_img", dummy_cryptomatte_tx_);
120 pass.bind_image("rp_color_img", dummy_aov_color_tx_);
121 pass.bind_image("rp_value_img", dummy_aov_value_tx_);
122 pass.bind_image("aov_color_img", dummy_aov_color_tx_);
123 pass.bind_image("aov_value_img", dummy_aov_value_tx_);
124 pass.bind_ssbo("aov_buf", &inst_.film.aovs_info);
125 /* Required by validation layers. */
126 pass.bind_resources(inst_.cryptomatte);
127 pass.bind_resources(inst_.uniform_data);
128 pass.bind_resources(inst_.sampling);
129 pass.bind_resources(inst_.sphere_probes);
130 pass.bind_resources(inst_.volume_probes);
131 pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
132
133 /* Split the rendering of the world in two passes. */
135}
136
138{
139 inst_.manager->submit(cubemap_face_ps_, view);
140}
141
143
144/* -------------------------------------------------------------------- */
148
150{
151 is_valid_ = (gpumat != nullptr) && (GPU_material_status(gpumat) == GPU_MAT_SUCCESS) &&
153 if (!is_valid_) {
154 /* Skip if the material has not compiled yet. */
155 return;
156 }
157
158 world_ps_.init();
159 world_ps_.state_set(DRW_STATE_WRITE_COLOR);
160 world_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
161 world_ps_.bind_resources(inst_.uniform_data);
162 world_ps_.bind_resources(inst_.volume.properties);
163 world_ps_.bind_resources(inst_.sampling);
164
165 world_ps_.material_set(*inst_.manager, gpumat, false, inst_.anisotropic_filtering);
166 /* Bind correct dummy texture for attributes defaults. */
167 PassSimple::Sub *sub = volume_sub_pass(world_ps_, nullptr, nullptr, gpumat);
168
169 is_valid_ = (sub != nullptr);
170 if (is_valid_) {
171 world_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
172 /* Sync with object property pass. */
173 world_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
174 }
175}
176
178{
179 if (!is_valid_) {
180 /* Clear the properties buffer instead of rendering if there is no valid shader. */
181 inst_.volume.prop_scattering_tx_.clear(float4(0.0f));
182 inst_.volume.prop_extinction_tx_.clear(float4(0.0f));
183 inst_.volume.prop_emission_tx_.clear(float4(0.0f));
184 inst_.volume.prop_phase_tx_.clear(float4(0.0f));
185 inst_.volume.prop_phase_weight_tx_.clear(float4(0.0f));
186 return;
187 }
188
189 inst_.manager->submit(world_ps_, view);
190}
191
193
194/* -------------------------------------------------------------------- */
198
200{
201 render_ps_.init();
202
203 {
205
206 draw::PassMain::Sub &pass = render_ps_.sub("Shadow.Surface");
207 pass.state_set(state);
208 pass.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
209 pass.bind_ssbo(SHADOW_RENDER_VIEW_BUF_SLOT, &inst_.shadows.render_view_buf_);
210 pass.bind_image(SHADOW_ATLAS_IMG_SLOT, inst_.shadows.atlas_tx_);
211 pass.bind_ssbo(SHADOW_RENDER_MAP_BUF_SLOT, &inst_.shadows.render_map_buf_);
212 pass.bind_ssbo(SHADOW_PAGE_INFO_SLOT, &inst_.shadows.pages_infos_data_);
213 pass.bind_resources(inst_.uniform_data);
214 pass.bind_resources(inst_.sampling);
215 surface_double_sided_ps_ = &pass.sub("Shadow.Surface.Double-Sided");
216 surface_single_sided_ps_ = &pass.sub("Shadow.Surface.Single-Sided");
217 surface_single_sided_ps_->state_set(state | DRW_STATE_CULL_BACK);
218 }
219}
220
222 GPUMaterial *gpumat)
223{
224 PassMain::Sub *pass = (material->blend_flag & MA_BL_CULL_BACKFACE_SHADOW) ?
225 surface_single_sided_ps_ :
226 surface_double_sided_ps_;
227 return &pass->sub(GPU_material_get_name(gpumat));
228}
229
231{
232 inst_.manager->submit(render_ps_, view);
233}
234
236
237/* -------------------------------------------------------------------- */
242
243void Prepass::init(DRWState extra_state,
244 bool supports_motion_vectors,
245 bool supports_raycast_visibility,
246 FunctionRef<void(PassMain &pass)> pass_setup_cb)
247{
249 inst_.film.depth.test_state | extra_state;
250 supports_motion_vectors_ = supports_motion_vectors;
251 supports_raycast_visibility_ = supports_raycast_visibility;
252
253 pass_.init();
254 /* Common resources. */
255 pass_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
256 pass_.bind_resources(inst_.uniform_data);
257 pass_.bind_resources(inst_.velocity);
258 pass_.bind_resources(inst_.sampling);
259 if (pass_setup_cb) {
260 pass_setup_cb(pass_);
261 }
262
263 static constexpr const char
264 *subpass_names[2 /*hide from raycast*/][2 /*double sided*/][2 /*moving*/][2 /*write id*/] = {
265 {{{"SingleSided.Static", "SingleSided.Static.ID"},
266 {"SingleSided.Moving", "SingleSided.Moving.ID"}},
267 {{"DoubleSided.Static", "DoubleSided.Static.ID"},
268 {"DoubleSided.Moving", "DoubleSided.Moving.ID"}}},
269 {{{"HideFromRaycast.SingleSided.Static", ""},
270 {"HideFromRaycast.SingleSided.Moving", ""}},
271 {{"HideFromRaycast.DoubleSided.Static", ""},
272 {"HideFromRaycast.DoubleSided.Moving", ""}}}};
273
274 for (bool hide_from_raycast : {false, true}) {
275 for (bool double_sided : {false, true}) {
276 for (bool moving : {false, true}) {
277 for (bool write_id : {false, true}) {
278 PassMain::Sub *&sub = subs_[hide_from_raycast][double_sided][moving][write_id];
279 PassMain::Sub *&setup_sub =
280 setup_subs_[hide_from_raycast][double_sided][moving][write_id];
281 if ((hide_from_raycast && write_id) || (!supports_motion_vectors && moving) ||
282 (!supports_raycast_visibility && !hide_from_raycast))
283 {
284 /* Never needed.
285 * Object IDs are only used for checking raycast self-hits.
286 * If the pipeline doesn't support motion vectors, Prepass::add should always be called
287 * with has_motion == false.
288 * If the pipeline doesn't support raycast visibility, Prepass::add should always be
289 * called with hide_from_raycast == true. */
290 sub = nullptr;
291 setup_sub = nullptr;
292 continue;
293 }
294 sub = &pass_.sub(subpass_names[hide_from_raycast][double_sided][moving][write_id]);
295 setup_sub = &sub->sub("Setup");
296 }
297 }
298 }
299 }
300
301 dummy_raycast_depth_tx_.ensure_2d(RenderBuffers::depth_format, int2(1));
302 dummy_raycast_id_tx_.ensure_2d(RenderBuffers::object_id_format, int2(1));
303 dummy_raycast_normal_tx_.ensure_2d(RenderBuffers::prepass_normal_format, int2(1));
304}
305
307 GPUMaterial *gpumat,
308 bool has_motion,
309 bool hide_from_raycast)
310{
311 const bool double_sided = !(blender_mat->blend_flag & MA_BL_CULL_BACKFACE);
312 const bool has_raycast = GPU_material_flag_get(gpumat, GPU_MATFLAG_RAYCAST);
313 const bool write_id = has_raycast && !hide_from_raycast;
314
315 PassMain::Sub &sub = subs_[hide_from_raycast][double_sided][has_motion][write_id]->sub(
316 GPU_material_get_name(gpumat));
317 if (has_raycast) {
318 /* NOTE: Bound per subpass since material textures could override these slots. */
320 hide_from_raycast ? &inst_.render_buffers.raycast_depth_tx :
321 &dummy_raycast_depth_tx_);
323 hide_from_raycast ? &inst_.render_buffers.object_id_tx :
324 &dummy_raycast_id_tx_);
326 hide_from_raycast ? &inst_.render_buffers.prepass_normal_tx :
327 &dummy_raycast_normal_tx_);
328 }
329 return &sub;
330}
331
333{
334 const bool has_raycast = inst_.pipelines.has_raycast;
335
336 for (bool hide_from_raycast : {false, true}) {
337 for (bool double_sided : {false, true}) {
338 for (bool moving : {false, true}) {
339 for (bool write_id : {false, true}) {
340 PassMain::Sub *sub = setup_subs_[hide_from_raycast][double_sided][moving][write_id];
341 if (!sub) {
342 continue;
343 }
344 const bool write_raycast = has_raycast && !hide_from_raycast;
345 const bool read_raycast = has_raycast && hide_from_raycast;
346 const bool write_motion = supports_motion_vectors_ && moving;
347 DRWState state = common_state_;
349 SET_FLAG_FROM_TEST(state, write_raycast || write_motion, DRW_STATE_WRITE_COLOR);
350 sub->state_set(state);
353 {write_raycast ?
355 (read_raycast ? GPU_ATTACHMENT_READ : GPU_ATTACHMENT_IGNORE), /* normal */
356 (write_raycast && write_id) ?
360 }
361 }
362 }
363 }
364
365 if (supports_raycast_visibility_) {
366 /* First Raycast-visible Subpass. */
367 setup_subs_[false][false][false][false]->bind_ubo(PIPELINE_BUF_SLOT, &pipeline_buf_copy_);
368 }
369 /* First HideFromRaycast Subpass. */
370 setup_subs_[true][false][false][false]->bind_ubo(PIPELINE_BUF_SLOT,
371 &pipeline_buf_copy_hide_from_raycast_);
372
373 if (has_raycast && supports_raycast_visibility_) {
374 setup_subs_[true][false][false][false]->texture_copy(&fb_depth_tx_,
375 &inst_.render_buffers.raycast_depth_tx);
376 }
377}
378
379void Prepass::render(View &view, gpu::Texture *fb_depth_tx, bool can_raycast)
380{
381 *pipeline_buf_copy_.data() = *inst_.uniform_data.pipeline.data();
382 pipeline_buf_copy_.can_raycast = false;
383 pipeline_buf_copy_.push_update();
384
385 *pipeline_buf_copy_hide_from_raycast_.data() = *inst_.uniform_data.pipeline.data();
386 pipeline_buf_copy_hide_from_raycast_.can_raycast = can_raycast;
387 pipeline_buf_copy_hide_from_raycast_.push_update();
388
389 fb_depth_tx_ = fb_depth_tx;
390
391 inst_.manager->submit(pass_, view);
392}
393
395
396/* -------------------------------------------------------------------- */
401
403{
404 camera_forward_ = inst_.camera.forward();
405 has_opaque_ = false;
406 has_transparent_ = false;
407 has_colored_transparency_ = false;
408 has_holdout_ = false;
409
410 prepass_.init({}, true, false);
411
412 {
413 opaque_ps_.init();
414
415 {
416 /* Common resources. */
417 opaque_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
418
419 opaque_ps_.bind_resources(inst_.uniform_data);
420 opaque_ps_.bind_resources(inst_.lights);
421 opaque_ps_.bind_resources(inst_.shadows);
422 opaque_ps_.bind_resources(inst_.volume.result);
423 opaque_ps_.bind_resources(inst_.sampling);
424 opaque_ps_.bind_resources(inst_.hiz_buffer.front);
425 opaque_ps_.bind_resources(inst_.volume_probes);
426 opaque_ps_.bind_resources(inst_.sphere_probes);
427 opaque_ps_.bind_resources(inst_.planar_probes);
428 }
429
432
433 static constexpr const char *subpass_names[2 /*Raycast*/][2 /*DoubleSided*/] = {
434 {"NoRaycast.SingleSided", "NoRaycast.DoubleSided"},
435 {"Raycast.SingleSided", "Raycast.DoubleSided"}};
436
437 for (bool raycast : {false, true}) {
438 for (bool double_sided : {false, true}) {
439 PassMain::Sub *&pass = opaque_subpasses_[raycast][double_sided];
440 pass = &opaque_ps_.sub(subpass_names[raycast][double_sided]);
441 pass->state_set(double_sided ? state : (state | DRW_STATE_CULL_BACK));
442 if (raycast) {
443 pass->bind_texture(RAYCAST_DEPTH_TEX_SLOT, &inst_.render_buffers.raycast_depth_tx);
444 pass->bind_texture(OBJECT_ID_TEX_SLOT, &inst_.render_buffers.object_id_tx);
445 pass->bind_texture(PREPASS_NORMAL_TEX_SLOT, &inst_.render_buffers.prepass_normal_tx);
446 }
447 }
448 }
449 }
450 {
451 transparent_ps_.init();
452 /* Workaround limitation of PassSortable. Use dummy pass that will be sorted first in all
453 * circumstances. */
454 PassMain::Sub &sub = transparent_ps_.sub("ResourceBind", -FLT_MAX);
455
456 /* Common resources. */
457
458 /* Textures. */
459 sub.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
460
461 sub.bind_resources(inst_.uniform_data);
462 sub.bind_resources(inst_.lights);
463 sub.bind_resources(inst_.shadows);
464 sub.bind_resources(inst_.volume.result);
465 sub.bind_resources(inst_.sampling);
466 sub.bind_resources(inst_.hiz_buffer.front);
467 sub.bind_resources(inst_.volume_probes);
468 sub.bind_resources(inst_.sphere_probes);
469 sub.bind_resources(inst_.planar_probes);
470 }
471 {
472 gpu::Shader *sh = inst_.shaders.static_shader_get(TRANSPARENCY_RESOLVE);
473
474 resolve_ps_.init();
475 resolve_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
476 resolve_ps_.shader_set(sh);
477 resolve_ps_.bind_texture("transparency_r_tx", &transp_buffer_.r_channel_tx);
478 resolve_ps_.bind_texture("transparency_g_tx", &transp_buffer_.g_channel_tx);
479 resolve_ps_.bind_texture("transparency_b_tx", &transp_buffer_.b_channel_tx);
480 resolve_ps_.bind_texture("transparency_a_tx", &transp_buffer_.a_channel_tx);
481 resolve_ps_.bind_image("rp_color_img", &inst_.render_buffers.rp_color_tx);
482 resolve_ps_.bind_image("rp_value_img", &inst_.render_buffers.rp_value_tx);
483 resolve_ps_.bind_resources(inst_.uniform_data);
484 resolve_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
485 }
486}
487
489{
490 inst_.pipelines.data.use_monochromatic_transmittance = !use_colored_transparency();
491 prepass_.end_sync();
492}
493
495 GPUMaterial *gpumat,
496 bool has_motion)
497{
499 "Forward Transparent should be registered directly without calling "
500 "PipelineModule::material_add()");
501
502 /* If material is fully additive or transparent, we can skip the opaque prepass. */
503 /* TODO(fclem): To skip it, we need to know if the transparent BSDF is fully white AND if there
504 * is no mix shader (could do better constant folding but that's expensive). */
505
506 has_opaque_ = true;
507 return prepass_.add(blender_mat, gpumat, has_motion, true);
508}
509
511 blender::Material *blender_mat,
512 GPUMaterial *gpumat)
513{
515 "Forward Transparent should be registered directly without calling "
516 "PipelineModule::material_add()");
517 has_holdout_ |= GPU_material_flag_get(gpumat, GPU_MATFLAG_HOLDOUT) ||
519 PassMain::Sub *pass = get_opaque_subpass(blender_mat, gpumat);
520 has_opaque_ = true;
521 return &pass->sub(GPU_material_get_name(gpumat));
522}
523
525 const float3 &ob_location,
526 blender::Material *blender_mat,
527 GPUMaterial *gpumat,
528 PassMain::Sub *&r_prepass_subpass,
529 PassMain::Sub *&r_material_subpass)
530{
532 inst_.film.depth.test_state;
533
535 DRW_STATE_CLIP_CONTROL_UNIT_RANGE | inst_.film.depth.test_state;
536
537 if (blender_mat->blend_flag & MA_BL_CULL_BACKFACE) {
538 prepass_state |= DRW_STATE_CULL_BACK;
539 material_state |= DRW_STATE_CULL_BACK;
540 }
541
542 has_transparent_ = true;
543 has_colored_transparency_ |= GPU_material_flag_get(gpumat,
545 has_holdout_ |= GPU_material_flag_get(gpumat, GPU_MATFLAG_HOLDOUT) ||
547 /* Must be checked here too,
548 * since this function is not called from PipelineModule::material_add. */
549 inst_.pipelines.has_raycast |= GPU_material_flag_get(gpumat, GPU_MATFLAG_RAYCAST);
550
551 /* Must match the `use_forward_lighting && use_transparency` condition on previous_layer_hiz /
552 * previous_layer_radiance. */
553 const bool bind_previous_layer = GPU_material_flag_get(gpumat, GPU_MATFLAG_TRANSPARENT);
554
555 /* Transparent needs to use one sub pass per object to support reordering.
556 * NOTE: Pre-pass needs to be created first in order to be sorted first. */
557 float sorting_value = math::dot(ob_location, camera_forward_);
558
559 const bool has_raycast = GPU_material_flag_get(gpumat, GPU_MATFLAG_RAYCAST);
560
561 /* Prepass */
562 if (blender_mat->blend_flag & MA_BL_HIDE_BACKFACE) {
563 PassMain::Sub *pass = &transparent_ps_.sub(GPU_material_get_name(gpumat), sorting_value);
564 pass->state_set(prepass_state);
565 pass->material_set(*inst_.manager, gpumat, true, inst_.anisotropic_filtering);
566 if (bind_previous_layer) {
567 pass->bind_texture(HIZ_PREVIOUS_LAYER_TEX_SLOT, &inst_.hiz_buffer.back.ref_tx_);
568 pass->bind_texture(RADIANCE_PREVIOUS_LAYER_TEX_SLOT, &inst_.render_buffers.combined_tx);
569 }
570 if (has_raycast) {
571 pass->bind_texture(RAYCAST_DEPTH_TEX_SLOT, &inst_.render_buffers.raycast_depth_tx);
572 pass->bind_texture(OBJECT_ID_TEX_SLOT, &inst_.render_buffers.object_id_tx);
573 pass->bind_texture(PREPASS_NORMAL_TEX_SLOT, &inst_.render_buffers.prepass_normal_tx);
574 }
575 r_prepass_subpass = pass;
576 }
577
578 /* Material */
579 {
580 PassMain::Sub *pass = &transparent_ps_.sub(GPU_material_get_name(gpumat), sorting_value);
581 pass->state_set(material_state);
582 pass->material_set(*inst_.manager, gpumat, true, inst_.anisotropic_filtering);
583 if (bind_previous_layer) {
584 pass->bind_texture(HIZ_PREVIOUS_LAYER_TEX_SLOT, &inst_.hiz_buffer.back.ref_tx_);
585 pass->bind_texture(RADIANCE_PREVIOUS_LAYER_TEX_SLOT, &inst_.render_buffers.combined_tx);
586 }
587 if (has_raycast) {
588 pass->bind_texture(RAYCAST_DEPTH_TEX_SLOT, &inst_.render_buffers.raycast_depth_tx);
589 pass->bind_texture(OBJECT_ID_TEX_SLOT, &inst_.render_buffers.object_id_tx);
590 pass->bind_texture(PREPASS_NORMAL_TEX_SLOT, &inst_.render_buffers.prepass_normal_tx);
591 }
592 r_material_subpass = pass;
593 }
594}
595
596void ForwardPipeline::TransparencyBuffer::acquire(int2 extent, bool use_colored_transparency)
597{
599
601 r_channel_tx.acquire_2d(extent, gpu::TextureFormat::SFLOAT_16_16_16_16, usage);
602 /* Dummy texture for validation. Will not be sampled or attached. */
603 g_channel_tx.acquire_2d(int2(1), gpu::TextureFormat::UNORM_8_8_8_8);
604 b_channel_tx.acquire_2d(int2(1), gpu::TextureFormat::UNORM_8_8_8_8);
605 a_channel_tx.acquire_2d(int2(1), gpu::TextureFormat::UNORM_8_8_8_8);
606 }
607 else {
608 r_channel_tx.acquire_2d(extent, gpu::TextureFormat::SFLOAT_16_16, usage);
609 g_channel_tx.acquire_2d(extent, gpu::TextureFormat::SFLOAT_16_16, usage);
610 b_channel_tx.acquire_2d(extent, gpu::TextureFormat::SFLOAT_16_16, usage);
611 a_channel_tx.acquire_2d(extent, gpu::TextureFormat::UNORM_8_8, usage);
612 }
613}
614
615void ForwardPipeline::TransparencyBuffer::release()
616{
617 r_channel_tx.release();
618 g_channel_tx.release();
619 b_channel_tx.release();
620 a_channel_tx.release();
621}
622
624{
625 /* Holdout also enables transparency since it uses the 4th target. */
626 return has_colored_transparency_ || has_holdout_;
627}
628
630 gpu::Texture *depth_tx,
631 Framebuffer &prepass_fb,
632 Framebuffer &transparent_fb,
633 Framebuffer &combined_fb,
634 int2 extent)
635{
636 /* We need to ensure the pipeline runs if outputting the transparent render-pass (see #154895).
637 */
638 if (!has_transparent_ && !has_opaque_ && inst_.render_buffers.data.transparent_id == -1) {
639 return;
640 }
641
642 inst_.hiz_buffer.swap_layer();
643
644 GPU_debug_group_begin("Forward.Opaque");
645
646 prepass_fb.bind();
647 prepass_.render(view, nullptr, true);
648
649 inst_.hiz_buffer.set_dirty();
650 inst_.hiz_buffer.update();
651
652 inst_.shadows.render(view, extent);
653 inst_.volume_probes.set_view(view);
654 inst_.sphere_probes.set_view(view);
655
656 transp_buffer_.acquire(extent, use_colored_transparency());
657
659 /* NOTE: When using Vulkan this triggers a (false positive) validation warning about writing to
660 * an attachment that isn't filled. The warning could be removed by adding dummy attachments,
661 * recompiling the shader, etc. But it is not worth the hassle.
662 *
663 * VUID: Undefined-Value-ShaderOutputNotConsumed-DynamicRendering
664 * MessageId: 0x46877e3e
665 */
666 transparent_fb.ensure(GPU_ATTACHMENT_TEXTURE(depth_tx),
667 GPU_ATTACHMENT_TEXTURE(transp_buffer_.r_channel_tx));
668 }
669 else {
670 transparent_fb.ensure(GPU_ATTACHMENT_TEXTURE(depth_tx),
671 GPU_ATTACHMENT_TEXTURE(transp_buffer_.r_channel_tx),
672 GPU_ATTACHMENT_TEXTURE(transp_buffer_.g_channel_tx),
673 GPU_ATTACHMENT_TEXTURE(transp_buffer_.b_channel_tx),
674 GPU_ATTACHMENT_TEXTURE(transp_buffer_.a_channel_tx));
675 }
676
677 transparent_fb.bind();
678
680 /* Split channel targets. Radiance in 1st channel, transmittance in 2nd channel. */
681 transparent_fb.clear_color(float4(0.0f, 1.0f, 0.0f, 0.0f));
682 }
683 else {
684 transparent_fb.clear_color(float4(0.0f, 0.0f, 0.0f, 1.0f));
685 }
686
687 if (has_opaque_) {
688 inst_.manager->submit(opaque_ps_, view);
689 }
690
692
693 if (has_transparent_) {
694 inst_.manager->submit(transparent_ps_, view);
695 }
696
697 combined_fb.bind();
698 inst_.manager->submit(resolve_ps_, view);
699
700 transp_buffer_.release();
701}
702
704
705/* -------------------------------------------------------------------- */
708
710{
711 gbuffer_ps_.init();
712 gbuffer_ps_.subpass_transition(GPU_ATTACHMENT_WRITE,
718 /* G-buffer. */
720 /* RenderPasses & AOVs. */
723 /* Cryptomatte. */
725 /* Storage Buffer. */
726 /* Textures. */
728
729 gbuffer_ps_.bind_resources(inst.uniform_data);
730 gbuffer_ps_.bind_resources(inst.sampling);
731 gbuffer_ps_.bind_resources(inst.hiz_buffer.front);
732 gbuffer_ps_.bind_resources(inst.cryptomatte);
733
736
737 static constexpr const char *subpass_names[2 /*Hybrid*/][2 /*Raycast*/][2 /*DoubleSided*/] = {
738 {{"Deferred.NoRaycast.SingleSided", "Deferred.NoRaycast.DoubleSided"},
739 {"Deferred.Raycast.SingleSided", "Deferred.Raycast.DoubleSided"}},
740 {{"Hybrid.NoRaycast.SingleSided", "Hybrid.NoRaycast.DoubleSided"},
741 {"Hybrid.Raycast.SingleSided", "Hybrid.Raycast.DoubleSided"}}};
742
743 for (bool hybrid : {false, true}) {
744 for (bool raycast : {false, true}) {
745 for (bool double_sided : {false, true}) {
746 PassMain::Sub *&pass = gbuffer_subpasses_[hybrid][raycast][double_sided];
747 pass = &gbuffer_ps_.sub(subpass_names[hybrid][raycast][double_sided]);
748 pass->state_set(double_sided ? state : (state | DRW_STATE_CULL_BACK));
749 if (hybrid) {
750 pass->bind_resources(inst.lights);
751 pass->bind_resources(inst.shadows);
752 pass->bind_resources(inst.sphere_probes);
753 pass->bind_resources(inst.volume_probes);
754 if (is_probe_) {
756 }
757 else {
758 pass->bind_resources(inst.planar_probes);
759 }
762 }
763 if (raycast) {
767 }
768 }
769 }
770 }
771
773 closure_count_ = 0;
774 radiance_behind_tx_ = nullptr;
775}
776
778{
779 /* Make alpha hash scale sub-pixel so that it converges to a noise free image.
780 * If there is motion, use pixel scale for stability. */
781 bool alpha_hash_subpixel_scale = !inst_.is_viewport() || !inst_.velocity.camera_has_motion();
782 inst_.pipelines.data.alpha_hash_scale = alpha_hash_subpixel_scale ? 0.1f : 1.0f;
783
785 true,
786 true,
787 [](PassMain &pass) { pass.state_stencil(0xFFu, 0u, 0xFFu); });
788
789 {
790 gpu::Shader *sh = inst_.shaders.static_shader_get(DEFERRED_AOV_CLEAR);
792 clear_aovs_ps_.shader_set(sh);
794 clear_aovs_ps_.bind_image("rp_color_img", &inst_.render_buffers.rp_color_tx);
795 clear_aovs_ps_.bind_image("rp_value_img", &inst_.render_buffers.rp_value_tx);
796 clear_aovs_ps_.bind_image("rp_cryptomatte_img", &inst_.render_buffers.cryptomatte_tx);
797 clear_aovs_ps_.bind_resources(inst_.cryptomatte);
798 clear_aovs_ps_.bind_resources(inst_.uniform_data);
799 clear_aovs_ps_.state_stencil(0xFFu, 0x0u, 0xFFu);
800 }
801
802 this->gbuffer_pass_sync(inst_);
803}
804
809
815
820
821void DeferredLayer::end_sync(bool is_first_pass,
822 bool is_last_pass,
823 bool next_layer_has_transmission)
824{
826
827 const bool has_any_closure = closure_bits_ != 0;
828 /* We need the feedback output in case of refraction in the next pass (see #126455). */
829 const bool is_layer_refracted = (next_layer_has_transmission && has_any_closure);
830 const bool has_transmit_closure = (closure_bits_ & (CLOSURE_REFRACTION | CLOSURE_TRANSLUCENT));
831 const bool has_reflect_closure = (closure_bits_ & (CLOSURE_REFLECTION | CLOSURE_DIFFUSE));
832 const bool has_transparent_shader_to_rgba = (closure_bits_ & CLOSURE_TRANSPARENCY) &&
834 use_raytracing_ = (has_transmit_closure || has_reflect_closure) &&
835 inst_.raytracing.use_raytracing();
836 /* Is the radiance split for the combined pass. Must match what the light evaluation writes:
837 * either ray-tracing writes the indirect radiance, or the light-probe evaluation does. */
838 use_split_radiance_ = use_raytracing_ || do_split_direct_indirect_radiance(inst_);
839
840 /* The first pass will never have any surfaces behind it. Nothing is refracted except the
841 * environment. So in this case, disable tracing and fallback to probe. */
842 use_screen_transmission_ = use_raytracing_ &&
843 (has_transmit_closure || has_transparent_shader_to_rgba) &&
844 !is_first_pass;
845 use_screen_reflection_ = use_raytracing_ && has_reflect_closure;
846
847 use_feedback_output_ = (use_raytracing_ || is_layer_refracted) &&
848 (!is_last_pass || use_screen_reflection_);
849
850 /* Clear AOVs in case previous layers wrote to them. First pass always get clear buffer because
851 * of #BackgroundPipeline::clear(). */
852 if (inst_.film.aovs_info.color_len > 0 && !is_first_pass) {
853 clear_aovs_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
854 }
855
856 {
857 RenderBuffersInfoData &rbuf_data = inst_.render_buffers.data;
858
859 /* Add the stencil classification step at the end of the GBuffer pass. */
860 {
861 gpu::Shader *sh = inst_.shaders.static_shader_get(
863 PassMain::Sub &sub = gbuffer_ps_.sub("StencilClassify");
864 sub.subpass_transition(GPU_ATTACHMENT_WRITE, /* Needed for depth test. */
866 GPU_ATTACHMENT_READ, /* Header. */
870 sub.shader_set(sh);
872 /* Binding any buffer to satisfy the binding. The buffer is not actually used. */
873 sub.bind_ssbo("dummy_workaround_buf", &inst_.film.aovs_info);
874 }
877 /* The shader sets the stencil directly in one full-screen pass. */
878 sub.state_stencil(uint8_t(StencilBits::HEADER_BITS), /* Set by shader */ 0x0u, 0xFFu);
880 }
881 else {
882 /* The shader cannot set the stencil directly. So we do one full-screen pass for each
883 * stencil bit we need to set and accumulate the result. */
884 auto set_bit = [&](StencilBits bit) {
885 sub.push_constant("current_bit", int(bit));
886 sub.state_stencil(uint8_t(bit), 0xFFu, 0xFFu);
888 };
889
890 if (closure_count_ > 0) {
891 set_bit(StencilBits::CLOSURE_COUNT_0);
892 }
893 if (closure_count_ > 1) {
894 set_bit(StencilBits::CLOSURE_COUNT_1);
895 }
897 set_bit(StencilBits::TRANSMISSION);
898 }
899 }
900 }
901
902 {
903 PassSimple &pass = eval_light_ps_;
904 pass.init();
905
906 /* TODO(fclem): Could also skip if no material uses thickness from shadow. */
908 PassSimple::Sub &sub = pass.sub("Eval.ThicknessFromShadow");
909 sub.shader_set(inst_.shaders.static_shader_get(DEFERRED_THICKNESS_AMEND));
910 sub.bind_resources(inst_.lights);
911 sub.bind_resources(inst_.shadows);
912 sub.bind_resources(inst_.hiz_buffer.front);
913 sub.bind_resources(inst_.uniform_data);
914 sub.bind_resources(inst_.sampling);
915 sub.bind_texture("utility_tx", &inst_.pipelines.utility_tx);
916 sub.bind_texture("gbuf_header_tx", &inst_.gbuffer.header_tx);
917 sub.bind_image("gbuf_normal_img", &inst_.gbuffer.normal_tx);
919 /* Render where there is transmission and the thickness from shadow bit is set. */
920 uint8_t stencil_bits = uint8_t(StencilBits::TRANSMISSION) |
921 uint8_t(StencilBits::THICKNESS_FROM_SHADOW);
922 sub.state_stencil(0x0u, stencil_bits, stencil_bits);
925 }
926 {
927 const bool use_transmission = (closure_bits_ & CLOSURE_TRANSMISSION) != 0;
928 const bool use_split_indirect = do_split_direct_indirect_radiance(inst_);
929 const bool use_lightprobe_eval = do_merge_direct_indirect_eval(inst_);
930 PassSimple::Sub &sub = pass.sub("Eval.Light");
931 /* Use depth test to reject background pixels which have not been stencil cleared. */
932 /* WORKAROUND: Avoid rasterizer discard by enabling stencil write, but the shaders actually
933 * use no fragment output. */
935 sub.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
936 sub.bind_image(RBUFS_COLOR_SLOT, &inst_.render_buffers.rp_color_tx);
937 sub.bind_image(RBUFS_VALUE_SLOT, &inst_.render_buffers.rp_value_tx);
938 const ShadowSceneData &shadow_scene = inst_.shadows.get_data();
939 auto set_specialization_constants =
940 [&](PassSimple::Sub &sub, gpu::Shader *sh, bool use_transmission) {
941 sub.specialize_constant(sh, "render_pass_shadow_id", rbuf_data.shadow_id);
942 sub.specialize_constant(sh, "use_split_indirect", use_split_indirect);
943 sub.specialize_constant(sh, "use_lightprobe_eval", use_lightprobe_eval);
944 sub.specialize_constant(sh, "use_transmission", use_transmission);
945 sub.specialize_constant(sh, "shadow_ray_count", &shadow_scene.ray_count);
946 sub.specialize_constant(sh, "shadow_ray_step_count", &shadow_scene.step_count);
947 };
948 /* Submit the more costly ones first to avoid long tail in occupancy.
949 * See page 78 of "SIGGRAPH 2023: Unreal Engine Substrate" by Hillaire & de Rousiers. */
950
951 for (int i = min_ii(3, closure_count_) - 1; i >= 0; i--) {
952 gpu::Shader *sh = inst_.shaders.static_shader_get(
954 set_specialization_constants(sub, sh, false);
955 sub.shader_set(sh);
956 sub.bind_image("direct_radiance_imgs", &direct_radiance_txs_);
957 sub.bind_image("indirect_radiance_1_img", &indirect_result_.closures[0]);
958 sub.bind_image("indirect_radiance_2_img", &indirect_result_.closures[1]);
959 sub.bind_image("indirect_radiance_3_img", &indirect_result_.closures[2]);
960 sub.bind_resources(inst_.uniform_data);
961 sub.bind_resources(inst_.gbuffer);
962 sub.bind_resources(inst_.lights);
963 sub.bind_resources(inst_.shadows);
964 sub.bind_resources(inst_.sampling);
965 sub.bind_resources(inst_.hiz_buffer.front);
966 sub.bind_resources(inst_.sphere_probes);
967 sub.bind_resources(inst_.volume_probes);
968 uint8_t compare_mask = uint8_t(StencilBits::CLOSURE_COUNT_0) |
969 uint8_t(StencilBits::CLOSURE_COUNT_1) |
970 uint8_t(StencilBits::TRANSMISSION);
971 sub.state_stencil(0x0u, i + 1, compare_mask);
973 if (use_transmission) {
974 /* Separate pass for transmission BSDF as their evaluation is quite costly. */
975 set_specialization_constants(sub, sh, true);
976 sub.shader_set(sh);
977 sub.state_stencil(0x0u, (i + 1) | uint8_t(StencilBits::TRANSMISSION), compare_mask);
979 }
980 }
981 }
982 }
983 {
984 PassSimple &pass = combine_ps_;
985 pass.init();
986 gpu::Shader *sh = inst_.shaders.static_shader_get(DEFERRED_COMBINE);
987 /* TODO(fclem): Could specialize directly with the pass index but this would break it for
988 * OpenGL and Vulkan implementation which aren't fully supporting the specialize
989 * constant. */
990 pass.specialize_constant(sh,
991 "render_pass_diffuse_light_enabled",
992 (rbuf_data.diffuse_light_id != -1) ||
993 (rbuf_data.diffuse_color_id != -1));
994 pass.specialize_constant(sh,
995 "render_pass_specular_light_enabled",
996 (rbuf_data.specular_light_id != -1) ||
997 (rbuf_data.specular_color_id != -1));
998 pass.specialize_constant(sh, "use_split_radiance", use_split_radiance_);
1000 sh, "use_radiance_feedback", use_feedback_output_ && do_modify_radiance(inst_));
1001 pass.specialize_constant(sh, "render_pass_normal_enabled", rbuf_data.normal_id != -1);
1002 pass.specialize_constant(sh, "render_pass_position_enabled", rbuf_data.position_id != -1);
1004 sh, "render_passes_denoising_depth_enabled", rbuf_data.denoising_depth_id != -1);
1006 sh, "render_passes_denoising_normal_enabled", rbuf_data.denoising_normal_id != -1);
1008 sh, "render_passes_denoising_roughness_enabled", rbuf_data.denoising_roughness_id != -1);
1009 pass.specialize_constant(sh,
1010 "render_passes_denoising_diffuse_albedo_enabled",
1011 rbuf_data.denoising_diffuse_albedo_id != -1);
1012 pass.specialize_constant(sh,
1013 "render_passes_denoising_specular_albedo_enabled",
1014 rbuf_data.denoising_specular_albedo_id != -1);
1015 pass.specialize_constant(sh,
1016 "use_albedo_roughness_weighting",
1017 (inst_.view_layer->eevee.denoising_pass_flags &
1019 pass.shader_set(sh);
1020 /* Use stencil test to reject pixels not written by this layer. */
1022 /* Render where stencil is not 0. */
1023 pass.state_stencil(0x0u, 0x0u, uint8_t(StencilBits::HEADER_BITS));
1024 pass.bind_texture("direct_radiance_txs", &direct_radiance_txs_);
1025 pass.bind_texture("indirect_radiance_1_tx", &indirect_result_.closures[0]);
1026 pass.bind_texture("indirect_radiance_2_tx", &indirect_result_.closures[1]);
1027 pass.bind_texture("indirect_radiance_3_tx", &indirect_result_.closures[2]);
1028 pass.bind_image(RBUFS_COLOR_SLOT, &inst_.render_buffers.rp_color_tx);
1029 pass.bind_image(RBUFS_VALUE_SLOT, &inst_.render_buffers.rp_value_tx);
1030 pass.bind_image("radiance_feedback_img", &radiance_feedback_tx_);
1031 pass.bind_resources(inst_.gbuffer);
1032 pass.bind_resources(inst_.uniform_data);
1033 pass.bind_resources(inst_.hiz_buffer.front);
1035 pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
1036 }
1037 }
1038}
1039
1041 GPUMaterial *gpumat,
1042 bool has_motion,
1043 bool hide_from_raycast)
1044{
1045 return prepass_.add(blender_mat, gpumat, has_motion, hide_from_raycast);
1046}
1047
1049{
1050 eClosureBits closure_bits = shader_closure_bits_from_flag(gpumat);
1051 if (closure_bits == eClosureBits(0)) {
1052 /* Fix the case where there is no active closure in the shader.
1053 * In this case we force the evaluation of emission to avoid disabling the entire layer by
1054 * accident, see #126459. */
1055 closure_bits |= CLOSURE_EMISSION;
1056 }
1057 closure_bits_ |= closure_bits;
1059
1060 PassMain::Sub *pass = get_gbuffer_subpass(blender_mat, gpumat);
1061 PassMain::Sub *material_pass = &pass->sub(GPU_material_get_name(gpumat));
1062 /* Set stencil for some deferred specialized shaders. */
1063 uint8_t material_stencil_bits = 0u;
1064 if (blender_mat->blend_flag & MA_BL_THICKNESS_FROM_SHADOW) {
1065 material_stencil_bits |= uint8_t(StencilBits::THICKNESS_FROM_SHADOW);
1066 }
1067 /* We use this opportunity to clear the stencil bits. The undefined areas are discarded using the
1068 * gbuf header value. */
1069 material_pass->state_stencil(0xFFu, material_stencil_bits, 0xFFu);
1070
1071 return material_pass;
1072}
1073
1075 Framebuffer &prepass_fb,
1076 Framebuffer &combined_fb,
1077 Framebuffer &gbuffer_fb,
1078 int2 extent,
1079 RayTraceBuffer &rt_buffer,
1080 gpu::Texture *radiance_behind_tx)
1081{
1082 if (closure_count_ == 0) {
1083 return radiance_behind_tx;
1084 }
1085
1086 radiance_behind_tx_ = radiance_behind_tx ? radiance_behind_tx : dummy_black;
1087
1088 RenderBuffers &rb = inst_.render_buffers;
1089
1090 constexpr eGPUTextureUsage usage_read = GPU_TEXTURE_USAGE_SHADER_READ;
1091 constexpr eGPUTextureUsage usage_write = GPU_TEXTURE_USAGE_SHADER_WRITE;
1092 constexpr eGPUTextureUsage usage_rw = usage_read | usage_write;
1093
1094 if (use_screen_transmission_) {
1095 /* Update for refraction. */
1096 inst_.hiz_buffer.update();
1097 }
1098
1099 GPU_framebuffer_bind(prepass_fb);
1100 /* Clear stencil buffer so that prepass can tag it. Then draw a full-screen triangle that will
1101 * clear AOVs for all the pixels touched by this layer. */
1102 GPU_framebuffer_clear_stencil(prepass_fb, 0xFFu);
1103 prepass_.render(render_view, rb.depth_tx, true);
1104 if (!clear_aovs_ps_.is_empty()) {
1105 inst_.manager->submit(clear_aovs_ps_);
1106 }
1107
1108 inst_.hiz_buffer.swap_layer();
1109 /* Update for lighting pass or AO node. */
1110 inst_.hiz_buffer.update();
1111
1112 inst_.volume_probes.set_view(render_view);
1113 inst_.sphere_probes.set_view(render_view);
1114 inst_.shadows.render(render_view, extent);
1115
1116 inst_.gbuffer.bind(gbuffer_fb);
1117 inst_.manager->submit(gbuffer_ps_, render_view);
1118
1119 /* Only three layers of closures are ever written,. */
1120 direct_radiance_txs_.acquire_2d_array(
1121 extent, min_ii(closure_count_, 3), gpu::TextureFormat::DEFERRED_RADIANCE_FORMAT, usage_rw);
1122 direct_radiance_txs_.ensure_layer_views();
1123
1124 if (use_raytracing_) {
1125 indirect_result_ = inst_.raytracing.render(
1126 rt_buffer, radiance_behind_tx, closure_bits_, render_view);
1127 }
1128 else if (use_split_radiance_) {
1129 indirect_result_ = inst_.raytracing.alloc_only(rt_buffer);
1130 }
1131 else {
1132 indirect_result_ = inst_.raytracing.alloc_dummy(rt_buffer);
1133 }
1134
1135 GPU_framebuffer_bind(combined_fb);
1136 inst_.manager->submit(eval_light_ps_, render_view);
1137
1138 inst_.subsurface.render(
1139 direct_radiance_txs_, indirect_result_.closures[0], closure_bits_, render_view);
1140
1141 radiance_feedback_tx_ = rt_buffer.feedback_ensure(!use_feedback_output_, extent);
1142
1143 const bool modify_radiance = do_modify_radiance(inst_);
1144
1145 if (use_feedback_output_ && modify_radiance) {
1146 /* We need to do a copy before the combine pass (otherwise we have a dependency issue) to save
1147 * the emission and the previous layer's radiance. */
1148 GPU_texture_copy(radiance_feedback_tx_, rb.combined_tx);
1149 }
1150
1151 GPU_framebuffer_bind(combined_fb);
1152 inst_.manager->submit(combine_ps_, render_view);
1153
1154 if (use_feedback_output_ && !modify_radiance) {
1155 /* We skip writing the radiance during the combine pass. Do a simple fast copy. */
1156 GPU_texture_copy(radiance_feedback_tx_, rb.combined_tx);
1157 }
1158
1159 indirect_result_.release();
1160 direct_radiance_txs_.release();
1161
1162 inst_.pipelines.deferred.debug_draw(render_view, combined_fb);
1163
1164 return use_feedback_output_ ? radiance_feedback_tx_ : nullptr;
1165}
1166
1168
1169/* -------------------------------------------------------------------- */
1174
1176{
1177 opaque_layer_.begin_sync();
1178 refraction_layer_.begin_sync();
1179}
1180
1182{
1183 Instance &inst = opaque_layer_.inst_;
1184
1185 opaque_layer_.end_sync(true, refraction_layer_.is_empty(), refraction_layer_.has_transmission());
1186 refraction_layer_.end_sync(opaque_layer_.is_empty(), true, false);
1187
1189
1190 debug_pass_sync();
1191}
1192
1193void DeferredPipeline::debug_pass_sync()
1194{
1195 Instance &inst = opaque_layer_.inst_;
1196 if (!ELEM(inst.debug_mode,
1199 {
1200 return;
1201 }
1202
1203 PassSimple &pass = debug_draw_ps_;
1204 pass.init();
1207 pass.push_constant("debug_mode", int(inst.debug_mode));
1208 pass.bind_resources(inst.gbuffer);
1209 pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
1210}
1211
1213{
1214 Instance &inst = opaque_layer_.inst_;
1215 if (!ELEM(inst.debug_mode,
1218 {
1219 return;
1220 }
1221
1222 switch (inst.debug_mode) {
1224 inst.info_append("Debug Mode: Deferred Lighting Cost");
1225 break;
1227 inst.info_append("Debug Mode: Gbuffer Storage Cost");
1228 break;
1229 default:
1230 /* Nothing to display. */
1231 return;
1232 }
1233
1234 GPU_framebuffer_bind(combined_fb);
1235 inst.manager->submit(debug_draw_ps_, view);
1236}
1237
1239 GPUMaterial *gpumat,
1240 bool has_motion,
1241 bool hide_from_raycast)
1242{
1243 if (blender_mat->blend_flag & MA_BL_SS_REFRACTION) {
1244 return refraction_layer_.prepass_add(blender_mat, gpumat, has_motion, hide_from_raycast);
1245 }
1246 return opaque_layer_.prepass_add(blender_mat, gpumat, has_motion, hide_from_raycast);
1247}
1248
1250{
1251 if (blender_mat->blend_flag & MA_BL_SS_REFRACTION) {
1252 return refraction_layer_.material_add(blender_mat, gpumat);
1253 }
1254 return opaque_layer_.material_add(blender_mat, gpumat);
1255}
1256
1257void DeferredPipeline::render(View & /*main_view*/,
1258 View &render_view,
1259 Framebuffer &prepass_fb,
1260 Framebuffer &combined_fb,
1261 Framebuffer &gbuffer_fb,
1262 int2 extent,
1263 RayTraceBuffer &rt_buffer_opaque_layer,
1264 RayTraceBuffer &rt_buffer_refract_layer)
1265{
1266 gpu::Texture *feedback_tx = nullptr;
1267
1268 GPU_debug_group_begin("Deferred.Opaque");
1269 feedback_tx = opaque_layer_.render(render_view,
1270 prepass_fb,
1271 combined_fb,
1272 gbuffer_fb,
1273 extent,
1274 rt_buffer_opaque_layer,
1275 feedback_tx);
1277
1278 GPU_debug_group_begin("Deferred.Refract");
1279 feedback_tx = refraction_layer_.render(render_view,
1280 prepass_fb,
1281 combined_fb,
1282 gbuffer_fb,
1283 extent,
1284 rt_buffer_refract_layer,
1285 feedback_tx);
1287}
1288
1290
1291/* -------------------------------------------------------------------- */
1295
1297{
1298 object_bounds_.clear();
1299 combined_screen_bounds_ = std::nullopt;
1300 use_hit_list = false;
1301 is_empty = true;
1302 finalized = false;
1303 has_scatter = false;
1304 has_absorption = false;
1305
1306 draw::PassMain &layer_pass = volume_layer_ps_;
1307 layer_pass.init();
1308 layer_pass.clear_stencil(0x0u);
1309 {
1310 PassMain::Sub &pass = layer_pass.sub("occupancy_ps");
1311 /* Always double sided to let all fragments be invoked. */
1313 pass.bind_resources(inst_.uniform_data);
1314 pass.bind_resources(inst_.volume.occupancy);
1315 pass.bind_resources(inst_.sampling);
1316 occupancy_ps_ = &pass;
1317 }
1318 {
1319 PassMain::Sub &pass = layer_pass.sub("material_ps");
1320 /* Double sided with stencil equal to ensure only one fragment is invoked per pixel. */
1322 pass.state_stencil(0x1u, 0x1u, 0x1u);
1324 pass.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
1325 pass.bind_resources(inst_.uniform_data);
1326 pass.bind_resources(inst_.volume.properties);
1327 pass.bind_resources(inst_.sampling);
1328 material_ps_ = &pass;
1329 }
1330}
1331
1333 const blender::Material *blender_mat,
1334 GPUMaterial *gpumat)
1335{
1337 "Only volume material should be added here");
1338 bool use_fast_occupancy = (ob->type == OB_VOLUME) ||
1339 (blender_mat->volume_intersection_method == MA_VOLUME_ISECT_FAST);
1340 use_hit_list |= !use_fast_occupancy;
1341 is_empty = false;
1342
1343 PassMain::Sub *pass = &occupancy_ps_->sub(GPU_material_get_name(gpumat));
1344 pass->material_set(*inst_.manager, gpumat, true, inst_.anisotropic_filtering);
1345 pass->push_constant("use_fast_method", use_fast_occupancy);
1346 return pass;
1347}
1348
1350 const blender::Material * /*blender_mat*/,
1351 GPUMaterial *gpumat)
1352{
1354 "Only volume material should be added here");
1356
1357 PassMain::Sub *pass = &material_ps_->sub(GPU_material_get_name(gpumat));
1358 pass->material_set(*inst_.manager, gpumat, true, inst_.anisotropic_filtering);
1360 has_scatter = true;
1361 }
1363 has_absorption = true;
1364 }
1365 return pass;
1366}
1367
1368bool VolumeLayer::bounds_overlaps(const VolumeObjectBounds &object_bounds) const
1369{
1370 /* First check the biggest area. */
1371 if (bounds::intersect(object_bounds.screen_bounds, combined_screen_bounds_)) {
1372 return true;
1373 }
1374 /* Check against individual bounds to try to squeeze the new object between them. */
1375 for (const std::optional<Bounds<float2>> &other_aabb : object_bounds_) {
1376 if (bounds::intersect(object_bounds.screen_bounds, other_aabb)) {
1377 return true;
1378 }
1379 }
1380 return false;
1381}
1382
1384{
1385 object_bounds_.append(object_bounds.screen_bounds);
1386 combined_screen_bounds_ = bounds::merge(combined_screen_bounds_, object_bounds.screen_bounds);
1387}
1388
1389void VolumeLayer::render(View &view, Texture &occupancy_tx)
1390{
1391 if (is_empty) {
1392 return;
1393 }
1394 if (finalized == false) {
1395 finalized = true;
1396 if (use_hit_list) {
1397 /* Add resolve pass only when needed. Insert after occupancy, before material pass. */
1398 occupancy_ps_->shader_set(inst_.shaders.static_shader_get(VOLUME_OCCUPANCY_CONVERT));
1399 occupancy_ps_->barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
1400 occupancy_ps_->draw_procedural(GPU_PRIM_TRIS, 1, 3);
1401 }
1402 }
1403 /* TODO(fclem): Move this clear inside the render pass. */
1404 occupancy_tx.clear(uint4(0u));
1405 inst_.manager->submit(volume_layer_ps_, view);
1406}
1407
1409
1410/* -------------------------------------------------------------------- */
1413
1415{
1416 object_integration_range_ = std::nullopt;
1417 has_scatter_ = false;
1418 has_absorption_ = false;
1419 for (auto &layer : layers_) {
1420 layer->sync();
1421 }
1422}
1423
1424void VolumePipeline::render(View &view, Texture &occupancy_tx)
1425{
1426 for (auto &layer : layers_) {
1427 layer->render(view, occupancy_tx);
1428 }
1429}
1430
1432 const ObjectHandle &ob_handle,
1433 int instance_index)
1434{
1435 /* TODO(fclem): For panoramic camera, we will have to do this check for each cube-face. */
1436 const float4x4 &view_matrix = camera.data_get().viewmat;
1437 /* Note in practice we only care about the projection type since we only care about 2D overlap,
1438 * and this is independent of FOV. */
1439 const float4x4 &projection_matrix = camera.data_get().winmat;
1440
1441 const Bounds<float3> bounds =
1442 BKE_object_boundbox_get(ob_handle.object).value_or(Bounds(float3(0.0f)));
1443
1444 const std::array<float3, 8> corners = bounds::corners(bounds);
1445
1446 screen_bounds = std::nullopt;
1447 z_range = std::nullopt;
1448
1449 for (const float3 &l_corner : corners) {
1450 float3 ws_corner = math::transform_point(ob_handle.object_to_world(instance_index), l_corner);
1451 /* Split view and projection for precision. */
1452 float3 vs_corner = math::transform_point(view_matrix, ws_corner);
1453 float3 ss_corner = math::project_point(projection_matrix, vs_corner);
1454
1455 z_range = bounds::min_max(z_range, vs_corner.z);
1456 if (camera.is_perspective() && vs_corner.z >= 1.0e-8f) {
1457 /* If the object is crossing the z=0 plane, we can't determine its 2D bounds easily.
1458 * In this case, consider the object covering the whole screen.
1459 * Still continue the loop for the Z range. */
1460 screen_bounds = Bounds<float2>(float2(-1.0f), float2(1.0f));
1461 }
1462 else {
1463 screen_bounds = bounds::min_max(screen_bounds, ss_corner.xy());
1464 }
1465 }
1466}
1467
1469{
1470 if (math::reduce_max(object_bounds.screen_bounds->size()) < 1e-5) {
1471 /* WORKAROUND(fclem): Fixes an issue with 0 scaled object (see #132889).
1472 * Is likely to be an issue somewhere else in the pipeline but it is hard to find. */
1473 return nullptr;
1474 }
1475
1476 object_integration_range_ = bounds::merge(object_integration_range_, object_bounds.z_range);
1477
1478 /* Do linear search in all layers in order. This can be optimized. */
1479 for (auto &layer : layers_) {
1480 if (!layer->bounds_overlaps(object_bounds)) {
1481 layer->add_object_bound(object_bounds);
1482 return layer.get();
1483 }
1484 }
1485 /* No non-overlapping layer found. Create new one. */
1486 int64_t index = layers_.append_and_get_index(std::make_unique<VolumeLayer>(inst_));
1487 (*layers_[index]).add_object_bound(object_bounds);
1488 return layers_[index].get();
1489}
1490
1491std::optional<Bounds<float>> VolumePipeline::object_integration_range() const
1492{
1493 return object_integration_range_;
1494}
1495
1497{
1498 for (const auto &layer : layers_) {
1499 if (layer->use_hit_list) {
1500 return true;
1501 }
1502 }
1503 return false;
1504}
1505
1507
1508/* -------------------------------------------------------------------- */
1513
1515{
1516 opaque_layer_.prepass_.init({}, false);
1517
1518 opaque_layer_.gbuffer_pass_sync(inst_);
1519}
1520
1522{
1523 opaque_layer_.prepass_.end_sync();
1524 if (!opaque_layer_.gbuffer_ps_.is_empty()) {
1525 PassSimple &pass = eval_light_ps_;
1526 pass.init();
1527 /* Use depth test to reject background pixels. */
1529 pass.shader_set(inst_.shaders.static_shader_get(DEFERRED_CAPTURE_EVAL));
1530 pass.bind_image(RBUFS_COLOR_SLOT, &inst_.render_buffers.rp_color_tx);
1531 pass.bind_image(RBUFS_VALUE_SLOT, &inst_.render_buffers.rp_value_tx);
1532 pass.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
1533 pass.bind_resources(inst_.uniform_data);
1534 pass.bind_resources(inst_.gbuffer);
1535 pass.bind_resources(inst_.lights);
1536 pass.bind_resources(inst_.shadows);
1537 pass.bind_resources(inst_.sampling);
1538 pass.bind_resources(inst_.hiz_buffer.front);
1539 pass.bind_resources(inst_.volume_probes);
1541 pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
1542 }
1543}
1544
1546 GPUMaterial *gpumat,
1547 bool hide_from_raycast)
1548{
1549 return opaque_layer_.prepass_.add(blender_mat, gpumat, false, hide_from_raycast);
1550}
1551
1553 GPUMaterial *gpumat)
1554{
1555 eClosureBits closure_bits = shader_closure_bits_from_flag(gpumat);
1556 if (closure_bits == eClosureBits(0)) {
1557 /* Fix the case where there is no active closure in the shader.
1558 * In this case we force the evaluation of emission to avoid disabling the entire layer by
1559 * accident, see #126459. */
1560 closure_bits |= CLOSURE_EMISSION;
1561 }
1562 opaque_layer_.closure_bits_ |= closure_bits;
1563 opaque_layer_.closure_count_ = max_ii(opaque_layer_.closure_count_, count_bits_i(closure_bits));
1564
1565 PassMain::Sub *pass = opaque_layer_.get_gbuffer_subpass(blender_mat, gpumat);
1566 return &pass->sub(GPU_material_get_name(gpumat));
1567}
1568
1570 Framebuffer &prepass_fb,
1571 Framebuffer &combined_fb,
1572 Framebuffer &gbuffer_fb,
1573 int2 extent)
1574{
1575 GPU_debug_group_begin("Probe.Render");
1576
1577 opaque_layer_.radiance_behind_tx_ = dummy_black;
1578
1579 prepass_fb.bind();
1580 prepass_fb.clear_depth(inst_.film.depth.clear_value);
1581 prepass_fb.clear_color(float4(0.0f));
1582 opaque_layer_.prepass_.render(view, inst_.render_buffers.depth_tx, true);
1583
1584 inst_.hiz_buffer.set_source(&inst_.render_buffers.depth_tx);
1585 inst_.hiz_buffer.update();
1586
1587 inst_.lights.set_view(view, extent);
1588 inst_.shadows.render(view, extent);
1589 inst_.volume_probes.set_view(view);
1590 inst_.sphere_probes.set_view(view);
1591
1592 /* Update for lighting pass. */
1593 inst_.hiz_buffer.update();
1594
1595 inst_.gbuffer.bind(gbuffer_fb);
1596 inst_.manager->submit(opaque_layer_.gbuffer_ps_, view);
1597
1598 combined_fb.bind();
1599 inst_.manager->submit(eval_light_ps_, view);
1600
1602}
1603
1605
1606/* -------------------------------------------------------------------- */
1610
1612{
1613 prepass_.init(DRW_STATE_NO_DRAW, false, true, [&](PassMain &pass) {
1614 pass.bind_ubo(CLIP_PLANE_BUF, inst_.planar_probes.world_clip_buf_);
1615 });
1616
1617 this->gbuffer_pass_sync(inst_);
1618
1620 closure_count_ = 0;
1621}
1622
1624{
1626 if (!gbuffer_ps_.is_empty()) {
1627 PassSimple &pass = eval_light_ps_;
1628 pass.init();
1630 pass.shader_set(inst_.shaders.static_shader_get(DEFERRED_PLANAR_EVAL));
1631 pass.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
1632 pass.bind_resources(inst_.uniform_data);
1633 pass.bind_resources(inst_.gbuffer);
1634 pass.bind_resources(inst_.lights);
1635 pass.bind_resources(inst_.shadows);
1636 pass.bind_resources(inst_.sampling);
1637 pass.bind_resources(inst_.hiz_buffer.front);
1638 pass.bind_resources(inst_.sphere_probes);
1639 pass.bind_resources(inst_.volume_probes);
1641 pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
1642 }
1643}
1644
1646 GPUMaterial *gpumat,
1647 bool hide_from_raycast)
1648{
1649 return prepass_.add(blender_mat, gpumat, false, hide_from_raycast);
1650}
1651
1653 GPUMaterial *gpumat)
1654{
1655 eClosureBits closure_bits = shader_closure_bits_from_flag(gpumat);
1656 if (closure_bits == eClosureBits(0)) {
1657 /* Fix the case where there is no active closure in the shader.
1658 * In this case we force the evaluation of emission to avoid disabling the entire layer by
1659 * accident, see #126459. */
1660 closure_bits |= CLOSURE_EMISSION;
1661 }
1662 closure_bits_ |= closure_bits;
1664
1665 PassMain::Sub *pass = get_gbuffer_subpass(blender_mat, gpumat);
1666 return &pass->sub(GPU_material_get_name(gpumat));
1667}
1668
1670 gpu::Texture *depth_layer_tx,
1671 Framebuffer &prepass_fb,
1672 Framebuffer &gbuffer_fb,
1673 Framebuffer &combined_fb,
1674 int2 extent)
1675{
1676 GPU_debug_group_begin("Planar.Capture");
1677
1678 radiance_behind_tx_ = dummy_black_;
1679
1680 inst_.pipelines.data.ray_type = RAY_TYPE_GLOSSY;
1681 inst_.uniform_data.pipeline.push_update();
1682
1683 GPU_framebuffer_bind(prepass_fb);
1684 GPU_framebuffer_clear_depth(prepass_fb, inst_.film.depth.clear_value);
1685 prepass_.render(view, depth_layer_tx, true);
1686
1687 /* TODO(fclem): This is the only place where we use the layer source to HiZ.
1688 * This is because the texture layer view is still a layer texture. */
1689 inst_.hiz_buffer.set_source(&depth_layer_tx, 0);
1690 inst_.hiz_buffer.update();
1691
1692 inst_.lights.set_view(view, extent);
1693 inst_.shadows.render(view, extent);
1694 inst_.volume_probes.set_view(view);
1695 inst_.sphere_probes.set_view(view);
1696
1697 inst_.gbuffer.bind(gbuffer_fb, true);
1698 inst_.manager->submit(gbuffer_ps_, view);
1699
1700 GPU_framebuffer_bind(combined_fb);
1701 inst_.manager->submit(eval_light_ps_, view);
1702
1703 inst_.pipelines.data.ray_type = RAY_TYPE_CAMERA;
1704 inst_.uniform_data.pipeline.push_update();
1705
1707}
1708
1710
1711/* -------------------------------------------------------------------- */
1715
1717{
1718 surface_ps_.init();
1719 /* Surfel output is done using a SSBO, so no need for a fragment shader output color or depth. */
1720 /* WORKAROUND: Avoid rasterizer discard, but the shaders actually use no fragment output. */
1721 surface_ps_.state_set(DRW_STATE_WRITE_STENCIL);
1722 surface_ps_.framebuffer_set(&inst_.volume_probes.bake.empty_raster_fb_);
1723
1724 surface_ps_.bind_ssbo(SURFEL_BUF_SLOT, &inst_.volume_probes.bake.surfels_buf_);
1725 surface_ps_.bind_ssbo(CAPTURE_BUF_SLOT, &inst_.volume_probes.bake.capture_info_buf_);
1726
1727 surface_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
1728 /* TODO(fclem): Remove. Bind to get the camera data,
1729 * but there should be no view dependent behavior during capture. */
1730 surface_ps_.bind_resources(inst_.uniform_data);
1731}
1732
1734 blender::Material *blender_mat,
1735 GPUMaterial *gpumat)
1736{
1737 if (pointcloud_is_gsplat(ob)) {
1738 /* GSplat objects are not currently supported by volume probe captures, so we do not sync. */
1739 return nullptr;
1740 }
1741
1742 PassMain::Sub &sub_pass = surface_ps_.sub(GPU_material_get_name(gpumat));
1743 GPUPass *gpupass = GPU_material_get_pass(gpumat);
1744 sub_pass.shader_set(GPU_pass_shader_get(gpupass));
1745 sub_pass.push_constant("is_double_sided",
1746 bool(blender_mat->blend_flag & MA_BL_LIGHTPROBE_VOLUME_DOUBLE_SIDED));
1747 return &sub_pass;
1748}
1749
1751{
1752 inst_.manager->submit(surface_ps_, view);
1753}
1754
1756
1757} // namespace blender::eevee
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
void ensure(GPUAttachment depth=GPU_ATTACHMENT_NONE, GPUAttachment color1=GPU_ATTACHMENT_NONE, GPUAttachment color2=GPU_ATTACHMENT_NONE, GPUAttachment color3=GPU_ATTACHMENT_NONE, GPUAttachment color4=GPU_ATTACHMENT_NONE, GPUAttachment color5=GPU_ATTACHMENT_NONE, GPUAttachment color6=GPU_ATTACHMENT_NONE, GPUAttachment color7=GPU_ATTACHMENT_NONE, GPUAttachment color8=GPU_ATTACHMENT_NONE)
void submit(PassSimple &pass, View &view)
float4x4 object_to_world(int instance_index) const
bool acquire_2d(int2 extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
void clear(float4 values)
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 clear_stencil(uint8_t stencil)
void specialize_constant(gpu::Shader *shader, const char *name, const float &data)
void subpass_transition(GPUAttachmentState depth_attachment, Span< GPUAttachmentState > color_attachments)
void bind_image(const char *name, gpu::Texture *image)
PassBase< DrawCommandBufType > & sub(const char *name)
Definition draw_pass.hh:701
void submit(command::RecordingState &state) const
Definition draw_pass.hh:764
void state_set(DRWState state, int clip_plane_count=0)
void barrier(GPUBarrier type)
void state_stencil(uint8_t write_mask, uint8_t reference, uint8_t compare_mask)
void bind_ubo(const char *name, gpu::UniformBuf *buffer)
void push_constant(const char *name, const float &data)
void bind_ssbo(const char *name, gpu::StorageBuf *buffer)
detail::PassBase< command::DrawCommandBuf > Sub
Definition draw_pass.hh:509
void render(View &view, Framebuffer &combined_fb)
void sync(GPUMaterial *gpumat, float background_opacity, float background_blur)
PassMain::Sub * surface_material_add(Object *ob, blender::Material *blender_mat, GPUMaterial *gpumat)
gpu::Texture * render(View &render_view, Framebuffer &prepass_fb, Framebuffer &combined_fb, Framebuffer &gbuffer_fb, int2 extent, RayTraceBuffer &rt_buffer, gpu::Texture *radiance_behind_tx)
PassMain::Sub * prepass_add(blender::Material *blender_mat, GPUMaterial *gpumat, bool has_motion, bool hide_from_raycast)
void end_sync(bool is_first_pass, bool is_last_pass, bool next_layer_has_transmission)
PassMain::Sub * material_add(blender::Material *blender_mat, GPUMaterial *gpumat)
static bool do_merge_direct_indirect_eval(const Instance &inst)
static bool do_split_direct_indirect_radiance(const Instance &inst)
static bool do_modify_radiance(const Instance &inst)
PassMain::Sub * material_add(blender::Material *blender_mat, GPUMaterial *gpumat)
PassMain::Sub * prepass_add(blender::Material *blender_mat, GPUMaterial *gpumat, bool has_motion, bool hide_from_raycast)
void debug_draw(draw::View &view, gpu::FrameBuffer *combined_fb)
void render(View &main_view, View &render_view, Framebuffer &prepass_fb, Framebuffer &combined_fb, Framebuffer &gbuffer_fb, int2 extent, RayTraceBuffer &rt_buffer_opaque_layer, RayTraceBuffer &rt_buffer_refract_layer)
void render(View &view, Framebuffer &prepass_fb, Framebuffer &combined_fb, Framebuffer &gbuffer_fb, int2 extent)
PassMain::Sub * material_add(blender::Material *blender_mat, GPUMaterial *gpumat)
PassMain::Sub * prepass_add(blender::Material *blender_mat, GPUMaterial *gpumat, bool hide_from_raycast)
void transparent_add(const Object *ob, const float3 &ob_location, blender::Material *blender_mat, GPUMaterial *gpumat, PassMain::Sub *&r_prepass_subpass, PassMain::Sub *&r_material_subpass)
PassMain::Sub * prepass_opaque_add(blender::Material *blender_mat, GPUMaterial *gpumat, bool has_motion)
void render(View &view, gpu::Texture *depth_tx, Framebuffer &prepass_fb, Framebuffer &transparent_fb, Framebuffer &combined_fb, int2 extent)
PassMain::Sub * material_opaque_add(const Object *ob, blender::Material *blender_mat, GPUMaterial *gpumat)
struct blender::eevee::HiZBuffer::@342214352322061324133130050175232001060230260232 back
struct blender::eevee::HiZBuffer::@342214352322061324133130050175232001060230260232 front
A running instance of the engine.
VolumeProbeModule volume_probes
SphereProbeModule sphere_probes
void info_append(const char *msg, Args &&...args)
PlanarProbeModule planar_probes
UniformDataModule uniform_data
struct blender::eevee::PlanarProbeModule::Dummy dummy_resources
PassMain::Sub * material_add(blender::Material *blender_mat, GPUMaterial *gpumat)
PassMain::Sub * prepass_add(blender::Material *blender_mat, GPUMaterial *gpumat, bool hide_from_raycast)
void render(View &view, gpu::Texture *depth_layer_tx, Framebuffer &prepass_fb, Framebuffer &gbuffer, Framebuffer &combined_fb, int2 extent)
void render(View &view, gpu::Texture *fb_depth_tx, bool can_raycast)
PassMain::Sub * add(blender::Material *blender_mat, GPUMaterial *gpumat, bool has_motion, bool hide_from_raycast)
void init(DRWState extra_state=DRW_STATE_NO_DRAW, bool supports_motion_vectors=true, bool supports_raycast_visibility=true, FunctionRef< void(PassMain &pass)> pass_setup_cb={})
static constexpr gpu::TextureFormat prepass_normal_format
static constexpr gpu::TextureFormat depth_format
static constexpr gpu::TextureFormat object_id_format
gpu::Shader * static_shader_get(eShaderType shader_type)
PassMain::Sub * surface_material_add(blender::Material *material, GPUMaterial *gpumat)
void add_object_bound(const VolumeObjectBounds &object_bounds)
void render(View &view, Texture &occupancy_tx)
bool bounds_overlaps(const VolumeObjectBounds &object_bounds) const
PassMain::Sub * occupancy_add(const Object *ob, const blender::Material *blender_mat, GPUMaterial *gpumat)
PassMain::Sub * material_add(const Object *ob, const blender::Material *blender_mat, GPUMaterial *gpumat)
std::optional< Bounds< float > > object_integration_range() const
VolumeLayer * register_and_get_layer(const VolumeObjectBounds &object_bounds)
void render(View &view, Texture &occupancy_tx)
void sync(GPUMaterial *gpumat)
virtual void init(const shader::ShaderCreateInfo &info, bool is_codegen_only)=0
#define RBUFS_UTILITY_TEX_SLOT
#define RADIANCE_PREVIOUS_LAYER_TEX_SLOT
#define HIZ_PREVIOUS_LAYER_TEX_SLOT
#define CAPTURE_BUF_SLOT
#define RBUFS_CRYPTOMATTE_SLOT
#define PIPELINE_BUF_SLOT
#define SHADOW_ATLAS_IMG_SLOT
#define SHADOW_RENDER_MAP_BUF_SLOT
#define OBJECT_ID_TEX_SLOT
#define RBUFS_VALUE_SLOT
#define RAYCAST_DEPTH_TEX_SLOT
#define RBUFS_COLOR_SLOT
#define PREPASS_NORMAL_TEX_SLOT
#define SHADOW_RENDER_VIEW_BUF_SLOT
#define SHADOW_PAGE_INFO_SLOT
#define CLIP_PLANE_BUF
#define SURFEL_BUF_SLOT
#define FLT_MAX
#define instance_index
#define layer
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
const int state
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
Definition BLI_bounds.hh:27
std::array< VecBase< T, 3 >, 8 > corners(const Bounds< VecBase< T, 3 > > &bounds)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
Definition BLI_bounds.hh:56
std::optional< Bounds< T > > intersect(const Bounds< T > &a, const Bounds< T > &b)
PassMain::Sub * volume_sub_pass(PassMain::Sub &ps, Scene *scene, Object *ob, GPUMaterial *gpu_material)
detail::Pass< command::DrawCommandBuf > PassSimple
detail::Pass< command::DrawMultiBuf > PassMain
bool pointcloud_is_gsplat(Object *ob)
@ DEFERRED_TILE_CLASSIFY_FALLBACK
T reduce_max(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
VectorT project_point(const MatT &mat, const VectorT &point)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
__int64 int64_t
Definition BKE_text.h:90
bool GPU_material_has_volume_output(GPUMaterial *mat)
VecBase< int32_t, 4 > int4
MINLINE int count_bits_i(unsigned int n)
VecBase< uint32_t, 4 > uint4
void GPU_texture_copy(gpu::Texture *dst, gpu::Texture *src)
@ GPU_MATFLAG_TRANSPARENT_MAYBE_COLORED
@ GPU_MATFLAG_HOLDOUT
@ GPU_MATFLAG_VOLUME_ABSORPTION
@ GPU_MATFLAG_IS_DIFFUSE_OR_GLOSSY_RAY_FLAG
@ GPU_MATFLAG_VOLUME_SCATTER
@ GPU_MATFLAG_RAYCAST
@ GPU_MATFLAG_TRANSPARENT
MINLINE int max_ii(int a, int b)
@ MA_BL_THICKNESS_FROM_SHADOW
@ MA_BL_LIGHTPROBE_VOLUME_DOUBLE_SIDED
@ GPU_MAT_SUCCESS
MatBase< float, 4, 4 > float4x4
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
VecBase< float, 4 > float4
gpu::Shader * GPU_pass_shader_get(GPUPass *pass)
Definition gpu_pass.cc:176
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_WRITE
@ GPU_TEXTURE_USAGE_ATTACHMENT
GPUPass * GPU_material_get_pass(GPUMaterial *material)
unsigned char uint8_t
Definition BKE_text.h:79
@ GPU_BARRIER_TEXTURE_FETCH
Definition GPU_state.hh:40
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition GPU_state.hh:38
@ DRW_STATE_CULL_BACK
Definition draw_state.hh:45
@ DRW_STATE_NO_DRAW
Definition draw_state.hh:29
@ DRW_STATE_CLIP_CONTROL_UNIT_RANGE
Definition draw_state.hh:71
@ DRW_STATE_BLEND_ADD_FULL
Definition draw_state.hh:55
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:32
@ DRW_STATE_STENCIL_ALWAYS
Definition draw_state.hh:48
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:31
@ DRW_STATE_BLEND_CUSTOM
Definition draw_state.hh:65
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:38
@ DRW_STATE_DEPTH_LESS
Definition draw_state.hh:39
@ DRW_STATE_WRITE_STENCIL
Definition draw_state.hh:34
@ DRW_STATE_STENCIL_EQUAL
Definition draw_state.hh:49
@ DRW_STATE_BLEND_TRANSPARENCY
Definition draw_state.hh:68
@ DRW_STATE_STENCIL_NEQUAL
Definition draw_state.hh:50
@ DRW_STATE_DEPTH_EQUAL
Definition draw_state.hh:41
void GPU_framebuffer_clear_depth(gpu::FrameBuffer *fb, float clear_depth)
void GPU_debug_group_end()
Definition gpu_debug.cc:34
MINLINE float square_f(float a)
bool GPU_stencil_export_support()
std::optional< Bounds< float3 > > BKE_object_boundbox_get(const Object *ob)
Definition object.cc:3726
@ EEVEE_DENOISING_PASS_USE_ALBEDO_ROUGHNESS_WEIGHTING
bool GPU_stencil_classify_buffer_workaround()
VecBase< float, 3 > float3
MINLINE int min_ii(int a, int b)
void GPU_framebuffer_clear_stencil(gpu::FrameBuffer *fb, uint clear_stencil)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
const char * GPU_material_get_name(GPUMaterial *material)
GPUMaterialStatus GPU_material_status(GPUMaterial *mat)
void GPU_debug_group_begin(const char *name)
Definition gpu_debug.cc:23
Bounds()=default
eObject_VisibilityFlag visibility_flag
void gbuffer_pass_sync(Instance &inst)
PassMain::Sub * gbuffer_subpasses_[2][2][2]
PassMain::Sub * get_gbuffer_subpass(blender::Material *blender_mat, GPUMaterial *gpumat)
void bind_optional_layers(PassType &pass)
gpu::Texture * feedback_ensure(bool is_dummy, int2 extent)
std::optional< Bounds< float2 > > screen_bounds
VolumeObjectBounds(const Camera &camera, const ObjectHandle &ob_handle, int instance_index)
std::optional< Bounds< float > > z_range