diff --git a/source/client/core/Config.cpp b/source/client/core/Config.cpp index cc22b77d..5cee9dd7 100644 --- a/source/client/core/Config.cpp +++ b/source/client/core/Config.cpp @@ -50,8 +50,8 @@ bool Config::isCrosshairVisible = true; // Graphics u16 Config::renderDistance = 8; +u8 Config::ambientOcclusion = 2; bool Config::isSmoothLightingEnabled = true; -bool Config::isAmbientOcclusionEnabled = false; bool Config::isWireframeModeEnabled = false; bool Config::isFullscreenModeEnabled = false; bool Config::isVerticalSyncEnabled = true; @@ -90,16 +90,16 @@ void Config::loadConfigFromFile(const char *filename) { isCrosshairVisible = lua["isCrosshairVisible"].get_or(isCrosshairVisible); renderDistance = lua["renderDistance"].get_or(renderDistance); + ambientOcclusion = std::clamp(lua["ambientOcclusion"].get_or(ambientOcclusion), 0, 2); isSmoothLightingEnabled = lua["isSmoothLightingEnabled"].get_or(isSmoothLightingEnabled); - isAmbientOcclusionEnabled = lua["isAmbientOcclusionEnabled"].get_or(isAmbientOcclusionEnabled); isWireframeModeEnabled = lua["isWireframeModeEnabled"].get_or(isWireframeModeEnabled); isFullscreenModeEnabled = lua["isFullscreenModeEnabled"].get_or(isFullscreenModeEnabled); isVerticalSyncEnabled = lua["isVerticalSyncEnabled"].get_or(isVerticalSyncEnabled); cameraFOV = lua["cameraFOV"].get_or(cameraFOV); screenWidth = lua["screenWidth"].get_or(screenWidth); screenHeight = lua["screenHeight"].get_or(screenHeight); - guiScale = lua["guiScale"].get_or(guiScale); - mipmapLevels = lua["mipmapLevels"].get_or(mipmapLevels); + guiScale = std::clamp(lua["guiScale"].get_or(guiScale), 1, 3); + mipmapLevels = std::clamp(lua["mipmapLevels"].get_or(mipmapLevels), 0, 4); mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity); @@ -126,8 +126,8 @@ void Config::saveConfigToFile(const char *filename) { file << "isCrosshairVisible = " << (isCrosshairVisible ? "true" : "false") << std::endl; file << std::endl; file << "renderDistance = " << renderDistance << std::endl; + file << "ambientOcclusion = " << (u16)ambientOcclusion << std::endl; file << "isSmoothLightingEnabled = " << (isSmoothLightingEnabled ? "true" : "false") << std::endl; - file << "isAmbientOcclusionEnabled = " << (isAmbientOcclusionEnabled ? "true" : "false") << std::endl; file << "isWireframeModeEnabled = " << (isWireframeModeEnabled ? "true" : "false") << std::endl; file << "isFullscreenModeEnabled = " << (isFullscreenModeEnabled ? "true" : "false") << std::endl; file << "isVerticalSyncEnabled = " << (isVerticalSyncEnabled ? "true" : "false") << std::endl; diff --git a/source/client/core/Config.hpp b/source/client/core/Config.hpp index 84764ea8..2121196e 100644 --- a/source/client/core/Config.hpp +++ b/source/client/core/Config.hpp @@ -45,8 +45,8 @@ namespace Config { // Graphics extern u16 renderDistance; + extern u8 ambientOcclusion; extern bool isSmoothLightingEnabled; - extern bool isAmbientOcclusionEnabled; extern bool isWireframeModeEnabled; extern bool isFullscreenModeEnabled; extern bool isVerticalSyncEnabled; diff --git a/source/client/states/SettingsMenuState.cpp b/source/client/states/SettingsMenuState.cpp index cf4faac6..f226d8d1 100644 --- a/source/client/states/SettingsMenuState.cpp +++ b/source/client/states/SettingsMenuState.cpp @@ -215,13 +215,21 @@ void SettingsMenuState::addGraphicsButtons() { Config::isSmoothLightingEnabled = !Config::isSmoothLightingEnabled; button.setText(std::string("Smooth Lighting: ") + (Config::isSmoothLightingEnabled ? "ON" : "OFF")); - m_aoButton->setEnabled(!Config::isSmoothLightingEnabled); - World::isReloadRequested = true; }); - m_aoButton = &addToggleButton("Ambient Occlusion", Config::isAmbientOcclusionEnabled, true); - m_aoButton->setEnabled(!Config::isSmoothLightingEnabled); + const std::string aoValueNames[3] = { + "OFF", + "Normal", + "Smooth Lighting" + }; + + m_menuWidget.addButton(std::string("Ambient Occlusion: ") + aoValueNames[Config::ambientOcclusion], [&, aoValueNames] (TextButton &button) { + Config::ambientOcclusion = (Config::ambientOcclusion + 1) % (Config::isSmoothLightingEnabled ? 3 : 2); + button.setText(std::string("Ambient Occlusion: ") + aoValueNames[Config::ambientOcclusion]); + + World::isReloadRequested = true; + }); m_menuWidget.addSlider("GUI Scale: " + std::to_string(Config::guiScale), [this] (SliderWidget &slider, u32 eventType) { slider.setText("GUI Scale: " + std::to_string(slider.getCurrentValue())); diff --git a/source/client/world/ChunkBuilder.cpp b/source/client/world/ChunkBuilder.cpp index 407bc7f6..3d6d954d 100644 --- a/source/client/world/ChunkBuilder.cpp +++ b/source/client/world/ChunkBuilder.cpp @@ -260,7 +260,7 @@ inline void ChunkBuilder::addFace(s8f x, s8f y, s8f z, s8f f, const ClientChunk } auto addVertex = [&](u8 v) { - if (!Config::isAmbientOcclusionEnabled || Config::isSmoothLightingEnabled) + if (Config::ambientOcclusion != 1) vertices[v].ambientOcclusion = 5; if (blockState.drawType() == BlockDrawType::Liquid) @@ -411,10 +411,8 @@ inline u8 ChunkBuilder::getLightForVertex(Light light, s8f x, s8f y, s8f z, cons // continue; // If the chunk is initialized, add the light value to the total - if (lightValues[i] != -1) { - // float strength = ((surroundingBlocks[i] - normal == gk::Vector3i{x, y, z}) ? 1 : Config::aoStrength); - // total += lightValues[i] * strength; - // count += strength; + // But only add dark blocks if AO is set on Smooth Lighting + if (lightValues[i] != -1 && (Config::ambientOcclusion == 2 || lightValues[i] != 0)) { total += lightValues[i]; ++count; }