feat(renderer): make ambient strength adjustable via dev panel

This commit is contained in:
2026-06-16 18:44:59 +08:00
parent a4f92e3659
commit 7ede49da72
4 changed files with 17 additions and 12 deletions

View File

@@ -27,8 +27,6 @@ constexpr int SIZE_X = CHUNK_SIZE;
constexpr int SIZE_Y = WORLD_SIZE_Y; constexpr int SIZE_Y = WORLD_SIZE_Y;
constexpr int SIZE_Z = CHUNK_SIZE; constexpr int SIZE_Z = CHUNK_SIZE;
constexpr float AMBIENT_STRENGTH = 0.3f;
constexpr ChunkPos CHUNK_DIR[]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}, constexpr ChunkPos CHUNK_DIR[]{{1, 0}, {-1, 0}, {0, 1}, {0, -1},
{1, 1}, {-1, 1}, {1, -1}, {-1, -1}}; {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};

View File

@@ -28,6 +28,7 @@ public:
void update_fov(float fov); void update_fov(float fov);
void update_proj_matrix(float aspect, float width, float height); void update_proj_matrix(float aspect, float width, float height);
void updata_framebuffer(int width, int height); void updata_framebuffer(int width, int height);
float& ambient_strength();
private: private:
static constexpr glm::vec3 SUNLIGHT_COLOR{1.0f, 1.0f, 1.0f}; static constexpr glm::vec3 SUNLIGHT_COLOR{1.0f, 1.0f, 1.0f};
@@ -38,6 +39,9 @@ private:
static constexpr float NEAR_PLANE = 0.1f; static constexpr float NEAR_PLANE = 0.1f;
static constexpr float SUN_SIZE = 50.0f; static constexpr float SUN_SIZE = 50.0f;
static constexpr float MOON_SIZE = 50.0f; static constexpr float MOON_SIZE = 50.0f;
float m_ambient_strength = 0.1f;
const Camera& m_camera; const Camera& m_camera;
DevPanel& m_dev_panel; DevPanel& m_dev_panel;
const TextureManager& m_texture_manager; const TextureManager& m_texture_manager;

View File

@@ -267,21 +267,17 @@ void DevPanel::show_time_table_bar() {
World& world = m_app.world(); World& world = m_app.world();
ImGui::Text("Game Tick %lld", world.game_tick()); ImGui::Text("Game Tick %lld", world.game_tick());
ImGui::Text("Day Tick %lld", world.day_tick()); ImGui::Text("Day Tick %lld", world.day_tick());
ImGui::Text("Set Day Tick"); if (ImGui::SliderInt("SetDayTick", &m_pre_set_day_tick, 0, DAY_TIME)) {
ImGui::SameLine();
if (ImGui::SliderInt("DayTick", &m_pre_set_day_tick, 0, DAY_TIME)) {
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Save##DayTick")) { if (ImGui::Button("Set##DayTick")) {
world.day_tick(static_cast<TickType>(m_pre_set_day_tick)); world.day_tick(static_cast<TickType>(m_pre_set_day_tick));
} }
ImGui::Text("MSPT %d", world.per_tick_time()); ImGui::Text("MSPT %d", world.per_tick_time());
ImGui::Text("Set MSPT");
ImGui::SameLine();
if (ImGui::SliderInt("SetMSPT", &m_pre_set_tick_speed, 0, 200)) { if (ImGui::SliderInt("SetMSPT", &m_pre_set_tick_speed, 0, 200)) {
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Save##MSPT")) { if (ImGui::Button("Set##MSPT")) {
world.per_tick_time(m_pre_set_tick_speed); world.per_tick_time(m_pre_set_tick_speed);
} }
} }
@@ -359,6 +355,10 @@ void DevPanel::show_settings_tab_item() {
static_cast<double>(m_config.mouse_sensitivity)); static_cast<double>(m_config.mouse_sensitivity));
m_player->hot_reload(); m_player->hot_reload();
} }
if (ImGui::SliderFloat("AmbientStrength",
&m_app.renderer().ambient_strength(), 0.0f,
0.35f))
;
if (ImGui::SliderInt("Distance", &m_config.rendering_distance, 2, if (ImGui::SliderInt("Distance", &m_config.rendering_distance, 2,
128)) { 128)) {
Config::get().set("world.rendering_distance", Config::get().set("world.rendering_distance",

View File

@@ -192,8 +192,8 @@ void Renderer::init_text() {
} }
void Renderer::render() { void Renderer::render() {
glDisable(GL_FRAMEBUFFER_SRGB);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
glClearColor(0.0, 0.0, 0.0, 1.0); glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -202,12 +202,13 @@ void Renderer::render() {
render_outline(); render_outline();
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glEnable(GL_FRAMEBUFFER_SRGB);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 1.0); glClearColor(0.0f, 0.0f, 0.0f, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
render_underwater(); render_underwater();
glDisable(GL_FRAMEBUFFER_SRGB);
render_ui(); render_ui();
render_text(); render_text();
render_dev_panel(); render_dev_panel();
@@ -479,7 +480,7 @@ void Renderer::render_world() {
glUniformMatrix4fv(m_proj_loc, 1, GL_FALSE, glm::value_ptr(m_p_mat)); glUniformMatrix4fv(m_proj_loc, 1, GL_FALSE, glm::value_ptr(m_p_mat));
glUniformMatrix4fv(normal_block_shader.loc("norm_matrix"), 1, GL_FALSE, glUniformMatrix4fv(normal_block_shader.loc("norm_matrix"), 1, GL_FALSE,
glm::value_ptr(m_norm_mat)); glm::value_ptr(m_norm_mat));
glUniform1f(normal_block_shader.loc("ambientStrength"), AMBIENT_STRENGTH); glUniform1f(normal_block_shader.loc("ambientStrength"), m_ambient_strength);
glUniform3fv(normal_block_shader.loc("sunlightColor"), 1, glUniform3fv(normal_block_shader.loc("sunlightColor"), 1,
glm::value_ptr(SUNLIGHT_COLOR)); glm::value_ptr(SUNLIGHT_COLOR));
glUniform3fv(normal_block_shader.loc("sunlightDir"), 1, glUniform3fv(normal_block_shader.loc("sunlightDir"), 1,
@@ -615,4 +616,6 @@ void Renderer::render_dev_panel() {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
float& Renderer::ambient_strength() { return m_ambient_strength; }
} // namespace Cubed } // namespace Cubed