opacity control

This commit is contained in:
2017-04-07 12:57:21 +01:00
parent d340324c3d
commit 2b4915154e
5 changed files with 17 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ public:
float m_tip_size;
float m_tip_spacing;
float m_tip_flow;
float m_tip_opacity;
float m_tip_angle;
float m_jitter_scale;
float m_jitter_angle;

View File

@@ -24,8 +24,8 @@ void ui::Canvas::clear()
}
void ui::Canvas::stroke_end()
{
m_current_stroke = nullptr;
stroke_commit();
m_current_stroke = nullptr;
m_show_tmp = false;
}
void ui::Canvas::stroke_draw()
@@ -33,6 +33,8 @@ void ui::Canvas::stroke_draw()
if (!(m_current_stroke && m_current_stroke->has_sample()))
return;
m_dirty = true;
m_tmp.bindFramebuffer();
GLint vp[4];
@@ -134,6 +136,10 @@ void ui::Canvas::stroke_draw()
}
void ui::Canvas::stroke_commit()
{
if (!m_dirty)
return;
m_dirty = false;
m_fb.bindFramebuffer();
// copy to tmp2 for layer blending
@@ -158,7 +164,7 @@ void ui::Canvas::stroke_commit()
ShaderManager::use(ui::kShader::StrokeLayer);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_int(kShaderUniform::TexBG, 1);
ShaderManager::u_float(kShaderUniform::Alpha, .5); // TODO: if using opacity in commit, update blending to match the preview when rendering m_tmp in NodeCanvas
ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush.m_tip_opacity); // TODO: if using opacity in commit, update blending to match the preview when rendering m_tmp in NodeCanvas
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
m_plane.draw_fill();
m_sampler.unbind();

View File

@@ -9,14 +9,15 @@ NS_START
class Canvas
{
Stroke* m_current_stroke = nullptr;
Plane m_plane;
BrushMesh m_mesh;
int m_current_layer_idx = 0;
bool m_dirty = false;
public:
int m_width;
int m_height;
bool m_use_instanced = false;
Stroke* m_current_stroke = nullptr;
bool m_show_tmp = false;
std::vector<Layer> m_layers;
std::vector<Stroke> m_strokes;

View File

@@ -1798,6 +1798,7 @@ public:
NodeSliderH* m_tip_size;
NodeSliderH* m_tip_spacing;
NodeSliderH* m_tip_flow;
NodeSliderH* m_tip_opacity;
NodeSliderH* m_tip_angle;
NodeSliderH* m_jitter_scale;
NodeSliderH* m_jitter_angle;
@@ -1822,6 +1823,7 @@ public:
init_slider(m_tip_size, "tip-size", &ui::Brush::m_tip_size);
init_slider(m_tip_spacing, "tip-spacing", &ui::Brush::m_tip_spacing);
init_slider(m_tip_flow, "tip-flow", &ui::Brush::m_tip_flow);
init_slider(m_tip_opacity, "tip-opacity", &ui::Brush::m_tip_opacity);
init_slider(m_tip_angle, "tip-angle", &ui::Brush::m_tip_angle);
init_slider(m_jitter_scale, "jitter-scale", &ui::Brush::m_jitter_scale);
init_slider(m_jitter_angle, "jitter-angle", &ui::Brush::m_jitter_angle);
@@ -1904,7 +1906,7 @@ public:
ui::ShaderManager::use(kShader::TextureAlpha);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
ui::ShaderManager::u_float(kShaderUniform::Alpha, .5);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_current_stroke->m_brush.m_tip_opacity);
m_canvas->m_tmp.bindTexture();
NodeBorder::m_plane.draw_fill();
m_canvas->m_tmp.unbindTexture();