implement grid and heightmap with lambert shading

This commit is contained in:
2018-12-24 22:22:16 +01:00
parent 4d2706bfab
commit 52c87d9ec6
16 changed files with 297 additions and 101 deletions

View File

@@ -290,32 +290,42 @@ void NodeCanvas::draw()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
bool blend = glIsEnabled(GL_BLEND);
auto mvp = proj * camera
* glm::translate(glm::vec3(0, glm::pow(App::I.grid->m_groud_offset->get_value() - 0.5f, 3), 0))
* glm::scale(glm::vec3(1, glm::pow(App::I.grid->m_hm_height->get_value() - 0.5f, 3.f) * 10.f, 1))
* glm::eulerAngleX(glm::radians(90.f));
// DRAW SOLID
glDisable(GL_BLEND);
ShaderManager::use(kShader::Lambert);
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
auto light_yaw = App::I.grid->m_hm_lyaw->get_value() * glm::pi<float>() * 2.f;
auto light_pitch = App::I.grid->m_hm_lpitch->get_value();
auto light_pos = glm::vec3(sinf(light_yaw), cosf(light_yaw), light_pitch);
ShaderManager::u_vec3(kShaderUniform::LightDir, glm::normalize(-light_pos));
App::I.grid->m_hm_plane.draw_fill();
// DRAW GRIDS
ShaderManager::use(kShader::Color);
// ground grid
int grid_divs = glm::floor(App::I.grid->m_groud_scale->get_value() * 100);
if (grid_divs != m_grid_divs && (grid_divs % 2) == 0)
if (App::I.grid->m_hm_wireframe->get_value() > 0.f)
{
m_grid_divs = grid_divs;
m_grid.create(1, 1, grid_divs);
glEnable(GL_BLEND);
ShaderManager::use(kShader::Color);
ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(
glm::vec3(App::I.grid->m_groud_value->get_value()),
App::I.grid->m_groud_opacity->get_value() *
App::I.grid->m_hm_wireframe->get_value()
));
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
//glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
//App::I.grid->m_hm_plane.draw_fill();
//glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
App::I.grid->m_hm_plane.draw_stroke();
}
float grid_scale = m_grid_divs * 0.01f;
ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(
glm::vec3(App::I.grid->m_groud_value->get_value()),
App::I.grid->m_groud_opacity->get_value()));
ShaderManager::u_mat4(kShaderUniform::MVP, proj * camera
* glm::translate(glm::vec3(0, glm::pow(App::I.grid->m_groud_height->get_value() - 0.5f, 3), 0))
* glm::eulerAngleX(glm::radians(90.f))
* glm::scale(glm::vec3(grid_scale, grid_scale, 1))
);
//m_grid.draw_stroke();
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
App::I.grid->m_hm_plane.draw_fill();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
App::I.grid->m_hm_plane.draw_stroke();
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
}
// box grid