enable rtt dtor, default values for <text> node, dual-brush wip, more brush options

This commit is contained in:
2019-02-14 02:08:29 +01:00
parent 8ad005de8b
commit 999723dd14
26 changed files with 998 additions and 389 deletions

View File

@@ -252,6 +252,7 @@ void Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
ShaderManager::u_int(kShaderUniform::Lock, false/*m_layers[layer_index].m_alpha_locked*/);
ShaderManager::u_int(kShaderUniform::Mask, false/*m_smask_active*/);
ShaderManager::u_int(kShaderUniform::UseFragCoordUV2, false);
ShaderManager::u_int(kShaderUniform::UseDual, false);
ShaderManager::u_int(kShaderUniform::BlendMode, m_current_stroke->m_brush->m_blend_mode);
ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
glActiveTexture(GL_TEXTURE0);
@@ -273,11 +274,11 @@ void Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
gl.restore();
}
std::array<std::vector<vertex_t>, 6> Canvas::stroke_draw_project(std::array<vertex_t, 4>& B)
std::array<std::vector<vertex_t>, 6> Canvas::stroke_draw_project(std::array<vertex_t, 4>& B) const
{
// intersect P with the current face to clip diverging points from the plane
auto unp_vp = zw(m_box);
auto unp_inv = glm::inverse(m_proj * m_mv);
const auto unp_vp = zw(m_box);
const auto unp_inv = glm::inverse(m_proj * m_mv);
std::array<std::vector<vertex_t>, 6> ret;
for (int i = 0; i < 6; i++)
{
@@ -338,7 +339,7 @@ std::array<std::vector<vertex_t>, 6> Canvas::stroke_draw_project(std::array<vert
return ret;
}
void Canvas::stroke_draw_samples(int i, std::vector<vertex_t>& P)
glm::vec4 Canvas::stroke_draw_samples(int i, std::vector<vertex_t>& P)
{
if (!ShaderManager::ext_framebuffer_fetch)
{
@@ -364,9 +365,6 @@ void Canvas::stroke_draw_samples(int i, std::vector<vertex_t>& P)
tex_pos.x, tex_pos.y, tex_sz.x, tex_sz.y);
}
m_dirty_box[i] = glm::vec4(glm::min(xy(m_dirty_box[i]), (glm::vec2)tex_pos),
glm::max(zw(m_dirty_box[i]), (glm::vec2)(tex_pos + tex_sz)));
if (P.size() == 4)
{
static vertex_t rect[6];
@@ -394,13 +392,15 @@ void Canvas::stroke_draw_samples(int i, std::vector<vertex_t>& P)
glActiveTexture(GL_TEXTURE1);
m_tex[i].unbind();
}
return glm::vec4(tex_pos, tex_pos + tex_sz);
}
std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute()
std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute(Stroke& stroke) const
{
std::vector<StrokeFrame> ret;
const auto& m_brush = m_current_stroke->m_brush;
auto samples = m_current_stroke->compute_samples();
StrokeSample prev = stroke.m_prev_sample;
auto samples = stroke.compute_samples();
std::array<vertex_t, 4> B = {
vertex_t{ {0, 0, 1, 1}, {0, 0}, {0, 0} },
vertex_t{ {0, 0, 1, 1}, {0, 1}, {0, 1} },
@@ -415,13 +415,7 @@ std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute()
ret.emplace_back();
auto& f = ret.back();
if (m_mixer_idle)
{
m_mixer_sample = s;
m_mixer_idle = false;
}
glm::vec2 dx_mix(m_mixer_sample.size * 0.5f, 0), dy_mix(0, m_mixer_sample.size * 0.5f);
glm::vec2 dx_mix(prev.size * 0.5f, 0), dy_mix(0, prev.size * 0.5f);
glm::vec2 off_mix[4] = {
-dx_mix - dy_mix, // A - bottom-left
-dx_mix + dy_mix, // B - top-left
@@ -442,20 +436,20 @@ std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute()
glm::vec2 mixer_bb_max(0, 0);
for (int j = 0; j < 4; j++)
{
auto p = (xy(m_mixer_sample.pos) + off_mix[j] * glm::orientate2(-s.angle) + glm::vec2(0, 1));
auto p = (xy(prev.pos) + 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) + off[j] * glm::orientate2(-s.angle), 1, 1);
B[j].pos = glm::vec4(xy(s.pos) + s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
B[j].uvs2 = p / mixer_sz;
}
f.m_mixer_rect = { mixer_bb_min, mixer_bb_max - mixer_bb_min };
f.col = glm::vec4(s.col, m_brush->m_tip_color.a);
f.col = glm::vec4(s.col, 1);
f.pressure = s.flow;
f.shapes = stroke_draw_project(B);
m_mixer_sample = s;
prev = s;
}
return ret;
}
@@ -475,29 +469,18 @@ void Canvas::stroke_draw()
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
const auto& m_brush = m_current_stroke->m_brush;
auto& tex = *m_brush->m_tip_texture;
const auto& brush = m_current_stroke->m_brush;
const auto& dual_brush = m_dual_stroke->m_brush;
auto ortho_proj = glm::ortho(0.f, (float)m_width, 0.f, (float)m_height, -1.f, 1.f);
glViewport(0, 0, m_width, m_height);
glActiveTexture(GL_TEXTURE0);
tex.bind();
m_sampler_brush.bind(0);
m_sampler_bg.bind(1);
m_sampler_stencil.bind(2);
m_sampler.bind(3);
//m_sampler_linear.bind(5);
glActiveTexture(GL_TEXTURE2);
if (m_brush->m_stencil_texture)
m_brush->m_stencil_texture->bind();
else
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE3);
m_mixer.bindTexture();
glDisable(GL_BLEND);
ShaderManager::use(kShader::Stroke);
ShaderManager::u_int(kShaderUniform::Tex, 0); // brush
@@ -508,21 +491,32 @@ void Canvas::stroke_draw()
//ShaderManager::u_int(kShaderUniform::TexMixA, 4); // mixer
ShaderManager::u_vec2(kShaderUniform::Resolution, { m_width, m_height });
ShaderManager::u_vec2(kShaderUniform::StencilOffset, stencil_offset);
ShaderManager::u_float(kShaderUniform::StencilAlpha, m_brush->m_tip_stencil);
ShaderManager::u_float(kShaderUniform::MixAlpha, m_brush->m_tip_mix);
ShaderManager::u_float(kShaderUniform::Wet, m_brush->m_tip_wet);
ShaderManager::u_float(kShaderUniform::Noise, m_brush->m_tip_noise);
ShaderManager::u_float(kShaderUniform::StencilAlpha, brush->m_tip_stencil);
ShaderManager::u_float(kShaderUniform::MixAlpha, brush->m_tip_mix);
ShaderManager::u_float(kShaderUniform::Wet, brush->m_tip_wet);
ShaderManager::u_float(kShaderUniform::Noise, brush->m_tip_noise);
ShaderManager::u_mat4(kShaderUniform::MVP, ortho_proj);
auto frames = stroke_draw_compute();
// DRAW MAIN BRUSH
glActiveTexture(GL_TEXTURE0);
brush->m_tip_texture->bind();
glActiveTexture(GL_TEXTURE2);
if (brush->m_stencil_texture)
brush->m_stencil_texture->bind();
else
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE3);
m_mixer.bindTexture();
auto frames = stroke_draw_compute(*m_current_stroke);
for (auto& f : frames)
{
if (m_brush->m_tip_mix > 0.f)
if (brush->m_tip_mix > 0.f)
{
stroke_draw_mix(xy(f.m_mixer_rect), zw(f.m_mixer_rect));
}
//ShaderManager::use(kShader::Stroke);
ShaderManager::use(kShader::Stroke);
ShaderManager::u_vec4(kShaderUniform::Col, f.col);
ShaderManager::u_float(kShaderUniform::Alpha, f.pressure);
for (int i = 0; i < 6; i++)
@@ -532,22 +526,56 @@ void Canvas::stroke_draw()
continue;
m_dirty_face[i] = true;
m_tmp[i].bindFramebuffer();
stroke_draw_samples(i, P);
auto rect = stroke_draw_samples(i, P);
m_tmp[i].unbindFramebuffer();
m_dirty_box[i] = glm::clamp(box_union(m_dirty_box[i], rect), glm::vec4(0), glm::vec4(m_width));
}
}
glActiveTexture(GL_TEXTURE2);
if (m_brush->m_stencil_texture)
m_brush->m_stencil_texture->unbind();
glActiveTexture(GL_TEXTURE3);
m_mixer.unbindTexture();
glActiveTexture(GL_TEXTURE2);
if (brush->m_stencil_texture)
brush->m_stencil_texture->unbind();
glActiveTexture(GL_TEXTURE0);
brush->m_tip_texture->unbind();
// DRAW DUAL BRUSH
if (brush->m_dual_enabled)
{
glActiveTexture(GL_TEXTURE0);
dual_brush->m_tip_texture->bind();
glActiveTexture(GL_TEXTURE2);
if (dual_brush->m_stencil_texture)
dual_brush->m_stencil_texture->bind();
else
glBindTexture(GL_TEXTURE_2D, 0);
auto frames_dual = stroke_draw_compute(*m_dual_stroke);
for (auto& f : frames_dual)
{
ShaderManager::use(kShader::Stroke);
ShaderManager::u_vec4(kShaderUniform::Col, f.col);
ShaderManager::u_float(kShaderUniform::Alpha, f.pressure);
for (int i = 0; i < 6; i++)
{
auto& P = f.shapes[i];
if (P.size() < 3)
continue;
m_tmp_dual[i].bindFramebuffer();
stroke_draw_samples(i, P);
m_tmp_dual[i].unbindFramebuffer();
}
}
glActiveTexture(GL_TEXTURE2);
if (dual_brush->m_stencil_texture)
dual_brush->m_stencil_texture->unbind();
glActiveTexture(GL_TEXTURE0);
dual_brush->m_tip_texture->unbind();
}
m_sampler_brush.unbind();
m_sampler_bg.unbind();
m_sampler_stencil.unbind();
tex.unbind();
glViewport(vp[0], vp[1], vp[2], vp[3]);
glClearColor(cc[0], cc[1], cc[2], cc[3]);
@@ -665,7 +693,6 @@ void Canvas::stroke_commit()
if (!m_dirty || m_layers.empty())
return;
m_mixer_idle = true;
m_dirty = false;
m_dirty_stroke = true; // new stroke ready for timelapse capture
App::I.redraw = true;
@@ -763,6 +790,9 @@ void Canvas::stroke_commit()
ShaderManager::u_int(kShaderUniform::UseFragCoordUV2, false);
ShaderManager::u_int(kShaderUniform::BlendMode, m_current_stroke->m_brush->m_blend_mode);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ShaderManager::u_int(kShaderUniform::TexDual, 3);
ShaderManager::u_int(kShaderUniform::UseDual, true);
ShaderManager::u_int(kShaderUniform::DualBlendMode, 1);
glActiveTexture(GL_TEXTURE0);
m_tex2[i].bind();
@@ -771,13 +801,11 @@ void Canvas::stroke_commit()
glActiveTexture(GL_TEXTURE2);
m_smask.m_rtt[i].bindTexture();
glActiveTexture(GL_TEXTURE3);
if (m_current_stroke->m_brush->m_stencil_texture)
m_current_stroke->m_brush->m_stencil_texture->bind();
else
glBindTexture(GL_TEXTURE_2D, 0);
m_current_stroke->m_brush->m_dual_enabled ?
m_tmp_dual[i].bindTexture() : glBindTexture(GL_TEXTURE_2D, 0);
m_plane.draw_fill();
if (m_current_stroke->m_brush->m_stencil_texture)
m_current_stroke->m_brush->m_stencil_texture->unbind();
if (m_current_stroke->m_brush->m_dual_enabled)
m_tmp_dual[i].unbindTexture();
glActiveTexture(GL_TEXTURE2);
m_smask.m_rtt[i].unbindTexture();
glActiveTexture(GL_TEXTURE1);
@@ -790,7 +818,7 @@ void Canvas::stroke_commit()
// ShaderManager::use(kShader::StrokeLayer);
// ShaderManager::u_int(kShaderUniform::TexBG, 1);
// ShaderManager::u_int(kShaderUniform::Lock, m_layers[m_current_layer_idx].m_alpha_locked);
// ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush->m_tip_opacity);
// ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->brush->m_tip_opacity);
//
// ShaderManager::u_int(kShaderUniform::Tex, 0);
// ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
@@ -819,14 +847,16 @@ void Canvas::stroke_commit()
void Canvas::stroke_update(glm::vec3 point, float pressure)
{
m_current_stroke->add_point(point, pressure);
m_dual_stroke->add_point(point, pressure);
}
void Canvas::stroke_start(glm::vec3 point, float pressure, const std::shared_ptr<Brush>& brush)
void Canvas::stroke_start(glm::vec3 point, float pressure)
{
// need to commit this now before starting a new stroke
if (m_current_stroke && m_commit_delayed)
{
stroke_commit();
m_current_stroke = nullptr;
m_dual_stroke = nullptr;
m_show_tmp = false;
m_commit_delayed = false;
}
@@ -836,9 +866,15 @@ void Canvas::stroke_start(glm::vec3 point, float pressure, const std::shared_ptr
m_current_stroke = std::make_unique<Stroke>();
m_current_stroke->m_camera.rot = m_cam_rot;
m_current_stroke->m_camera.fov = m_cam_fov;
m_current_stroke->start(brush);
m_current_stroke->start(m_current_brush);
m_current_stroke->add_point(point, pressure);
m_dual_stroke = std::make_unique<Stroke>();
m_dual_stroke->m_camera.rot = m_cam_rot;
m_dual_stroke->m_camera.fov = m_cam_fov;
m_dual_stroke->start(m_dual_brush);
m_dual_stroke->add_point(point, pressure);
for (int i = 0; i < 6; i++)
{
m_dirty_box[i] = glm::vec4(m_width, m_height, 0, 0); // reset bounding box
@@ -847,6 +883,13 @@ void Canvas::stroke_start(glm::vec3 point, float pressure, const std::shared_ptr
m_tmp[i].bindFramebuffer();
m_tmp[i].clear({ 0, 0, 0, 0 });
m_tmp[i].unbindFramebuffer();
if (m_current_stroke->m_brush->m_dual_enabled)
{
m_tmp_dual[i].bindFramebuffer();
m_tmp_dual[i].clear({ 0, 0, 0, 0 });
m_tmp_dual[i].unbindFramebuffer();
}
}
m_show_tmp = true;
}
@@ -934,6 +977,7 @@ void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
ShaderManager::u_int(kShaderUniform::Lock, false);
ShaderManager::u_int(kShaderUniform::BlendMode, m_layers[source_idx].m_blend_mode);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
ShaderManager::u_int(kShaderUniform::UseDual, false);
glActiveTexture(GL_TEXTURE0);
m_tex2[i].bind();
@@ -971,9 +1015,11 @@ void Canvas::resize(int width, int height)
{
#if defined(__IOS__) || defined(__ANDROID__)
m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA8);
#else
m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F);
#endif
m_tex2[i].create(width, height, GL_RGBA8);
@@ -992,10 +1038,12 @@ bool Canvas::create(int width, int height)
{
#if defined(__IOS__) || defined(__ANDROID__)
m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tmp_dual[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA8);
m_sampler_brush.create();
#else
m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tmp_dual[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F);
m_sampler_brush.create(GL_LINEAR, GL_CLAMP_TO_BORDER);
#endif