From a0ed07929942053d26b9216f95d2d61d8d54bb85 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 26 Feb 2019 15:14:42 +0100 Subject: [PATCH] scale brush size on high dpi --- data/shaders/comp-draw.glsl | 2 +- src/brush.h | 3 ++- src/canvas.cpp | 4 ++-- src/canvas_modes.cpp | 4 ++-- src/node_panel_brush.cpp | 5 ++++- src/node_panel_stroke.cpp | 1 + src/node_stroke_preview.cpp | 20 +++++++++++--------- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/data/shaders/comp-draw.glsl b/data/shaders/comp-draw.glsl index d71f0fd..84acf89 100644 --- a/data/shaders/comp-draw.glsl +++ b/data/shaders/comp-draw.glsl @@ -49,7 +49,7 @@ out mediump vec4 frag; void main() { - mediump vec2 uv_base = use_fragcoord ? gl_FragCoord.st / resolution : uv; + mediump vec2 uv_base = use_fragcoord ? (gl_FragCoord.st / resolution) : uv; mediump vec4 base = texture(tex, uv_base); mediump vec4 stroke = texture(tex_stroke, uv); diff --git a/src/brush.h b/src/brush.h index a3486b4..aac1b1b 100644 --- a/src/brush.h +++ b/src/brush.h @@ -24,12 +24,13 @@ public: glm::vec4 m_tip_color = { 0, 0, 0, 1 }; glm::vec2 m_tip_scale = { 1.f, 1.f }; + float m_tip_width = 1.f; float m_tip_size = 50; float m_tip_spacing = .25; float m_tip_flow = 1.f; float m_tip_opacity = 1.f; float m_tip_angle = 0; - float m_tip_angle_smooth = 0.01; + float m_tip_angle_smooth = 0.2; float m_tip_mix = 0; float m_tip_wet = 0; float m_tip_noise = 0; diff --git a/src/canvas.cpp b/src/canvas.cpp index 5eb6657..f559972 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -437,11 +437,11 @@ std::vector Canvas::stroke_draw_compute(Stroke& stroke) con glm::vec2 mixer_bb_max(0, 0); for (int j = 0; j < 4; j++) { - auto p = (xy(prev.pos) + s.scale * off_mix[j] * glm::orientate2(-s.angle)); + auto p = (xy(prev.pos) + App::I.zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle)); mixer_bb_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p)); mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, p)); - B[j].pos = glm::vec4(xy(s.pos) + s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1); + B[j].pos = glm::vec4(xy(s.pos) + App::I.zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1); B[j].uvs2 = p / mixer_sz; } diff --git a/src/canvas_modes.cpp b/src/canvas_modes.cpp index 888b1c9..1c59243 100644 --- a/src/canvas_modes.cpp +++ b/src/canvas_modes.cpp @@ -213,7 +213,7 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const ShaderManager::u_int(kShaderUniform::Tex, 0); float tip_scale_fix = 1.f / glm::tan(glm::radians(Canvas::I->m_cam_fov * 0.5f)); float tip_angle = brush->m_tip_angle * (float)(M_PI * 2.0); - glm::vec2 tip_scale = brush->m_tip_scale * + glm::vec2 tip_scale = App::I.zoom * brush->m_tip_scale * glm::vec2(brush->m_tip_size * tip_scale_fix) * glm::vec2(brush->m_tip_flipx ? -1 : 1, brush->m_tip_flipy ? -1.f : 1.f) * glm::vec2((brush->m_tip_aspect <= 0.5 ? brush->m_tip_aspect * 2.f : 1.f), @@ -225,7 +225,7 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const const auto& s = Canvas::I->m_current_stroke->m_prev_sample; if (s.size > 0.f) { - tip_scale = (brush->m_tip_size * tip_scale_fix) * s.scale; + tip_scale = App::I.zoom * (brush->m_tip_size * tip_scale_fix) * s.scale; tip_angle = s.angle; tip_offset = s.pos - s.origin; tip_color = glm::vec4(s.col, s.flow); diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp index 774084b..78d8ee8 100644 --- a/src/node_panel_brush.cpp +++ b/src/node_panel_brush.cpp @@ -486,6 +486,7 @@ bool NodePanelBrushPreset::save() i.m_stencil_thumb_path_len = b->m_pattern_thumb_path.size(); i.m_tip_color = b->m_tip_color; i.m_tip_scale = b->m_tip_scale; + i.m_tip_width = b->m_tip_width; i.m_tip_size = b->m_tip_size; i.m_tip_spacing = b->m_tip_spacing; i.m_tip_flow = b->m_tip_flow; @@ -589,6 +590,7 @@ bool NodePanelBrushPreset::restore() auto b = std::make_shared(); b->m_tip_color = i.m_tip_color; b->m_tip_scale = i.m_tip_scale; + b->m_tip_width = i.m_tip_width; b->m_tip_size = i.m_tip_size; b->m_tip_spacing = i.m_tip_spacing; b->m_tip_flow = i.m_tip_flow; @@ -667,6 +669,8 @@ bool NodePanelBrushPreset::restore() { if (!b->m_pattern_path.empty()) b->load_pattern(b->m_pattern_path, b->m_pattern_thumb_path); + if (!b->m_dual_path.empty()) + b->load_dual(b->m_dual_path, b->m_dual_thumb_path); NodeBrushPresetItem* brush = new NodeBrushPresetItem; m_container->add_child(brush); @@ -676,7 +680,6 @@ bool NodePanelBrushPreset::restore() brush->thumb_path = b->m_brush_thumb_path; brush->high_path = b->m_brush_path; brush->m_brush = b; - brush->m_brush->m_tip_size = .05f; brush->m_preview->m_brush = b; brush->m_preview->draw_stroke(); brush->m_thumb->set_image(brush->m_brush->m_brush_thumb_path); diff --git a/src/node_panel_stroke.cpp b/src/node_panel_stroke.cpp index c859e99..6465bd9 100644 --- a/src/node_panel_stroke.cpp +++ b/src/node_panel_stroke.cpp @@ -135,6 +135,7 @@ bool NodePanelStroke::import_abr(const std::string& path) } async_start(); + m_presets_popup->save(); pb->destroy(); app_redraw(); async_update(); diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index 0dd304d..f65469b 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -204,11 +204,11 @@ std::vector NodeStrokePreview::stroke_draw_compu glm::vec2 mixer_bb_max(0, 0); for (int j = 0; j < 4; j++) { - auto p = (xy(prev.pos) + s.scale * off_mix[j] * glm::orientate2(-s.angle)); + auto p = (xy(prev.pos) + App::I.zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle)); mixer_bb_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p)); mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, p)); - B[j].pos = glm::vec4(xy(s.pos) + s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1); + B[j].pos = glm::vec4(xy(s.pos) + App::I.zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1); B[j].uvs2 = p / mixer_sz; } @@ -245,7 +245,7 @@ void NodeStrokePreview::draw_stroke() const auto& b = m_brush; m_stroke.m_filter_points = false; - m_stroke.m_max_size = m_size.y * App::I.zoom; + m_stroke.m_max_size = m_size.y; m_stroke.m_camera.fov = Canvas::I->m_cam_fov; m_stroke.m_camera.rot = Canvas::I->m_cam_rot; m_stroke.reset(true); @@ -280,12 +280,14 @@ void NodeStrokePreview::draw_stroke() { float w = m_size.x * App::I.zoom; float h = m_size.y * App::I.zoom; - float pad = m_size.x * App::I.zoom * .15f; - std::vector kp = { { pad, pad },{ pad, h - pad },{ w - pad, pad },{ w - pad, h - pad } }; - for (int i = 0; i < 20; i++) + glm::vec2 pad = { 0, 0 }; + if (!b->m_tip_size_pressure) + pad = m_size * App::I.zoom * .15f; + std::vector kp = { pad, { pad.x, h - pad.y },{ w - pad.x, pad.y },{ w - pad.x, h - pad.y } }; + for (int i = 0; i < 100; i++) { - float t = (float)i / 20.f; - float p = 1.f - glm::abs(t * 2.f - 1.f); + float t = (float)i / 100.f; + float p = glm::pow(1.f - glm::abs(t * 2.f - 1.f), 2.f); m_stroke.add_point(glm::vec3(BezierCurve::Bezier2D(kp, t), 0), p); if (b->m_dual_enabled) m_dual_stroke.add_point(glm::vec3(BezierCurve::Bezier2D(kp, t), 0), p); @@ -312,7 +314,6 @@ void NodeStrokePreview::draw_stroke() 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_int(kShaderUniform::UsePattern, b->m_pattern_enabled && b->m_pattern_eachsample); ShaderManager::u_mat4(kShaderUniform::MVP, ortho_proj); // DRAW DUAL BRUSH @@ -346,6 +347,7 @@ void NodeStrokePreview::draw_stroke() // DRAW MAIN BRUSH ShaderManager::use(kShader::Stroke); + ShaderManager::u_int(kShaderUniform::UsePattern, b->m_pattern_enabled && b->m_pattern_eachsample); 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);