scale brush size on high dpi

This commit is contained in:
2019-02-26 15:14:42 +01:00
parent cbfcd66bfc
commit a0ed079299
7 changed files with 23 additions and 16 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -437,11 +437,11 @@ std::vector<Canvas::StrokeFrame> 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;
}

View File

@@ -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);

View File

@@ -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<Brush>();
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);

View File

@@ -135,6 +135,7 @@ bool NodePanelStroke::import_abr(const std::string& path)
}
async_start();
m_presets_popup->save();
pb->destroy();
app_redraw();
async_update();

View File

@@ -204,11 +204,11 @@ std::vector<NodeStrokePreview::StrokeFrame> 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<glm::vec2> 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<glm::vec2> 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);