From 945f7f5e2348c1663acf23799750b83f87125bd8 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Fri, 26 Jul 2024 10:29:00 +0300 Subject: [PATCH] Fix: Grease Pencil not visible when using compositor Grease Pencil objects are not visible when using the viewport compositor. That's because since the introduction of multi-pass compositing, the compositor now access the combined pass written by EEVEE, which does not include GP. To fix this, we skip writing the EEVEE combined pass, then read the viewport texture for the combined pass as a special case, which should include GP. --- .../engines/compositor/compositor_engine.cc | 18 +++++++++++++----- .../draw/engines/eevee_next/eevee_film.cc | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc index 4223447867e..f8f0ae3dadb 100644 --- a/source/blender/draw/engines/compositor/compositor_engine.cc +++ b/source/blender/draw/engines/compositor/compositor_engine.cc @@ -146,17 +146,25 @@ class Context : public realtime_compositor::Context { return nullptr; } + /* The combined pass is a special case where we return the viewport color texture, because it + * includes Grease Pencil objects since GP is drawn using their own engine. */ + if (STREQ(pass_name, RE_PASSNAME_COMBINED)) { + return DRW_viewport_texture_list_get()->color; + } + + /* Return the pass that was written by the engine if such pass was found. */ GPUTexture *pass_texture = DRW_viewport_pass_texture_get(pass_name).gpu_texture(); if (pass_texture) { return pass_texture; } - if (STREQ(pass_name, RE_PASSNAME_COMBINED)) { - return get_output_texture(); - } - else { - return nullptr; + /* If no Z pass was found above, return the viewport depth as a fallback, which might be + * populated if overlays are enabled. */ + if (STREQ(pass_name, RE_PASSNAME_Z)) { + return DRW_viewport_texture_list_get()->depth; } + + return nullptr; } StringRef get_view_name() const override diff --git a/source/blender/draw/engines/eevee_next/eevee_film.cc b/source/blender/draw/engines/eevee_next/eevee_film.cc index bba93a21b40..e3dfd36a55d 100644 --- a/source/blender/draw/engines/eevee_next/eevee_film.cc +++ b/source/blender/draw/engines/eevee_next/eevee_film.cc @@ -917,6 +917,13 @@ void Film::write_viewport_compositor_passes() continue; } + /* The compositor will use the viewport color texture as the combined pass because the viewport + * texture will include Grease Pencil, so no need to write the combined pass from the engine + * side. */ + if (pass_type == EEVEE_RENDER_PASS_COMBINED) { + continue; + } + Vector pass_names = Film::pass_to_render_pass_names(pass_type, inst_.view_layer); for (const int64_t pass_offset : IndexRange(pass_names.size())) { GPUTexture *pass_texture = this->get_pass_texture(pass_type, pass_offset);