improve grid panel

This commit is contained in:
2019-01-19 15:21:37 +01:00
parent 886ab1f29b
commit d8c8a4b7ed
7 changed files with 100 additions and 30 deletions

View File

@@ -26,7 +26,7 @@ void NodePanelGrid::init_controls()
{
m_groud_opacity = find<NodeSliderH>("grid-ground-opacity");
m_groud_value = find<NodeSliderH>("grid-ground-value");
m_groud_resolution = find<NodeSliderH>("grid-ground-resolution");
m_groud_resolution = find<NodeComboBox>("grid-ground-resolution");
m_groud_offset = find<NodeSliderH>("grid-ground-offset");
m_hm_preview = find<NodeImageTexture>("grid-heightmap-preview");
@@ -34,10 +34,13 @@ void NodePanelGrid::init_controls()
m_hm_clear = find<NodeButton>("grid-heightmap-clear");
m_hm_reload = find<NodeButton>("grid-heightmap-reload");
m_hm_wireframe = find<NodeSliderH>("grid-heightmap-wireframe");
m_hm_thickness = find<NodeSliderH>("grid-heightmap-thickness");
m_hm_height = find<NodeSliderH>("grid-heightmap-height");
m_hm_lyaw = find<NodeSliderH>("grid-heightmap-lyaw");
m_hm_lpitch = find<NodeSliderH>("grid-heightmap-lpitch");
m_hm_shading = find<NodeComboBox>("grid-heightmap-shading");
m_hm_texres = find<NodeComboBox>("grid-heightmap-texres");
m_hm_samples = find<NodeComboBox>("grid-heightmap-samples");
m_render = find<NodeButton>("grid-render");
m_commit = find<NodeButton>("grid-commit");
@@ -49,18 +52,18 @@ void NodePanelGrid::init_controls()
m_hm_preview_nav->SetHeightP(100);
//m_hm_height->on_value_changed = update_hm;
m_groud_resolution->on_value_final = [this](Node* target, float v) {
m_groud_resolution->on_select = [this](Node* target, int index) {
if (m_hm_image.data())
m_hm_plane.create(1, 1, m_hm_image, v * 5.f, get_height());
m_hm_plane.create(1, 1, m_hm_image, get_resolution(), get_height());
else
m_hm_plane.create(1, 1, 100 * v * 5.f);
m_hm_plane.create(1, 1, 100 * get_resolution());
m_rt_dirty = true;
LOG("resolution value %f", v);
LOG("resolution index %d", index);
};
m_hm_height->on_value_final = [this](Node* target, float v) {
if (m_hm_image.data())
m_hm_plane.create(1, 1, m_hm_image, m_groud_resolution->get_value() * 5.f, get_height());
m_hm_plane.create(1, 1, m_hm_image, get_resolution(), get_height());
m_rt_dirty = true;
LOG("height value %f", v);
};
@@ -81,8 +84,7 @@ void NodePanelGrid::init_controls()
m_hm_preview->tex.create_mipmaps();
auto sz = m_hm_preview->tex.size();
m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_plane.create(1, 1, m_hm_image,
m_groud_resolution->get_value() * 5.f, get_height());
m_hm_plane.create(1, 1, m_hm_image, get_resolution(), get_height());
m_hm_preview->SetHeight(100);
if (m_groud_opacity->get_value() == 0.f)
m_groud_opacity->set_value(1.f);
@@ -95,7 +97,7 @@ void NodePanelGrid::init_controls()
m_hm_clear->on_click = [this](Node*)
{
m_hm_plane.create(1, 1, 100 * m_groud_resolution->get_value() * 5.f);
m_hm_plane.create(1, 1, 100 * get_resolution());
m_hm_image.destroy();
m_hm_preview->tex.destroy();
m_hm_preview->SetHeight(0);
@@ -111,8 +113,7 @@ void NodePanelGrid::init_controls()
m_hm_preview->tex.create_mipmaps();
auto sz = m_hm_preview->tex.size();
m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_plane.create(1, 1, m_hm_image,
m_groud_resolution->get_value() * 5.f, get_height());
m_hm_plane.create(1, 1, m_hm_image, get_resolution(), get_height());
m_hm_preview->SetHeight(100);
m_rt_dirty = true;
}
@@ -137,10 +138,38 @@ void NodePanelGrid::init_controls()
m_groud_opacity->set_value(0);
gl.restore();
};
m_texture.create(1024, 1024);
m_hm_texres->on_select = [this](Node*, int index) {
int rexres = get_texres();
m_texture.create(rexres, rexres);
};
int rexres = get_texres();
m_texture.create(rexres, rexres);
m_sampler_linear.create();
m_sampler_linear.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
m_sphere.create<8, 8>(.0001f);
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, m_line_range);
//glGetFloatv(GL_ALIASED_LINE_WIDTH_GRANULARITY, &m_line_granularity);
}
int NodePanelGrid::get_samples() const
{
return atoi(m_hm_samples->m_items[m_hm_samples->m_current_index].c_str());
}
int NodePanelGrid::get_texres() const
{
return atoi(m_hm_texres->m_items[m_hm_texres->m_current_index].c_str());
}
float NodePanelGrid::get_thickness() const
{
return glm::lerp(m_line_range[0], m_line_range[1], m_hm_thickness->get_value());
}
float NodePanelGrid::get_resolution() const
{
return atof(m_groud_resolution->m_items[m_groud_resolution->m_current_index].c_str());
}
float NodePanelGrid::get_height() const
@@ -160,7 +189,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
auto nav = -(m_hm_preview_nav->m_value - 0.5f);
auto nav = m_hm_image.m_data ? -(m_hm_preview_nav->m_value - 0.5f) : glm::vec2(0);
auto mvp = proj * camera
* glm::translate(glm::vec3(0, get_offset(), 0))
* glm::translate(glm::vec3(nav.x, get_offset(), nav.y));
@@ -231,7 +260,11 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
m_hm_plane.draw_fill();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
float current_width = 1;
glGetFloatv(GL_LINE_WIDTH, &current_width);
glLineWidth(get_thickness());
m_hm_plane.draw_stroke();
glLineWidth(current_width);
}
}
}
@@ -296,6 +329,7 @@ void NodePanelGrid::bake_uvs()
std::atomic_int pb_value(0);
auto data_out = std::make_unique<uint8_t[]>(fb.getWidth() * fb.getHeight() * 4);
const auto samples = get_samples();
std::thread worker([&]
{
__block float* d_pos = data_pos.get();
@@ -324,7 +358,7 @@ void NodePanelGrid::bake_uvs()
}
int hit = 0;
for (int s = 0; s < 16; s++)
for (int s = 0; s < samples; s++)
{
auto dir = glm::normalize(light_dir + glm::sphericalRand(.1f));
@@ -344,7 +378,7 @@ void NodePanelGrid::bake_uvs()
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);
out = glm::lerp(glm::vec4(255, 255, 255, 255), glm::vec4(50, 50, 50, 255), hit / (float)samples);
}
pb_value++;
}