add progress bar to lightmap rendering

This commit is contained in:
2019-01-15 22:25:23 +01:00
parent c3220b5b15
commit f5c4aed4fd
8 changed files with 98 additions and 53 deletions

View File

@@ -106,6 +106,7 @@ target_include_directories(native-lib PRIVATE
../libs/poly2tri/poly2tri
../libs/base64
../libs/sqlite3
../libs/nanort
)
# add lib dependencies

View File

@@ -390,6 +390,7 @@ static int engine_init_display(struct engine* engine) {
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_NONE
};
EGLint w, h, dummy, format;

View File

@@ -153,7 +153,7 @@
<border color=".2" height="20" justify="center" align="center"><text text="Tip Settings" font-face="arial" font-size="11"/></border>
<node dir="row">
<node width="30%" dir="col">
<node height="30" justify="center"><text text="Blend" font-face="arial" font-size="11"/></node>
<node height="30" justify="center" margin="5 0 5 0"><text text="Blend" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Size" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Flow" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Opacity" font-face="arial" font-size="11"/></node>
@@ -168,7 +168,7 @@
<node height="20" justify="center"><text text="Val" font-face="arial" font-size="11"/></node>
</node>
<node dir="col" align="center" grow="1" width="1" flood-events="1">
<node height="30" pad="1" width="100%" dir="row">
<node height="30" pad="1" width="100%" dir="row" margin="5 0 5 0">
<combobox id="blend-mode" text="Normal" width="100%" height="30" combo-list="Normal,-,Multiply,Screen,-,Color Dodge,Overlay" default="0"/>
</node>
<node height="20" pad="1" width="100%" dir="row">
@@ -221,7 +221,7 @@
</node>
</node>
<border color=".2" height="20" justify="center" align="center"><text text="Jitter Settings" font-face="arial" font-size="11"/></border>
<border color=".2" height="20" justify="center" align="center" margin="5 0 5 0"><text text="Jitter Settings" font-face="arial" font-size="11"/></border>
<node dir="row">
<node width="30%" dir="col">
<node height="20" justify="center"><text text="Scale" font-face="arial" font-size="11"/></node>
@@ -1119,7 +1119,7 @@ Here's a list of what's available in this release.
<node height="100%" dir="row" shrink="1">
<scroll id="panels" pad="5 25 5 5" margin="0 0 0 0" color=".3 .3 .3 .4" height="100%" dir="col" wrap="0" shrink="1">
<!--Stroke-->
<!--<panel-stroke id="panel-stroke"/>-->
<panel-stroke id="panel-stroke"/>
<!--Brushes-->
<!--<panel-brush id="panel-brush"/>-->
<!--Layers-->

View File

@@ -17,6 +17,7 @@ bool Font::load(const char* ttf, int font_size)
auto bitmap = std::make_unique<uint8_t[]>(w*h);
chars.resize(num_chars);
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size*2, bitmap.get(), w, h, start_char, num_chars, chars.data());
calc_bounds();
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());
file.close();
size = font_size;
@@ -25,6 +26,21 @@ bool Font::load(const char* ttf, int font_size)
return false;
}
void Font::calc_bounds()
{
glm::vec2 bbmin(FLT_MAX);
glm::vec2 bbmax(-FLT_MAX);
for (int i = 0; i < num_chars; i++)
{
stbtt_aligned_quad q;
float x = 0, y = 0;
stbtt_GetBakedQuad(chars.data(), w, h, i, &x, &y, &q, true);
bbmin = glm::min(bbmin, { q.x0 / 2.f, q.y0 / 2.f });
bbmax = glm::max(bbmax, { q.x1 / 2.f, q.y1 / 2.f });
}
bounds = { glm::vec4(bbmin, bbmax) };
}
void FontManager::init()
{
m_sampler.create();

View File

@@ -16,12 +16,15 @@ public:
const int h = 512;
const int num_chars = 96;
const int start_char = 32;
// {mix, max}
glm::vec4 bounds{ 0 };
int size = 0;
stbtt_fontinfo font;
Texture2D font_tex;
std::vector<stbtt_bakedchar> chars;
bool load(const char* ttf, int sz);
void calc_bounds();
};
class FontManager

View File

@@ -264,6 +264,12 @@ void NodePanelGrid::bake_uvs()
fb.unbindFramebuffer();
fb.destroy();
auto pb = root()->add_child<NodeProgressBar>();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Lightmap Rendering");
pb->btn_cancel->destroy();
async_update();
if (m_rt_dirty)
{
nanort::BVHBuildOptions<float> build_options; // Use default option
@@ -281,7 +287,11 @@ void NodePanelGrid::bake_uvs()
auto light_pos = glm::vec3(sinf(light_yaw), light_pitch + get_offset(), cosf(light_yaw));
auto light_dir = glm::normalize(light_pos);
std::atomic_int pb_value(0);
__block auto data_out = std::make_unique<uint8_t[]>(fb.getWidth() * fb.getHeight() * 4);
std::thread worker([&]
{
#if _WIN32
concurrency::parallel_for(int(0), fb.getHeight(), [&](int y)
#elif __IOS__ || __OSX__
@@ -298,11 +308,11 @@ void NodePanelGrid::bake_uvs()
auto pos = glm::make_vec3(&data_pos[i * 4]);
auto& out = *reinterpret_cast<glm::i8vec4*>(&data_out[i * 4]);
// if (glm::dot(nor, light_dir) <= 0.f)
// {
// out = { 50, 50, 50, 255 };
// continue;
// }
if (glm::dot(nor, light_dir) <= 0.f)
{
out = { 50, 50, 50, 255 };
continue;
}
int hit = 0;
for (int s = 0; s < 16; s++)
@@ -327,10 +337,21 @@ void NodePanelGrid::bake_uvs()
}
out = glm::lerp(glm::vec4(255, 255, 255, 255), glm::vec4(50, 50, 50, 255), hit / 16.f);
}
pb_value++;
}
#if _WIN32 || __IOS__ || __OSX__
);
#endif
}
);
while (pb_value < fb.getHeight())
{
pb->m_progress->SetWidthP((float)pb_value / (float)fb.getHeight() * 100.f);
async_update();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
worker.join();
pb->destroy();
//stbi_write_jpg("bake-out.jpg", fb.getWidth(), fb.getHeight(), 4, data_out.get(), 75);
m_texture.update(data_out.get());
m_texture.create_mipmaps();

View File

@@ -9,6 +9,9 @@
#include "node_button.h"
#include "shape.h"
#include "image.h"
#define NANORT_USE_CPP11_FEATURE
#define NANORT_ENABLE_PARALLEL_BUILD
#include "nanort.h"
class NodePanelGrid : public Node

View File

@@ -132,6 +132,8 @@ void NodePanelLayer::init()
add_layer();
if (on_layer_add)
on_layer_add(this);
if (on_layer_change)
on_layer_change(this, -1, m_layers_container->get_child_index(m_current_layer));
update_attributes();
};
btn_remove->on_click = [this](Node*) {
@@ -189,8 +191,6 @@ NodeLayer* NodePanelLayer::add_layer(const char* name)
m_current_layer = l;
m_current_layer->m_selected = true;
m_layers.push_back(l);
if (on_layer_change)
on_layer_change(this, -1, m_layers_container->get_child_index(m_current_layer));
update_attributes();
return l;
}