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

@@ -163,6 +163,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="20" justify="center" margin="5 0 5 0"><text text="Shade" 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>
@@ -178,6 +179,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="20" pad="1" width="100%" margin="5 0 5 0"><slider-h id="tip-shade" value="1"/></node>
<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>
@@ -269,14 +271,16 @@
<node width="40%" dir="col">
<node height="20" justify="center"><text text="Opacity" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Value" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Resolution" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Offset" font-face="arial" font-size="11"/></node>
<node height="30" justify="center" margin="5 0 0 0"><text text="Resolution" font-face="arial" font-size="11"/></node>
</node>
<node dir="col" align="center" grow="1" width="1" flood-events="1">
<node height="20" pad="1" width="100%"><slider-h id="grid-ground-opacity"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-ground-value" value="0.0"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-ground-resolution" value="0.2"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-ground-offset" value="0.25"/></node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-ground-resolution" width="100%" height="30" combo-list="0.1,0.5,1,2,4,8" default="2"/>
</node>
</node>
</node>
<node height="5"/>
@@ -289,9 +293,12 @@
<node height="30" justify="center"><text text="File" font-face="arial" font-size="11"/></node>
<node height="30" justify="center" margin="5 0 0 0"><text text="Shading" font-face="arial" font-size="11"/></node>
<node height="20" justify="center" margin="5 0 0 0"><text text="Wireframe" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Thickness" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="Height" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="L-Yaw" font-face="arial" font-size="11"/></node>
<node height="20" justify="center"><text text="L-Pitch" font-face="arial" font-size="11"/></node>
<node height="30" justify="center" margin="5 0 0 0"><text text="Samples" font-face="arial" font-size="11"/></node>
<node height="30" justify="center" margin="5 0 0 0"><text text="Tex Res." font-face="arial" font-size="11"/></node>
</node>
<node dir="col" align="center" grow="1" width="1" flood-events="1" color=".3" >
<node height="30" width="100%" dir="row" pad="0 1 0 1">
@@ -305,13 +312,20 @@
<combobox id="grid-heightmap-shading" width="100%" height="30" combo-list="Transparent,Flat,Solid,Textured" default="0"/>
</node>
<node height="20" pad="1" width="100%" margin="5 0 0 0"><slider-h id="grid-heightmap-wireframe" value="1.0"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-thickness" value="0.5"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-height" value="0.25"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-lyaw" value="0.5"/></node>
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-lpitch" value="0.5"/></node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-samples" width="100%" height="30" combo-list="1,4,8,16,32,64,128" default="3"/>
</node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-texres" width="100%" height="30" combo-list="256,512,1024,2048,4096" default="2"/>
</node>
</node>
<button id="grid-render" text="Render" height="30" margin="5 0 0 0"/>
<button id="grid-commit" text="Commit" height="30" margin="5 0 0 0"/>
</node>
<button id="grid-render" text="Render Lightmap" height="30" margin="5 0 0 0"/>
<button id="grid-commit" text="Commit to Layer" height="30" margin="5 0 0 0"/>
</border>
</node>

View File

@@ -373,7 +373,7 @@ void App::init()
title_update();
GLfloat width_range[2];
glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, width_range);
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, width_range);
LOG("GL line range: %f - %f", width_range[0], width_range[1]);
LOG("Screen Size: %f %f", width, height);

View File

@@ -161,8 +161,11 @@ void Canvas::snap_history(const std::vector<int>& planes)
// save image before commit
glm::vec2 box_or = xy(m_layers[m_current_layer_idx].m_dirty_box[i]);
glm::vec2 box_sz = zw(m_layers[m_current_layer_idx].m_dirty_box[i]) - xy(m_layers[m_current_layer_idx].m_dirty_box[i]);
if (box_sz.x > 0 && box_sz.y > 0)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
}
action->m_box[i] = m_layers[m_current_layer_idx].m_dirty_box[i];
action->m_old_box[i] = m_layers[m_current_layer_idx].m_dirty_box[i];
@@ -190,8 +193,11 @@ ActionStroke* Canvas::create_action(int layer)
// save image before commit
glm::vec2 box_or = xy(m_layers[layer].m_dirty_box[i]);
glm::vec2 box_sz = zw(m_layers[layer].m_dirty_box[i]) - xy(m_layers[layer].m_dirty_box[i]);
if (box_sz.x > 0 && box_sz.y > 0)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
}
action->m_box[i] = m_layers[layer].m_dirty_box[i];
action->m_old_box[i] = m_layers[layer].m_dirty_box[i];
@@ -2231,15 +2237,16 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
m_tmp[i].unbindFramebuffer();
glm::vec4 bounds = m_tmp[i].calc_bounds();
glm::vec2 box_sz = zw(bounds) - xy(bounds);
if (box_sz.x <= 0 || box_sz.y <= 0)
continue;
layer.m_rtt[i].bindFramebuffer();
// save image before commit
glm::vec2 box_sz = zw(bounds) - xy(bounds);
if (box_sz.x > 0 && box_sz.y > 0)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
glReadPixels(bounds.x, bounds.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());
}
action->m_box[i] = bounds;
action->m_old_box[i] = layer.m_dirty_box[i];

View File

@@ -73,10 +73,13 @@ void NodeBorder::draw()
if (m_thinkness > 0 && m_border_color.a > 0.f)
{
float current_width = 1;
glGetFloatv(GL_LINE_WIDTH, &current_width);
glLineWidth(m_thinkness);
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
m_border_color.a < 1.f ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
m_plane.draw_stroke();
glLineWidth(current_width);
glDisable(GL_BLEND);
}
}

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++;
}

View File

@@ -38,7 +38,7 @@ public:
NodeSliderH* m_groud_opacity;
NodeSliderH* m_groud_value;
NodeSliderH* m_groud_resolution;
NodeComboBox* m_groud_resolution;
NodeSliderH* m_groud_offset;
NodeImageTexture* m_hm_preview;
NodeButton* m_hm_load;
@@ -47,8 +47,11 @@ public:
NodeComboBox* m_hm_shading;
NodeSliderH* m_hm_height;
NodeSliderH* m_hm_wireframe;
NodeSliderH* m_hm_thickness;
NodeSliderH* m_hm_lyaw;
NodeSliderH* m_hm_lpitch;
NodeComboBox* m_hm_texres;
NodeComboBox* m_hm_samples;
NodeButton* m_render;
NodeButton* m_commit;
HeightmapPlane m_hm_plane;
@@ -61,11 +64,17 @@ public:
nanort::BVHAccel<float> m_rt_accel;
bool m_rt_dirty = true;;
ShadeMode m_shade_mode{ ShadeMode::Transparent };
GLfloat m_line_range[2];
GLfloat m_line_granularity;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;
void init_controls();
int get_samples() const;
int get_texres() const;
float get_thickness() const;
float get_resolution() const;
float get_height() const;
float get_offset() const;
void draw_heightmap(const glm::mat4& proj, const glm::mat4& camera) const;

View File

@@ -180,6 +180,7 @@ struct gl_state
GLint program;
GLint fb;
GLint active_tex;
GLfloat line_width;
void save()
{
blend = glIsEnabled(GL_BLEND);
@@ -187,6 +188,7 @@ struct gl_state
scissor_test = glIsEnabled(GL_SCISSOR_TEST);
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
glGetFloatv(GL_LINE_WIDTH, &line_width);
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb);
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_tex);
@@ -215,5 +217,6 @@ struct gl_state
}
glActiveTexture(active_tex);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube);
glLineWidth(line_width);
}
};