fix grid bounds calculation issue with float framebuffer
This commit is contained in:
@@ -316,7 +316,7 @@
|
||||
<!--<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="20" pad="1" width="100%"><slider-h id="grid-heightmap-lpitch" value="0.1"/></node>
|
||||
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-ambient" value="0.0"/></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="2"/>
|
||||
|
||||
@@ -2221,6 +2221,12 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, layer.w, layer.h);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
RTT rtt;
|
||||
rtt.create(layer.w, layer.h);
|
||||
rtt.bindFramebuffer();
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
|
||||
rtt.unbindFramebuffer();
|
||||
|
||||
// allocate action to add to history
|
||||
auto action = new ActionStroke;
|
||||
action->was_saved = !m_unsaved;
|
||||
@@ -2229,14 +2235,12 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
glm::mat4 plane_camera = glm::lookAt(glm::vec3(0), m_plane_origin[i], m_plane_tangent[i]);
|
||||
m_tmp[i].bindFramebuffer();
|
||||
m_tmp[i].clear({ 1, 1, 1, 0 });
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
|
||||
rtt.bindFramebuffer();
|
||||
rtt.clear({ 1, 1, 1, 0 });
|
||||
observer(plane_camera, proj, i);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
m_tmp[i].unbindFramebuffer();
|
||||
rtt.unbindFramebuffer();
|
||||
|
||||
glm::vec4 bounds = m_tmp[i].calc_bounds();
|
||||
glm::vec4 bounds = rtt.calc_bounds();
|
||||
|
||||
layer.m_rtt[i].bindFramebuffer();
|
||||
|
||||
@@ -2246,9 +2250,9 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
{
|
||||
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_box[i] = bounds;
|
||||
action->m_old_box[i] = layer.m_dirty_box[i];
|
||||
action->m_old_dirty[i] = layer.m_dirty_face[i];
|
||||
|
||||
@@ -2258,9 +2262,9 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-0.5f, 0.5f, -0.5f, 0.5f));
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_sampler_nearest.bind(0);
|
||||
m_tmp[i].bindTexture();
|
||||
rtt.bindTexture();
|
||||
m_plane.draw_fill();
|
||||
m_tmp[i].unbindTexture();
|
||||
rtt.unbindTexture();
|
||||
|
||||
layer.m_rtt[i].unbindFramebuffer();
|
||||
|
||||
@@ -2275,6 +2279,7 @@ void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm:
|
||||
ActionManager::add(action);
|
||||
|
||||
glDeleteRenderbuffers(1, &rboID);
|
||||
rtt.destroy();
|
||||
|
||||
// restore viewport and clear color states
|
||||
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
||||
|
||||
@@ -351,7 +351,7 @@ void NodeCanvas::draw()
|
||||
for (auto& mode : Canvas::modes[(int)Canvas::kCanvasMode::Grid])
|
||||
mode->on_Draw(ortho_proj, proj, camera);
|
||||
|
||||
App::I.grid->draw_heightmap(proj, camera);
|
||||
App::I.grid->draw_heightmap(proj, camera, false);
|
||||
|
||||
for (auto& mode : *m_canvas->m_mode)
|
||||
mode->on_Draw(ortho_proj, proj, camera);
|
||||
|
||||
@@ -134,7 +134,7 @@ void NodePanelGrid::init_controls()
|
||||
gl_state gl;
|
||||
gl.save();
|
||||
Canvas::I->draw_objects([this](const glm::mat4& camera, const glm::mat4& proj, int i) {
|
||||
draw_heightmap(proj, camera);
|
||||
draw_heightmap(proj, camera, true);
|
||||
});
|
||||
m_groud_opacity->set_value(0);
|
||||
gl.restore();
|
||||
@@ -156,9 +156,12 @@ void NodePanelGrid::init_controls()
|
||||
};
|
||||
int rexres = get_texres();
|
||||
m_texture.create(rexres, rexres);
|
||||
m_sampler_mipmap.create();
|
||||
m_sampler_mipmap.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
|
||||
m_sampler_linear.create();
|
||||
m_sampler_linear.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
|
||||
m_sphere.create<8, 8>(.0001f);
|
||||
m_plane.create<1>(1, 1);
|
||||
|
||||
TextureManager::load("data/sun.png");
|
||||
|
||||
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, m_line_range);
|
||||
//glGetFloatv(GL_ALIASED_LINE_WIDTH_GRANULARITY, &m_line_granularity);
|
||||
@@ -199,7 +202,7 @@ float NodePanelGrid::get_offset() const
|
||||
return glm::pow(m_groud_offset->get_value() - 0.5f, 3);
|
||||
}
|
||||
|
||||
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera) const
|
||||
void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const
|
||||
{
|
||||
if (m_groud_opacity->get_value() > 0.f)
|
||||
{
|
||||
@@ -216,14 +219,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
|
||||
auto light_pos = glm::vec3(sinf(light_yaw) + nav.x, light_pitch + get_offset(), cosf(light_yaw) + nav.y);
|
||||
auto light_dir = glm::normalize(light_pos);
|
||||
|
||||
// DRAW SUN SPHERE
|
||||
glDisable(GL_BLEND);
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, proj * camera *
|
||||
glm::translate(light_pos) * glm::scale(glm::vec3(.1f)));
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, { 1, 0, 0, 1 });
|
||||
m_sphere.draw_fill();
|
||||
|
||||
// DRAW SOLID
|
||||
if (m_hm_image.m_data)
|
||||
{
|
||||
@@ -254,7 +250,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
|
||||
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
|
||||
ShaderManager::u_float(kShaderUniform::Ambient, get_ambient());
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
m_sampler_linear.bind(0);
|
||||
m_sampler_mipmap.bind(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_texture.bind();
|
||||
m_hm_plane.draw_fill();
|
||||
@@ -282,6 +278,29 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
|
||||
}
|
||||
m_hm_plane.draw_stroke();
|
||||
}
|
||||
|
||||
// DRAW SUN SPHERE
|
||||
if (!commit)
|
||||
{
|
||||
auto c = proj * camera * glm::translate(light_pos) * glm::vec4(0, 0, 0, 1);
|
||||
if (c.w > 0)
|
||||
{
|
||||
auto p2d = xy(c) / c.z;
|
||||
GLint vp[4];
|
||||
glGetIntegerv(GL_VIEWPORT, vp);
|
||||
auto aspect_ratio = (float)vp[3] / (float)vp[2];
|
||||
glEnable(GL_BLEND);
|
||||
ShaderManager::use(kShader::Texture);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-1.f, 1.f, -1.f, 1.f) *
|
||||
glm::translate(glm::vec3(p2d, 0)) * glm::scale(glm::vec3(.1f * aspect_ratio, .1f, 1.f)));
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_sampler_linear.bind(0);
|
||||
constexpr auto sun_tex = const_hash("data/sun.png");
|
||||
TextureManager::get(sun_tex).bind();
|
||||
m_plane.draw_fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,10 @@ public:
|
||||
NodeButton* m_commit;
|
||||
HeightmapPlane m_hm_plane;
|
||||
NodeHeightmapOverlay* m_hm_preview_nav;
|
||||
Sphere m_sphere;
|
||||
Plane m_plane;
|
||||
Image m_hm_image;
|
||||
Texture2D m_texture;
|
||||
Sampler m_sampler_mipmap;
|
||||
Sampler m_sampler_linear;
|
||||
std::string m_file_path;
|
||||
nanort::BVHAccel<float> m_rt_accel;
|
||||
@@ -79,6 +80,6 @@ public:
|
||||
float get_resolution() const;
|
||||
float get_height() const;
|
||||
float get_offset() const;
|
||||
void draw_heightmap(const glm::mat4& proj, const glm::mat4& camera) const;
|
||||
void draw_heightmap(const glm::mat4& proj, const glm::mat4& camera, bool commit) const;
|
||||
void bake_uvs();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user