Share retained preview pass sequence helper

This commit is contained in:
2026-06-13 11:08:53 +02:00
parent cf3b8e856d
commit f513500b3c
6 changed files with 221 additions and 89 deletions

View File

@@ -130,4 +130,45 @@ struct LegacyNodeStrokePreviewMixPassRequest {
return plan;
}
struct LegacyNodeStrokePreviewPassSequenceRequest {
bool dual_pass_enabled = false;
std::function<void()> prepare_dual_pass;
std::function<void()> execute_dual_pass;
std::function<void()> capture_background;
std::function<void()> prepare_main_pass;
std::function<void()> execute_main_pass;
std::function<void()> finish_main_pass;
std::function<void()> execute_final_composite;
std::function<void()> copy_preview_result;
};
[[nodiscard]] inline bool execute_legacy_node_stroke_preview_pass_sequence(
const LegacyNodeStrokePreviewPassSequenceRequest& request)
{
if (!request.capture_background ||
!request.prepare_main_pass ||
!request.execute_main_pass ||
!request.finish_main_pass ||
!request.execute_final_composite ||
!request.copy_preview_result) {
return false;
}
if (request.dual_pass_enabled) {
if (!request.prepare_dual_pass || !request.execute_dual_pass) {
return false;
}
request.prepare_dual_pass();
request.execute_dual_pass();
}
request.capture_background();
request.prepare_main_pass();
request.execute_main_pass();
request.finish_main_pass();
request.execute_final_composite();
request.copy_preview_result();
return true;
}
} // namespace pp::panopainter

View File

@@ -797,102 +797,107 @@ void NodeStrokePreview::draw_stroke_immediate()
.set_opacity = false,
});
// DRAW DUAL BRUSH
if (material.dual_pass.enabled)
{
pp::panopainter::setup_legacy_stroke_dual_shader(material.dual_pass.uses_pattern);
bind_stroke_preview_dual_pass_textures(*dual_brush);
execute_stroke_preview_live_pass(
m_tex_dual,
size,
copy_stroke_destination,
[&] {
m_rtt.clear();
const bool sequence_ok = pp::panopainter::execute_legacy_node_stroke_preview_pass_sequence(
pp::panopainter::LegacyNodeStrokePreviewPassSequenceRequest {
.dual_pass_enabled = material.dual_pass.enabled,
.prepare_dual_pass = [&] {
pp::panopainter::setup_legacy_stroke_dual_shader(material.dual_pass.uses_pattern);
bind_stroke_preview_dual_pass_textures(*dual_brush);
},
[&] {
return stroke_draw_compute(m_dual_stroke, zoom);
.execute_dual_pass = [&] {
execute_stroke_preview_live_pass(
m_tex_dual,
size,
copy_stroke_destination,
[&] {
m_rtt.clear();
},
[&] {
return stroke_draw_compute(m_dual_stroke, zoom);
},
[](auto& frame) {
frame.col = { 0, 0, 0, 1 };
},
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
});
},
[](auto& frame) {
frame.col = { 0, 0, 0, 1 };
.capture_background = [&] {
execute_stroke_preview_background_capture_pass(
size,
b->m_tip_mix > 0.f || b->m_blend_mode != 0,
m_tex_background,
[&] {
m_plane.draw_fill();
});
},
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
});
}
.prepare_main_pass = [&] {
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_blend_uniforms(
material.stroke_pass.uses_pattern,
b->m_tip_mix,
b->m_tip_wet,
b->m_tip_noise);
// CHEKCERBOARD
bind_stroke_preview_main_pass_textures(
*b,
m_tex,
m_rtt_mixer,
copy_stroke_destination,
preview_composite_plan.uses_mixer);
},
.execute_main_pass = [&] {
execute_stroke_preview_live_pass(
m_tex,
size,
copy_stroke_destination,
[&] {
m_rtt.clear();
},
[&] {
return stroke_draw_compute(m_stroke, zoom);
},
[&](auto& frame) {
if (b->m_tip_mix > 0.f)
{
stroke_draw_mix(xy(frame.m_mixer_rect), zw(frame.m_mixer_rect));
}
execute_stroke_preview_background_capture_pass(
size,
b->m_tip_mix > 0.f || b->m_blend_mode != 0,
m_tex_background,
[&] {
m_plane.draw_fill();
});
// DRAW MAIN BRUSH
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_blend_uniforms(
material.stroke_pass.uses_pattern,
b->m_tip_mix,
b->m_tip_wet,
b->m_tip_noise);
bind_stroke_preview_main_pass_textures(
*b,
m_tex,
m_rtt_mixer,
copy_stroke_destination,
preview_composite_plan.uses_mixer);
execute_stroke_preview_live_pass(
m_tex,
size,
copy_stroke_destination,
[&] {
m_rtt.clear();
},
[&] {
return stroke_draw_compute(m_stroke, zoom);
},
[&](auto& frame) {
if (b->m_tip_mix > 0.f)
{
stroke_draw_mix(xy(frame.m_mixer_rect), zw(frame.m_mixer_rect));
}
frame.col = b->m_blend_mode != 0 || b->m_tip_mix > 0.f ?
glm::vec4 { .7, .4, .1, 1 } :
glm::vec4 { 0, 0, 0, 1 };
frame.flow = glm::max(frame.flow, m_min_flow);
},
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
});
set_active_texture_unit(stroke_preview_live_slots::kMixer);
m_rtt_mixer.unbindTexture();
// COMPOSITE
execute_stroke_preview_final_composite_pass(
StrokePreviewCompositePassInputs {
.resolution = size,
.pattern_scale = patt_scale,
.brush = *b,
.composite_pass = material.composite_pass,
.background_texture = m_tex_background,
.stroke_texture = m_tex,
.dual_texture = m_tex_dual,
.linear_sampler = m_sampler_linear,
.repeat_sampler = m_sampler_linear_repeat,
.draw_composite = [&] {
m_plane.draw_fill();
frame.col = b->m_blend_mode != 0 || b->m_tip_mix > 0.f ?
glm::vec4 { .7, .4, .1, 1 } :
glm::vec4 { 0, 0, 0, 1 };
frame.flow = glm::max(frame.flow, m_min_flow);
},
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
});
},
.finish_main_pass = [&] {
set_active_texture_unit(stroke_preview_live_slots::kMixer);
m_rtt_mixer.unbindTexture();
},
.execute_final_composite = [&] {
execute_stroke_preview_final_composite_pass(
StrokePreviewCompositePassInputs {
.resolution = size,
.pattern_scale = patt_scale,
.brush = *b,
.composite_pass = material.composite_pass,
.background_texture = m_tex_background,
.stroke_texture = m_tex,
.dual_texture = m_tex_dual,
.linear_sampler = m_sampler_linear,
.repeat_sampler = m_sampler_linear_repeat,
.draw_composite = [&] {
m_plane.draw_fill();
},
});
},
.copy_preview_result = [&] {
copy_stroke_preview_result_to_texture(m_tex_preview, size);
},
});
// copy the result to the actual preview
copy_stroke_preview_result_to_texture(m_tex_preview, size);
assert(sequence_ok);
m_rtt.unbindFramebuffer();