improving mixer

This commit is contained in:
2018-08-02 09:44:14 +02:00
parent 8a3760df9e
commit 12c1aa33c4
10 changed files with 71 additions and 51 deletions

View File

@@ -228,7 +228,7 @@ void ui::Canvas::stroke_draw_mix()
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
m_sampler_bg.bind(0);
m_sampler.bind(0);
auto layer_index = m_current_layer_idx;
for (int plane_index = 0; plane_index < 6; plane_index++)
{
@@ -236,9 +236,10 @@ void ui::Canvas::stroke_draw_mix()
continue;
glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)m_mixer.getWidth() / m_mixer.getHeight(), 0.1f, 1000.f);
auto plane_mvp_z = m_proj * m_mv *
auto plane_mvp_z =
glm::scale(glm::vec3(1, -1, 1)) *
m_proj * m_mv *
m_plane_transform[plane_index] *
//glm::scale(glm::vec3(1, -1, 1)) *
glm::translate(glm::vec3(0, 0, -1));
ui::ShaderManager::use(kShader::TextureAlpha);
@@ -258,7 +259,7 @@ void ui::Canvas::stroke_draw_mix()
m_node->m_face_plane.draw_fill();
m_tmp[plane_index].unbindTexture();
}
m_sampler_bg.unbind();
m_sampler.unbind();
m_mixer.unbindFramebuffer();
}
void ui::Canvas::stroke_draw()
@@ -273,42 +274,11 @@ void ui::Canvas::stroke_draw()
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
stroke_draw_mix();
glViewport(0, 0, m_width, m_height);
auto ortho_proj = glm::ortho(0.f, (float)m_width, 0.f, (float)m_height, -1.f, 1.f);
auto m_brush = m_current_stroke->m_brush;
auto samples = m_current_stroke->compute_samples();
auto& tex = TextureManager::get(m_brush.m_tex_id);
auto& stencil = TextureManager::get(const_hash("data/paper.jpg"));
glActiveTexture(GL_TEXTURE0);
tex.bind();
m_sampler_brush.bind(0);
m_sampler_bg.bind(1);
m_sampler_stencil.bind(2);
m_sampler_mix.bind(3);
glActiveTexture(GL_TEXTURE2);
stencil.bind();
glActiveTexture(GL_TEXTURE3);
m_mixer.bindTexture();
glDisable(GL_BLEND);
ShaderManager::use(ui::kShader::Stroke);
ShaderManager::u_int(kShaderUniform::Tex, 0); // brush
#ifndef __IOS__
ShaderManager::u_int(kShaderUniform::TexBG, 1); // bg
#endif
ShaderManager::u_int(kShaderUniform::TexStencil, 2); // stencil
ShaderManager::u_int(kShaderUniform::TexMix, 3); // 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);
auto ortho_proj = glm::ortho(0.f, (float)m_width, 0.f, (float)m_height, -1.f, 1.f);
for (const auto& s : samples)
{
@@ -317,7 +287,39 @@ void ui::Canvas::stroke_draw()
m_mixer_sample = s;
m_mixer_idle = false;
}
if (m_brush.m_tip_mix > 0.f)
stroke_draw_mix();
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_mix.bind(3);
glActiveTexture(GL_TEXTURE2);
stencil.bind();
glActiveTexture(GL_TEXTURE3);
m_mixer.bindTexture();
glDisable(GL_BLEND);
ShaderManager::use(ui::kShader::Stroke);
ShaderManager::u_int(kShaderUniform::Tex, 0); // brush
#ifndef __IOS__
ShaderManager::u_int(kShaderUniform::TexBG, 1); // bg
#endif
ShaderManager::u_int(kShaderUniform::TexStencil, 2); // stencil
ShaderManager::u_int(kShaderUniform::TexMix, 3); // 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);
static glm::vec2 UV2[4];
for (int j = 0; j < 4; j++)
{
@@ -328,8 +330,8 @@ void ui::Canvas::stroke_draw()
+dx + dy, // C - top-right
+dx - dy, // D - bottom-right
};
UV2[j] = (m_mixer_sample.pos + off[j]) / glm::vec2(m_mixer.getWidth(), m_mixer.getHeight()) * m_mixer_scale;
UV2[j].y = 1 - UV2[j].y;
UV2[j] = (m_mixer_sample.pos + off[j] + glm::vec2(0,1)) / glm::vec2(m_mixer.getWidth(), m_mixer.getHeight()) * m_mixer_scale;
//UV2[j].y = 1.f - UV2[j].y;
}
for (int i = 0; i < 6; i++)
@@ -866,7 +868,7 @@ bool ui::Canvas::create(int width, int height)
m_sampler_bg.create(GL_NEAREST);
m_sampler_mask.create(GL_LINEAR);
m_sampler_stencil.create(GL_LINEAR, GL_REPEAT);
m_sampler_mix.create(GL_LINEAR, GL_REPEAT);
m_sampler_mix.create(GL_NEAREST, GL_REPEAT);
m_plane.create<1>(1, 1);
m_plane_brush.create<1>(1, 1);
m_mesh.create();