check float texture extension, use float32 or float16 if available, show extension on title bar, add thread and render task for lightmap rendering
This commit is contained in:
@@ -121,12 +121,19 @@ void NodePanelGrid::init_controls()
|
||||
|
||||
m_render->on_click = [this](Node*)
|
||||
{
|
||||
gl_state gl;
|
||||
gl.save();
|
||||
bake_uvs();
|
||||
m_hm_shading->set_index(3);
|
||||
m_shade_mode = ShadeMode::Textured;
|
||||
gl.restore();
|
||||
if (ShaderManager::ext_texture_float || ShaderManager::ext_half_float_pixel)
|
||||
{
|
||||
std::thread([this] {
|
||||
bake_uvs();
|
||||
m_hm_shading->set_index(3);
|
||||
m_shade_mode = ShadeMode::Textured;
|
||||
}).detach();
|
||||
}
|
||||
else
|
||||
{
|
||||
App::I->message_box("Rendering failed",
|
||||
"Your hardware does not support lightmap rendering.");
|
||||
}
|
||||
};
|
||||
m_commit->on_click = [this](Node*)
|
||||
{
|
||||
@@ -213,6 +220,7 @@ float NodePanelGrid::get_offset() const
|
||||
|
||||
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const
|
||||
{
|
||||
assert(App::I->is_render_thread());
|
||||
if (m_groud_opacity->get_value() > 0.f)
|
||||
{
|
||||
bool depth = glIsEnabled(GL_DEPTH_TEST);
|
||||
@@ -345,38 +353,43 @@ void NodePanelGrid::bake_uvs()
|
||||
return;
|
||||
|
||||
RTT fb;
|
||||
#if defined(__IOS__) || defined(__ANDROID__)
|
||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
|
||||
#else
|
||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
|
||||
#endif
|
||||
fb.bindFramebuffer();
|
||||
fb.clear({ 1, 0, 0, 1 });
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glViewport(0, 0, fb.getWidth(), fb.getHeight());
|
||||
ShaderManager::use(kShader::BakeUV);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::mat4(1));
|
||||
|
||||
// bake normal
|
||||
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
||||
m_hm_plane.draw_fill();
|
||||
std::unique_ptr<float[]> data_nor(fb.readTextureDataFloat());
|
||||
//stbi_write_png("bake-nor.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||
|
||||
// bake position
|
||||
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
||||
m_hm_plane.draw_fill();
|
||||
std::unique_ptr<float[]> data_pos(fb.readTextureDataFloat());
|
||||
//stbi_write_png("bake-pos.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||
if (ShaderManager::ext_texture_float)
|
||||
{
|
||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
|
||||
}
|
||||
else if (ShaderManager::ext_half_float_pixel)
|
||||
{
|
||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
|
||||
}
|
||||
|
||||
fb.unbindFramebuffer();
|
||||
fb.destroy();
|
||||
std::unique_ptr<float[]> data_nor;
|
||||
std::unique_ptr<float[]> data_pos;
|
||||
App::I->render_task([&]{
|
||||
fb.bindFramebuffer();
|
||||
fb.clear({ 1, 0, 0, 1 });
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glViewport(0, 0, fb.getWidth(), fb.getHeight());
|
||||
ShaderManager::use(kShader::BakeUV);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::mat4(1));
|
||||
|
||||
auto pb = root()->add_child<NodeProgressBar>();
|
||||
pb->m_progress->SetWidthP(0);
|
||||
pb->m_title->set_text("Lightmap Rendering");
|
||||
pb->btn_cancel->destroy();
|
||||
// bake normal
|
||||
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
||||
m_hm_plane.draw_fill();
|
||||
data_nor.reset(fb.readTextureDataFloat());
|
||||
//stbi_write_png("bake-nor.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||
|
||||
// bake position
|
||||
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
||||
m_hm_plane.draw_fill();
|
||||
data_pos.reset(fb.readTextureDataFloat());
|
||||
//stbi_write_png("bake-pos.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||
|
||||
fb.unbindFramebuffer();
|
||||
fb.destroy();
|
||||
});
|
||||
|
||||
auto pb = App::I->show_progress("Lightmap Rendering");
|
||||
|
||||
if (m_rt_dirty)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user