export depth

This commit is contained in:
2019-04-25 23:31:03 +02:00
parent 2da84ec63d
commit db208bd7cd
5 changed files with 131 additions and 1 deletions

View File

@@ -1032,6 +1032,21 @@ void Canvas::draw_merge(std::array<bool, 6> faces /*= SIXPLETTE(false)*/)
m_layers[layer_index]->m_rtt[plane_index].unbindTexture();
glActiveTexture(GL_TEXTURE0);
m_layers[layer_index]->m_rtt[plane_index].unbindTexture();
/*
m_sampler.bind(0);
m_sampler_linear.bind(1);
ShaderManager::use(kShader::TextureColorize);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_vec4(kShaderUniform::Col, { glm::vec3((float)layer_index / (float)m_order.size()), 1.f });
ShaderManager::u_mat4(kShaderUniform::MVP, ortho);
glActiveTexture(GL_TEXTURE0);
m_layers[layer_index]->m_rtt[plane_index].bindTexture();
m_plane.draw_fill();
m_layers[layer_index]->m_rtt[plane_index].unbindTexture();
*/
}
if (use_blend)
@@ -1828,6 +1843,92 @@ void Canvas::export_depth_thread(std::string file_name)
gl_state gl;
gl.save();
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
RTT rtt;
rtt.create(1024, 1024);
rtt.bindFramebuffer();
rtt.clear({ 0, 0, 0, 1 });
glViewport(0, 0, rtt.getWidth(), rtt.getHeight());
glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)rtt.getWidth() / (float)rtt.getHeight(), 0.1f, 100.f);
glm::mat4 camera = m_cam_rot;
for (int plane_index = 0; plane_index < 6; plane_index++)
{
auto plane_mvp_z = proj * camera *
m_plane_transform[plane_index] *
glm::translate(glm::vec3(0, 0, -1)) *
glm::scale(glm::vec3(2));
m_sampler.bind(0);
m_sampler_linear.bind(1);
ShaderManager::use(kShader::TextureAlphaSep);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_int(kShaderUniform::TexA, 1);
ShaderManager::u_float(kShaderUniform::Alpha, 1.f);
ShaderManager::u_int(kShaderUniform::Highlight, false);
ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
glActiveTexture(GL_TEXTURE0);
m_layers_merge.m_rtt[plane_index].bindTexture();
glActiveTexture(GL_TEXTURE1);
m_layers_merge.m_rtt[plane_index].bindTexture();
m_plane.draw_fill();
glActiveTexture(GL_TEXTURE1);
m_layers_merge.m_rtt[plane_index].unbindTexture();
glActiveTexture(GL_TEXTURE0);
m_layers_merge.m_rtt[plane_index].unbindTexture();
}
uint8_t* rgba_data = rtt.readTextureData();
stbi_flip_vertically_on_write(true);
std::string path_rgba = App::I.work_path + "/" + file_name + ".png";
stbi_write_jpg(path_rgba.c_str(), rtt.getWidth(), rtt.getHeight(), 4, rgba_data, 100);
delete rgba_data;
rtt.clear({ 0, 0, 0, 1 });
for (size_t i = 0; i < m_order.size(); i++)
{
auto layer_index = m_order[i];
for (int plane_index = 0; plane_index < 6; plane_index++)
{
if ((!m_layers[layer_index]->m_visible ||
m_layers[layer_index]->m_opacity == .0f ||
!m_layers[layer_index]->m_dirty_face[plane_index]))
continue;
auto plane_mvp_z = proj * camera *
m_plane_transform[plane_index] *
glm::translate(glm::vec3(0, 0, -1)) *
glm::scale(glm::vec3(2));
m_sampler.bind(0);
m_sampler_linear.bind(1);
ShaderManager::use(kShader::TextureColorize);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_vec4(kShaderUniform::Col, { glm::vec3((float)(i + 1) / (float)(m_order.size() + 1)), 1.f });
ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
glActiveTexture(GL_TEXTURE0);
m_layers[layer_index]->m_rtt[plane_index].bindTexture();
m_plane.draw_fill();
m_layers[layer_index]->m_rtt[plane_index].unbindTexture();
}
}
uint8_t* depth_data = rtt.readTextureData();
std::string path_depth = App::I.work_path + "/" + file_name + "_depth.png";
stbi_write_jpg(path_depth.c_str(), rtt.getWidth(), rtt.getHeight(), 4, depth_data, 100);
delete depth_data;
stbi_flip_vertically_on_write(false);
rtt.unbindFramebuffer();
rtt.destroy();
gl.restore();
App::I.async_end();
}