stencil in brush preview
This commit is contained in:
@@ -258,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) * stencil_alpha;\n"
|
||||
" mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset) * 2.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__
|
||||
|
||||
@@ -107,12 +107,18 @@ bool ui::BrushMesh::create()
|
||||
static const char* shader_stroke_inst_f =
|
||||
SHADER_VERSION
|
||||
"uniform mediump sampler2D tex;"
|
||||
"uniform mediump sampler2D tex_stencil;\n"
|
||||
"uniform mediump vec4 col;"
|
||||
"uniform mediump vec2 resolution;\n"
|
||||
"uniform mediump vec2 stencil_offset;\n"
|
||||
"uniform mediump float stencil_alpha;\n"
|
||||
"in mediump float alpha;"
|
||||
"in mediump vec3 uv;"
|
||||
"out mediump vec4 frag;"
|
||||
"void main(){"
|
||||
" mediump float a = (1.0 - texture(tex, uv.xy).r) * alpha;"
|
||||
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
|
||||
" mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset)).r * 0.9) * stencil_alpha;\n"
|
||||
" mediump float a = (1.0 - texture(tex, uv.xy).r) * alpha * stencil;"
|
||||
" frag = vec4(col.rgb, a);"
|
||||
"}";
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ void ui::Canvas::stroke_draw()
|
||||
ShaderManager::u_int(kShaderUniform::TexStencil, 3); // stencil
|
||||
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_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)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ void NodeStrokePreview::clone_finalize(Node* dest) const
|
||||
void NodeStrokePreview::init_controls()
|
||||
{
|
||||
m_mesh.create();
|
||||
m_sampler.create();
|
||||
m_sampler.create(GL_LINEAR, GL_REPEAT);
|
||||
m_sampler_brush.create();
|
||||
m_sampler_brush.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
|
||||
TextureManager::load("data/thumbs/Round-Hard.png");
|
||||
@@ -74,14 +74,24 @@ void NodeStrokePreview::draw_stroke()
|
||||
m_stroke.m_prev_sample.origin = m_stroke.m_keypoints[0].pos;
|
||||
auto samples = m_stroke.compute_samples();
|
||||
auto& tex = TextureManager::get(m_brush.m_tex_id);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
tex.bind();
|
||||
m_sampler_brush.bind(0);
|
||||
|
||||
auto& stencil = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
stencil.bind();
|
||||
m_sampler.bind(1);
|
||||
|
||||
if (true)
|
||||
{
|
||||
m_mesh.shader.use();
|
||||
m_mesh.shader.u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 });
|
||||
m_mesh.shader.u_int(kShaderUniform::Tex, 0);
|
||||
m_mesh.shader.u_int(kShaderUniform::TexStencil, 1); // stencil
|
||||
m_mesh.shader.u_vec2(kShaderUniform::Resolution, { m_rtt.getWidth(), m_rtt.getHeight() });
|
||||
m_mesh.shader.u_vec2(kShaderUniform::StencilOffset, glm::vec2(0));
|
||||
m_mesh.shader.u_float(kShaderUniform::StencilAlpha, m_brush.m_tip_stencil);
|
||||
m_mesh.draw(samples, proj);
|
||||
}
|
||||
//else
|
||||
@@ -102,6 +112,7 @@ void NodeStrokePreview::draw_stroke()
|
||||
//}
|
||||
|
||||
m_sampler_brush.unbind();
|
||||
m_sampler.unbind();
|
||||
tex.unbind();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
||||
@@ -105,24 +105,29 @@ void Shader::use()
|
||||
}
|
||||
void Shader::u_vec4(kShaderUniform id, const glm::vec4& v)
|
||||
{
|
||||
if (m_umap.count(id) == 0) LOG("UNIFORM %d NOT FOUND in shader %d", (int)id, (int)name);
|
||||
glUniform4fv(m_umap[id], 1, glm::value_ptr(v));
|
||||
}
|
||||
|
||||
void Shader::u_vec2(kShaderUniform id, const glm::vec2& v)
|
||||
{
|
||||
if (m_umap.count(id) == 0) LOG("UNIFORM %d NOT FOUND in shader %d", (int)id, (int)name);
|
||||
glUniform2fv(m_umap[id], 1, glm::value_ptr(v));
|
||||
}
|
||||
|
||||
void Shader::u_mat4(kShaderUniform id, const glm::mat4& m)
|
||||
{
|
||||
if (m_umap.count(id) == 0) LOG("UNIFORM %d NOT FOUND in shader %d", (int)id, (int)name);
|
||||
glUniformMatrix4fv(m_umap[id], 1, GL_FALSE, glm::value_ptr(m));
|
||||
}
|
||||
void Shader::u_int(kShaderUniform id, int i)
|
||||
{
|
||||
if (m_umap.count(id) == 0) LOG("UNIFORM %d NOT FOUND in shader %d", (int)id, (int)name);
|
||||
glUniform1i(m_umap[id], i);
|
||||
}
|
||||
void Shader::u_float(kShaderUniform id, float f)
|
||||
{
|
||||
if (m_umap.count(id) == 0) LOG("UNIFORM %d NOT FOUND in shader %d", (int)id, (int)name);
|
||||
glUniform1f(m_umap[id], f);
|
||||
}
|
||||
GLint ui::Shader::GetAttribLocation(const char* name)
|
||||
|
||||
Reference in New Issue
Block a user