diff --git a/src/node_panel_grid.cpp b/src/node_panel_grid.cpp index a2a5bfa..4d056ae 100644 --- a/src/node_panel_grid.cpp +++ b/src/node_panel_grid.cpp @@ -133,8 +133,9 @@ void NodePanelGrid::init_controls() m_groud_opacity->set_value(0); gl.restore(); }; - m_texture.create(2048, 2048); - m_sampler_linear.create(GL_NEAREST); + m_texture.create(1024, 1024); + m_sampler_linear.create(); + m_sampler_linear.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR); m_sphere.create<8, 8>(.0001f); } @@ -297,35 +298,34 @@ void NodePanelGrid::bake_uvs() auto pos = glm::make_vec3(&data_pos[i * 4]); auto& out = *reinterpret_cast(&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; +// } - nanort::Ray 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] = light_dir.x; - ray.dir[1] = light_dir.y; - ray.dir[2] = light_dir.z; - - float kFar = 20.0; - ray.min_t = 0.01f; - ray.max_t = kFar; - - nanort::TriangleIntersector<> triangle_intersector(reinterpret_cast(m_hm_plane.vertices.data()), m_hm_plane.idx.data(), sizeof(vertex_t)); - nanort::TriangleIntersection<> isect; - bool hit = m_rt_accel.Traverse(ray, triangle_intersector, &isect); - if (hit) + int hit = 0; + for (int s = 0; s < 16; s++) { - out = { 50, 50, 50, 255 }; - } - else - { - out = { 255, 255, 255, 255 }; + auto dir = glm::normalize(light_dir + glm::sphericalRand(.1f)); + + nanort::Ray 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(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__ @@ -333,4 +333,5 @@ void NodePanelGrid::bake_uvs() #endif //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(); } diff --git a/src/node_panel_layer.cpp b/src/node_panel_layer.cpp index 85a46e2..db10d9c 100644 --- a/src/node_panel_layer.cpp +++ b/src/node_panel_layer.cpp @@ -189,6 +189,8 @@ 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; } diff --git a/src/pch.h b/src/pch.h index fd28c83..6dd013d 100644 --- a/src/pch.h +++ b/src/pch.h @@ -106,6 +106,7 @@ #include #include #include +#include #include #include #include