diff --git a/data/layout.xml b/data/layout.xml index 6b1db2b..35d5245 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -316,7 +316,7 @@ - + diff --git a/src/canvas.cpp b/src/canvas.cpp index 2315e20..a7712b0 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -2221,6 +2221,12 @@ void Canvas::draw_objects(std::functionwas_saved = !m_unsaved; @@ -2229,14 +2235,12 @@ void Canvas::draw_objects(std::functionm_image[i] = std::make_unique(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::functionon_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); diff --git a/src/node_panel_grid.cpp b/src/node_panel_grid.cpp index d8bf69d..2da1bff 100644 --- a/src/node_panel_grid.cpp +++ b/src/node_panel_grid.cpp @@ -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(); + } + } } } diff --git a/src/node_panel_grid.h b/src/node_panel_grid.h index 5e7ea83..73f5b3b 100644 --- a/src/node_panel_grid.h +++ b/src/node_panel_grid.h @@ -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 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(); };