Thin canvas draw seams and own grid worker
This commit is contained in:
@@ -449,60 +449,60 @@ void NodePanelGrid::bake_uvs()
|
||||
auto data_out = std::make_unique<uint8_t[]>(fb.getWidth() * fb.getHeight() * 4);
|
||||
const auto samples = get_samples();
|
||||
const auto radius = get_radius();
|
||||
std::thread worker([&]
|
||||
{
|
||||
BT_SetTerminate();
|
||||
float* d_pos = data_pos.get();
|
||||
float* d_nor = data_nor.get();
|
||||
auto* d_out = reinterpret_cast<glm::u8vec4*>(data_out.get());
|
||||
parallel_for(fb.getHeight(), [&](size_t y)
|
||||
std::jthread worker([&]
|
||||
{
|
||||
for (int x = 0; x < fb.getWidth(); x++)
|
||||
BT_SetTerminate();
|
||||
float* d_pos = data_pos.get();
|
||||
float* d_nor = data_nor.get();
|
||||
auto* d_out = reinterpret_cast<glm::u8vec4*>(data_out.get());
|
||||
parallel_for(fb.getHeight(), [&](size_t y)
|
||||
{
|
||||
int i = (int)y * fb.getHeight() + x;
|
||||
auto nor = glm::make_vec3(&d_nor[i * 4]);
|
||||
auto pos = glm::make_vec3(&d_pos[i * 4]);
|
||||
auto& out = d_out[i];
|
||||
|
||||
if (glm::dot(nor, light_dir) <= 0.f)
|
||||
for (int x = 0; x < fb.getWidth(); x++)
|
||||
{
|
||||
out = { 50, 50, 50, 255 };
|
||||
continue;
|
||||
int i = (int)y * fb.getHeight() + x;
|
||||
auto nor = glm::make_vec3(&d_nor[i * 4]);
|
||||
auto pos = glm::make_vec3(&d_pos[i * 4]);
|
||||
auto& out = d_out[i];
|
||||
|
||||
if (glm::dot(nor, light_dir) <= 0.f)
|
||||
{
|
||||
out = { 50, 50, 50, 255 };
|
||||
continue;
|
||||
}
|
||||
|
||||
int hit = 0;
|
||||
for (int s = 0; s < samples; s++)
|
||||
{
|
||||
auto dir = glm::normalize(light_dir + glm::sphericalRand(radius));
|
||||
|
||||
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 / (float)samples);
|
||||
}
|
||||
|
||||
int hit = 0;
|
||||
for (int s = 0; s < samples; s++)
|
||||
{
|
||||
auto dir = glm::normalize(light_dir + glm::sphericalRand(radius));
|
||||
|
||||
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 / (float)samples);
|
||||
}
|
||||
pb_value++;
|
||||
pb_value++;
|
||||
});
|
||||
});
|
||||
while (pb_value < fb.getHeight())
|
||||
{
|
||||
pb->set_progress((float)pb_value / (float)fb.getHeight());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
);
|
||||
while (pb_value < fb.getHeight())
|
||||
{
|
||||
pb->set_progress((float)pb_value / (float)fb.getHeight());
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
worker.join();
|
||||
pp::panopainter::close_legacy_dialog_node(*pb);
|
||||
//stbi_write_jpg("bake-out.jpg", fb.getWidth(), fb.getHeight(), 4, data_out.get(), 75);
|
||||
m_texture.update(data_out.get());
|
||||
|
||||
Reference in New Issue
Block a user