fix grid bounds calculation issue with float framebuffer
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user