Isolate legacy stroke shader setup

This commit is contained in:
2026-06-12 22:35:07 +02:00
parent 33f21e0a1b
commit 6c58b6bb5d
5 changed files with 262 additions and 75 deletions

View File

@@ -7,6 +7,7 @@
#include "canvas.h"
#include "app.h"
#include "legacy_canvas_stroke_execution_services.h"
#include "legacy_canvas_stroke_shader_services.h"
#include "legacy_canvas_stroke_services.h"
#include "legacy_ui_gl_dispatch.h"
#include "paint_renderer/compositor.h"
@@ -439,36 +440,36 @@ void NodeStrokePreview::draw_stroke_immediate()
if (b->m_pattern_flipy) patt_scale.y *= -1.f;
apply_stroke_preview_capability(pp::renderer::gl::blend_state(), false);
ShaderManager::use(kShader::Stroke);
ShaderManager::u_int(kShaderUniform::Tex, 0); // brush
const auto stroke_feedback = stroke_preview_destination_feedback_plan(m_rtt.getWidth(), m_rtt.getHeight());
const bool copy_stroke_destination = !stroke_feedback.reads_destination_color;
const auto material = stroke_preview_material_plan(*b, copy_stroke_destination);
if (copy_stroke_destination)
ShaderManager::u_int(kShaderUniform::TexBG, 1); // bg
ShaderManager::u_int(kShaderUniform::TexPattern, 2); // pattern
ShaderManager::u_int(kShaderUniform::TexMix, 3); // mixer
//ShaderManager::u_int(kShaderUniform::TexMixA, 4); // mixer
ShaderManager::u_vec2(kShaderUniform::Resolution, size);
ShaderManager::u_vec2(kShaderUniform::PatternScale, patt_scale);
ShaderManager::u_float(kShaderUniform::PatternInvert, b->m_pattern_invert);
ShaderManager::u_float(kShaderUniform::PatternBright, b->m_pattern_brightness);
ShaderManager::u_float(kShaderUniform::PatternContrast, b->m_pattern_contrast);
ShaderManager::u_float(kShaderUniform::PatternDepth, b->m_pattern_depth);
ShaderManager::u_int(kShaderUniform::PatternBlendMode, b->m_pattern_blend_mode);
ShaderManager::u_vec2(kShaderUniform::PatternOffset, glm::vec2(b->m_pattern_rand_offset ? 0.5f : 0.0f));
ShaderManager::u_mat4(kShaderUniform::MVP, ortho_proj);
pp::panopainter::setup_legacy_stroke_shader(
pp::panopainter::LegacyStrokeShaderSetupUniforms {
.resolution = size,
.pattern = {
.scale = patt_scale,
.invert = static_cast<float>(b->m_pattern_invert),
.brightness = b->m_pattern_brightness,
.contrast = b->m_pattern_contrast,
.depth = b->m_pattern_depth,
.blend_mode = b->m_pattern_blend_mode,
.offset = glm::vec2(b->m_pattern_rand_offset ? 0.5f : 0.0f),
},
.mvp = ortho_proj,
.uses_destination_feedback = copy_stroke_destination,
.uses_pattern = false,
.mix_alpha = 0.0f,
.wet = 0.0f,
.noise = 0.0f,
.set_opacity = false,
});
// DRAW DUAL BRUSH
if (material.dual_pass.enabled)
{
m_rtt.clear();
ShaderManager::use(kShader::Stroke);
ShaderManager::u_int(kShaderUniform::UsePattern, material.dual_pass.uses_pattern);
ShaderManager::u_float(kShaderUniform::MixAlpha, 0);
ShaderManager::u_float(kShaderUniform::Wet, 0);
ShaderManager::u_float(kShaderUniform::Noise, 0);
pp::panopainter::setup_legacy_stroke_dual_shader(material.dual_pass.uses_pattern);
set_active_texture_unit(0U);
dual_brush->m_tip_texture ?
dual_brush->m_tip_texture->bind() :
@@ -476,9 +477,12 @@ void NodeStrokePreview::draw_stroke_immediate()
auto frames_dual = stroke_draw_compute(m_dual_stroke, zoom);
for (auto& f : frames_dual)
{
ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 });
ShaderManager::u_float(kShaderUniform::Alpha, f.flow);
ShaderManager::u_float(kShaderUniform::Opacity, f.opacity);
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = { 0, 0, 0, 1 },
.alpha = f.flow,
.opacity = f.opacity,
});
/*auto rect =*/ stroke_draw_samples(f.shapes, m_tex_dual, copy_stroke_destination);
}
@@ -514,11 +518,12 @@ void NodeStrokePreview::draw_stroke_immediate()
// DRAW MAIN BRUSH
ShaderManager::use(kShader::Stroke);
ShaderManager::u_int(kShaderUniform::UsePattern, material.stroke_pass.uses_pattern);
ShaderManager::u_float(kShaderUniform::MixAlpha, b->m_tip_mix);
ShaderManager::u_float(kShaderUniform::Wet, b->m_tip_wet);
ShaderManager::u_float(kShaderUniform::Noise, b->m_tip_noise);
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);
set_active_texture_unit(0U);
b->m_tip_texture->bind();
@@ -542,13 +547,15 @@ void NodeStrokePreview::draw_stroke_immediate()
stroke_draw_mix(xy(f.m_mixer_rect), zw(f.m_mixer_rect));
}
ShaderManager::use(kShader::Stroke);
if (b->m_blend_mode != 0 || b->m_tip_mix > 0.f)
ShaderManager::u_vec4(kShaderUniform::Col, { .7, .4, .1, 1 } /*f.col*/);
else
ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 } /*f.col*/);
ShaderManager::u_float(kShaderUniform::Alpha, glm::max(f.flow, m_min_flow));
ShaderManager::u_float(kShaderUniform::Opacity, f.opacity);
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = b->m_blend_mode != 0 || b->m_tip_mix > 0.f ?
glm::vec4 { .7, .4, .1, 1 } /*f.col*/ :
glm::vec4 { 0, 0, 0, 1 } /*f.col*/,
.alpha = glm::max(f.flow, m_min_flow),
.opacity = f.opacity,
});
/*auto rect =*/ stroke_draw_samples(f.shapes, m_tex, copy_stroke_destination);
}
set_active_texture_unit(3U);