mixer brush partially working, still wip
This commit is contained in:
@@ -291,10 +291,13 @@ void App::initShaders()
|
||||
"uniform mat4 mvp;\n"
|
||||
"in vec4 pos;\n"
|
||||
"in vec2 uvs;\n"
|
||||
"in vec2 uvs2;\n"
|
||||
"out vec2 uv;\n"
|
||||
"out vec2 uv_2;\n"
|
||||
"out float q;\n"
|
||||
"void main(){\n"
|
||||
" uv = uvs;\n"
|
||||
" uv_2 = uvs2;\n"
|
||||
" q = pos.z;\n"
|
||||
" gl_Position = mvp * vec4(pos.xy, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
@@ -317,6 +320,7 @@ void App::initShaders()
|
||||
"uniform mediump float mix_alpha;\n"
|
||||
"uniform mediump float wet;\n"
|
||||
"in mediump vec2 uv;\n"
|
||||
"in mediump vec2 uv_2;\n"
|
||||
"in mediump float q;\n"
|
||||
#ifdef __IOS__
|
||||
"inout mediump vec4 frag;\n"
|
||||
@@ -344,7 +348,8 @@ void App::initShaders()
|
||||
#else
|
||||
" mediump vec4 bg = texture(tex_bg, uv2);\n"
|
||||
#endif
|
||||
" mediump vec4 mbg = texture(tex_mix, uv/q);\n"
|
||||
" mediump vec4 mbg = texture(tex_mix, uv_2);\n"
|
||||
" bg.rgb = mix(bg.rgb, mbg.rgb, mix_alpha);\n"
|
||||
" fg.a *= 1.0-rand(uv2+uv)*noise;\n"
|
||||
" if (fg.a == 0.0) discard;\n"
|
||||
" mediump float contribution = (1.0 - bg.a) * fg.a;\n"
|
||||
@@ -352,7 +357,7 @@ void App::initShaders()
|
||||
" mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);\n"
|
||||
" mediump vec4 frag_wet = vec4(rgb, max(bg.a, fg.a * 1.2));\n"
|
||||
" mediump vec4 frag_dry = vec4(rgb, alpha_tot);\n"
|
||||
" frag = mix(mix(frag_dry, frag_wet, wet), mbg, mix_alpha);\n"
|
||||
" frag = mix(frag_dry, frag_wet, wet);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* shader_checkerboard_v =
|
||||
|
||||
@@ -222,11 +222,11 @@ void ui::Canvas::stroke_cancel()
|
||||
void ui::Canvas::stroke_draw_mix()
|
||||
{
|
||||
m_mixer.bindFramebuffer();
|
||||
m_mixer.clear({ 0, 1, 1, 1 });
|
||||
m_mixer.clear({ 1, 1, 1, 1 });
|
||||
|
||||
glViewport(m_vp.x, m_vp.y, m_vp.z, m_vp.w);
|
||||
glDisable(GL_BLEND);
|
||||
glViewport(0, 0, m_mixer.getWidth(), m_mixer.getHeight());
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
m_sampler_bg.bind(0);
|
||||
auto layer_index = m_current_layer_idx;
|
||||
@@ -237,24 +237,25 @@ void ui::Canvas::stroke_draw_mix()
|
||||
|
||||
auto plane_mvp_z = 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);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Highlight, false);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||
// m_node->m_face_plane.draw_fill();
|
||||
// m_layers[layer_index].m_rtt[plane_index].unbindTexture();
|
||||
|
||||
m_tmp[plane_index].bindTexture();
|
||||
m_node->m_face_plane.draw_fill();
|
||||
m_tmp[plane_index].unbindTexture();
|
||||
}
|
||||
ui::ShaderManager::use(kShader::TextureAlpha);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity);
|
||||
ui::ShaderManager::u_int(kShaderUniform::Highlight, false);
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
//glDisable(GL_BLEND);
|
||||
m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||
m_node->m_face_plane.draw_fill();
|
||||
m_layers[layer_index].m_rtt[plane_index].unbindTexture();
|
||||
|
||||
m_tmp[plane_index].bindTexture();
|
||||
m_node->m_face_plane.draw_fill();
|
||||
m_tmp[plane_index].unbindTexture();
|
||||
}
|
||||
m_sampler_bg.unbind();
|
||||
m_mixer.unbindFramebuffer();
|
||||
@@ -342,12 +343,15 @@ void ui::Canvas::stroke_draw()
|
||||
+ dx - dy, // D - bottom-right
|
||||
};
|
||||
static glm::vec4 P[4];
|
||||
static glm::vec2 UV2[4];
|
||||
int intersected = 0;
|
||||
int inside = 0;
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
glm::vec3 ray_origin, ray_dir;
|
||||
point_unproject(s.pos + off[j] * glm::orientate2(-s.angle), { 0, 0, zw(m_box) }, m_mv, m_proj, ray_origin, ray_dir);
|
||||
UV2[j] = (s.pos + off[j]) / glm::vec2(m_mixer.getWidth(), m_mixer.getHeight());
|
||||
UV2[j].y = 1 - UV2[j].y;
|
||||
glm::vec3 hit;
|
||||
if (ray_intersect(ray_origin, ray_dir, m_plane_origin[i], m_plane_normal[i], m_plane_tangent[i], hit))
|
||||
{
|
||||
@@ -401,7 +405,7 @@ void ui::Canvas::stroke_draw()
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, ortho_proj);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(s.col, m_brush.m_tip_color.a));
|
||||
ShaderManager::u_float(kShaderUniform::Alpha, s.flow);
|
||||
m_plane_brush.update_vertices(P);
|
||||
m_plane_brush.update_vertices(P, nullptr, UV2);
|
||||
m_plane_brush.draw_fill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,11 @@ bool Shader::create(const char* vertex, const char* fragment)
|
||||
if (glGetAttribLocation(ps, "uvs") != -1)
|
||||
glBindAttribLocation(ps, 1, "uvs");
|
||||
|
||||
if (glGetAttribLocation(ps, "uvs2") != -1)
|
||||
glBindAttribLocation(ps, 2, "uvs2");
|
||||
|
||||
if (glGetAttribLocation(ps, "col") != -1)
|
||||
glBindAttribLocation(ps, 2, "col");
|
||||
glBindAttribLocation(ps, 3, "col");
|
||||
|
||||
glLinkProgram(ps);
|
||||
glGetProgramiv(ps, GL_LINK_STATUS, &status);
|
||||
|
||||
@@ -41,6 +41,7 @@ enum class kShader : uint16_t
|
||||
CompErase = const_hash("comp-erase"),
|
||||
CompDraw = const_hash("comp-draw"),
|
||||
UVs = const_hash("uvs"),
|
||||
UVs_2 = const_hash("uvs2"),
|
||||
Font = const_hash("font"),
|
||||
Atlas = const_hash("atlas"),
|
||||
Stroke = const_hash("stroke"),
|
||||
|
||||
@@ -28,10 +28,12 @@ bool Shape::create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize)
|
||||
glBindVertexArray(arrays[i]);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)0);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs2));
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
@@ -62,9 +64,11 @@ bool Shape::create_buffers(GLvoid* vertices, int vsize)
|
||||
glBindVertexArray(arrays[i]);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)0);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs2));
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
@@ -209,7 +213,7 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_
|
||||
*idx++ = div; // D
|
||||
*idx++ = 0; // A
|
||||
}
|
||||
void ui::Plane::update_vertices(const glm::vec4* data)
|
||||
void ui::Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const glm::vec2* uvs2)
|
||||
{
|
||||
static vertex_t vertices[4];
|
||||
|
||||
@@ -219,14 +223,18 @@ void ui::Plane::update_vertices(const glm::vec4* data)
|
||||
for (int i = 0; i < 4; i++)
|
||||
d[i] = glm::distance(xy(data[i]), mid);
|
||||
|
||||
vertices[0] = { data[0],{ 0, 0 } }; // A
|
||||
vertices[1] = { data[1],{ 0, 1 } }; // B
|
||||
vertices[2] = { data[2],{ 1, 1 } }; // C
|
||||
vertices[3] = { data[3],{ 1, 0 } }; // D
|
||||
vertices[0] = { data[0], { 0, 0 }, { 0, 0 } }; // A
|
||||
vertices[1] = { data[1], { 0, 1 }, { 0, 1 } }; // B
|
||||
vertices[2] = { data[2], { 1, 1 }, { 1, 1 } }; // C
|
||||
vertices[3] = { data[3], { 1, 0 }, { 1, 0 } }; // D
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float q = (d[i] + d[(i + 2) % 4]) / d[(i + 2) % 4];
|
||||
if (uvs)
|
||||
vertices[i].uvs = uvs[i];
|
||||
if (uvs2)
|
||||
vertices[i].uvs2 = uvs2[i];
|
||||
vertices[i].uvs *= q;
|
||||
vertices[i].pos.z = q;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ protected:
|
||||
GLvoid* ioff[2]{ 0, 0 };
|
||||
bool use_idx = true;
|
||||
public:
|
||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; glm::vec2 uvs2; };
|
||||
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
||||
bool create_buffers(GLvoid* vertices, int vsize);
|
||||
void draw_fill() const;
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
create_impl(w, h, div, idx, vertices);
|
||||
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
||||
}
|
||||
void update_vertices(const glm::vec4* data);
|
||||
void update_vertices(const glm::vec4* data, const glm::vec2* uvs = nullptr, const glm::vec2* uvs2 = nullptr);
|
||||
/*
|
||||
bool create(att::Divisions divisions, att::Width w, att::Height h)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user