From 856628162aa19292fcd764c46553260844336706 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 20 Oct 2017 10:26:08 +0100 Subject: [PATCH] add stencil alpha control to ui --- data/layout.xml | 2 ++ engine/app_shaders.cpp | 3 ++- engine/brush.h | 1 + engine/canvas.cpp | 1 + engine/node_panel_stroke.cpp | 2 ++ engine/node_panel_stroke.h | 1 + engine/shader.h | 1 + 7 files changed, 10 insertions(+), 1 deletion(-) diff --git a/data/layout.xml b/data/layout.xml index 2fd08c0..a4ba7f5 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -152,6 +152,7 @@ + @@ -175,6 +176,7 @@ + diff --git a/engine/app_shaders.cpp b/engine/app_shaders.cpp index db07fe2..fab154a 100644 --- a/engine/app_shaders.cpp +++ b/engine/app_shaders.cpp @@ -248,6 +248,7 @@ void App::initShaders() "uniform mediump vec2 resolution;\n" "uniform mediump float alpha;\n" "uniform mediump vec2 stencil_offset;\n" + "uniform mediump float stencil_alpha;\n" "in mediump vec2 uv;\n" "in mediump float q;\n" #ifdef __IOS__ @@ -257,7 +258,7 @@ void App::initShaders() #endif "void main(){\n" " mediump vec2 uv2 = gl_FragCoord.st / resolution;\n" - " mediump float stencil = 1-(texture(tex_stencil, (uv2+stencil_offset) * 5.0).r * 0.9);\n" + " mediump float stencil = 1-(texture(tex_stencil, (uv2+stencil_offset) * 5.0).r * 0.9) * stencil_alpha;\n" " mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;\n" " mediump vec4 fg = vec4(col.rgb, brush_alpha);\n" #ifdef __IOS__ diff --git a/engine/brush.h b/engine/brush.h index 58d5e59..c783fae 100644 --- a/engine/brush.h +++ b/engine/brush.h @@ -16,6 +16,7 @@ public: float m_tip_flow = 0; float m_tip_opacity = 0; float m_tip_angle = 0; + float m_tip_stencil = 0; bool m_tip_angle_follow = false; bool m_tip_flow_pressure = false; bool m_tip_size_pressure = false; diff --git a/engine/canvas.cpp b/engine/canvas.cpp index d021ae0..5f84eab 100644 --- a/engine/canvas.cpp +++ b/engine/canvas.cpp @@ -243,6 +243,7 @@ void ui::Canvas::stroke_draw() ShaderManager::u_vec4(kShaderUniform::Col, m_brush.m_tip_color); ShaderManager::u_vec2(kShaderUniform::Resolution, { m_width, m_height }); ShaderManager::u_vec2(kShaderUniform::StencilOffset, glm::vec2((rand()%1000)*0.001f, (rand()%1000)*0.001f)); + ShaderManager::u_float(kShaderUniform::StencilAlpha, m_brush.m_tip_stencil); for (const auto& s : samples) { glm::vec2 dx(s.size * 0.5f, 0), dy(0, s.size * 0.5f); diff --git a/engine/node_panel_stroke.cpp b/engine/node_panel_stroke.cpp index cea44c0..bd01d95 100644 --- a/engine/node_panel_stroke.cpp +++ b/engine/node_panel_stroke.cpp @@ -26,6 +26,7 @@ void NodePanelStroke::set_params(const ui::Brush &b) m_tip_flow->m_value.x = glm::pow(b.m_tip_flow, 1.f/2.f); m_tip_opacity->m_value.x = b.m_tip_opacity; m_tip_angle->m_value.x = b.m_tip_angle; + m_tip_stencil->m_value.x = b.m_tip_stencil; m_jitter_scale->m_value.x = b.m_jitter_scale; m_jitter_angle->m_value.x = b.m_jitter_angle; m_jitter_spread->m_value.x = b.m_jitter_spread; @@ -46,6 +47,7 @@ void NodePanelStroke::init_controls() 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_tip_stencil, "tip-stencil", &ui::Brush::m_tip_stencil); init_slider(m_jitter_scale, "jitter-scale", &ui::Brush::m_jitter_scale); init_slider(m_jitter_angle, "jitter-angle", &ui::Brush::m_jitter_angle); init_slider(m_jitter_spread, "jitter-spread", &ui::Brush::m_jitter_spread); diff --git a/engine/node_panel_stroke.h b/engine/node_panel_stroke.h index dec31c1..7651cbe 100644 --- a/engine/node_panel_stroke.h +++ b/engine/node_panel_stroke.h @@ -14,6 +14,7 @@ public: NodeSliderH* m_tip_flow; NodeSliderH* m_tip_opacity; NodeSliderH* m_tip_angle; + NodeSliderH* m_tip_stencil; NodeSliderH* m_jitter_scale; NodeSliderH* m_jitter_angle; NodeSliderH* m_jitter_spread; diff --git a/engine/shader.h b/engine/shader.h index 7bdf2c7..4446b43 100644 --- a/engine/shader.h +++ b/engine/shader.h @@ -13,6 +13,7 @@ enum class kShaderUniform : uint16_t TexStroke = const_hash("tex_stroke"), TexStencil= const_hash("tex_stencil"), StencilOffset = const_hash("stencil_offset"), + StencilAlpha = const_hash("stencil_alpha"), Lock = const_hash("lock"), Col = const_hash("col"), Tof = const_hash("tof"),