add progress bar to lightmap rendering
This commit is contained in:
@@ -106,6 +106,7 @@ target_include_directories(native-lib PRIVATE
|
||||
../libs/poly2tri/poly2tri
|
||||
../libs/base64
|
||||
../libs/sqlite3
|
||||
../libs/nanort
|
||||
)
|
||||
|
||||
# add lib dependencies
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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-->
|
||||
|
||||
16
src/font.cpp
16
src/font.cpp
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,56 +287,71 @@ 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);
|
||||
#if _WIN32
|
||||
concurrency::parallel_for(int(0), fb.getHeight(), [&](int y)
|
||||
#elif __IOS__ || __OSX__
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_apply((size_t)fb.getHeight(), queue, ^(size_t y)
|
||||
#else
|
||||
for (int y = 0; y < fb.getHeight(); y++)
|
||||
#endif
|
||||
std::thread worker([&]
|
||||
{
|
||||
for (int x = 0; x < fb.getWidth(); x++)
|
||||
{
|
||||
int i = y * fb.getHeight() + x;
|
||||
auto nor = glm::make_vec3(&data_nor[i * 4]);
|
||||
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;
|
||||
// }
|
||||
|
||||
int hit = 0;
|
||||
for (int s = 0; s < 16; s++)
|
||||
{
|
||||
auto dir = glm::normalize(light_dir + glm::sphericalRand(.1f));
|
||||
|
||||
nanort::Ray<float> ray;
|
||||
ray.org[0] = pos.x;// + nor.x * 0.005;
|
||||
ray.org[1] = pos.y;// + nor.y * 0.005;
|
||||
ray.org[2] = pos.z;// + nor.z * 0.005;
|
||||
ray.dir[0] = dir.x;
|
||||
ray.dir[1] = dir.y;
|
||||
ray.dir[2] = dir.z;
|
||||
|
||||
float kFar = 2000.0;
|
||||
ray.min_t = 0.005f;
|
||||
ray.max_t = kFar;
|
||||
|
||||
nanort::TriangleIntersector<> triangle_intersector(reinterpret_cast<float*>(m_hm_plane.vertices.data()), m_hm_plane.idx.data(), sizeof(vertex_t));
|
||||
nanort::TriangleIntersection<> isect;
|
||||
hit += m_rt_accel.Traverse(ray, triangle_intersector, &isect);
|
||||
}
|
||||
out = glm::lerp(glm::vec4(255, 255, 255, 255), glm::vec4(50, 50, 50, 255), hit / 16.f);
|
||||
}
|
||||
}
|
||||
#if _WIN32 || __IOS__ || __OSX__
|
||||
);
|
||||
#if _WIN32
|
||||
concurrency::parallel_for(int(0), fb.getHeight(), [&](int y)
|
||||
#elif __IOS__ || __OSX__
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_apply((size_t)fb.getHeight(), queue, ^ (size_t y)
|
||||
#else
|
||||
for (int y = 0; y < fb.getHeight(); y++)
|
||||
#endif
|
||||
{
|
||||
for (int x = 0; x < fb.getWidth(); x++)
|
||||
{
|
||||
int i = y * fb.getHeight() + x;
|
||||
auto nor = glm::make_vec3(&data_nor[i * 4]);
|
||||
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;
|
||||
}
|
||||
|
||||
int hit = 0;
|
||||
for (int s = 0; s < 16; s++)
|
||||
{
|
||||
auto dir = glm::normalize(light_dir + glm::sphericalRand(.1f));
|
||||
|
||||
nanort::Ray<float> ray;
|
||||
ray.org[0] = pos.x;// + nor.x * 0.005;
|
||||
ray.org[1] = pos.y;// + nor.y * 0.005;
|
||||
ray.org[2] = pos.z;// + nor.z * 0.005;
|
||||
ray.dir[0] = dir.x;
|
||||
ray.dir[1] = dir.y;
|
||||
ray.dir[2] = dir.z;
|
||||
|
||||
float kFar = 2000.0;
|
||||
ray.min_t = 0.005f;
|
||||
ray.max_t = kFar;
|
||||
|
||||
nanort::TriangleIntersector<> triangle_intersector(reinterpret_cast<float*>(m_hm_plane.vertices.data()), m_hm_plane.idx.data(), sizeof(vertex_t));
|
||||
nanort::TriangleIntersection<> isect;
|
||||
hit += m_rt_accel.Traverse(ray, triangle_intersector, &isect);
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user