Skip to content

Commit

Permalink
Merged smooth lighting config options.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jun 29, 2020
1 parent 466c0cf commit abbf55f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
3 changes: 1 addition & 2 deletions config/client.example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ isCrosshairVisible = true

-- Graphics
renderDistance = 8
isTorchSmoothLightingEnabled = true
isSunSmoothLightingEnabled = true
isSmoothLightingEnabled = true
isAmbientOcclusionEnabled = false
isWireframeModeEnabled = false
isFullscreenModeEnabled = false
Expand Down
9 changes: 3 additions & 6 deletions source/client/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ bool Config::isCrosshairVisible = true;

// Graphics
u16 Config::renderDistance = 8;
bool Config::isTorchSmoothLightingEnabled = true;
bool Config::isSunSmoothLightingEnabled = true;
bool Config::isSmoothLightingEnabled = true;
bool Config::isAmbientOcclusionEnabled = false;
bool Config::isWireframeModeEnabled = false;
bool Config::isFullscreenModeEnabled = false;
Expand Down Expand Up @@ -81,8 +80,7 @@ void Config::loadConfigFromFile(const char *filename) {
isCrosshairVisible = lua["isCrosshairVisible"].get_or(isCrosshairVisible);

renderDistance = lua["renderDistance"].get_or(renderDistance);
isTorchSmoothLightingEnabled = lua["isTorchSmoothLightingEnabled"].get_or(isTorchSmoothLightingEnabled);
isSunSmoothLightingEnabled = lua["isSunSmoothLightingEnabled"].get_or(isSunSmoothLightingEnabled);
isSmoothLightingEnabled = lua["isSmoothLightingEnabled"].get_or(isSmoothLightingEnabled);
isAmbientOcclusionEnabled = lua["isAmbientOcclusionEnabled"].get_or(isAmbientOcclusionEnabled);
isWireframeModeEnabled = lua["isWireframeModeEnabled"].get_or(isWireframeModeEnabled);
isFullscreenModeEnabled = lua["isFullscreenModeEnabled"].get_or(isFullscreenModeEnabled);
Expand Down Expand Up @@ -118,8 +116,7 @@ void Config::saveConfigToFile(const char *filename) {
file << "isCrosshairVisible = " << (isCrosshairVisible ? "true" : "false") << std::endl;
file << std::endl;
file << "renderDistance = " << renderDistance << std::endl;
file << "isTorchSmoothLightingEnabled = " << (isTorchSmoothLightingEnabled ? "true" : "false") << std::endl;
file << "isSunSmoothLightingEnabled = " << (isSunSmoothLightingEnabled ? "true" : "false") << 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;
Expand Down
3 changes: 1 addition & 2 deletions source/client/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace Config {

// Graphics
extern u16 renderDistance;
extern bool isTorchSmoothLightingEnabled;
extern bool isSunSmoothLightingEnabled;
extern bool isSmoothLightingEnabled;
extern bool isAmbientOcclusionEnabled;
extern bool isWireframeModeEnabled;
extern bool isFullscreenModeEnabled;
Expand Down
14 changes: 11 additions & 3 deletions source/client/states/SettingsMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,17 @@ void SettingsMenuState::addGraphicsButtons() {

addToggleButton("Wireframe Mode", Config::isWireframeModeEnabled, false);

addToggleButton("Torch Smooth Lighting", Config::isTorchSmoothLightingEnabled, true);
addToggleButton("Sun Smooth Lighting", Config::isSunSmoothLightingEnabled, true);
addToggleButton("Ambient Occlusion", Config::isAmbientOcclusionEnabled, true);
m_menuWidget.addButton(std::string("Smooth Lighting: ") + (Config::isSmoothLightingEnabled ? "ON" : "OFF"), [&] (TextButton &button) {
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);

m_menuWidget.addButton("GUI Scale: " + std::to_string(Config::guiScale), [this] (TextButton &button) {
Config::guiScale = 1 + (Config::guiScale + 1) % 3;
Expand Down
2 changes: 2 additions & 0 deletions source/client/states/SettingsMenuState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class SettingsMenuState : public InterfaceState {
};

MenuState m_state = MenuState::Main;

TextButton *m_aoButton = nullptr;
};

#endif // SETTINGSMENUSTATE_HPP_
4 changes: 2 additions & 2 deletions source/client/world/ChunkBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ inline void ChunkBuilder::addFace(s8f x, s8f y, s8f z, s8f f, const ClientChunk
vertices[v].texCoord[0] = gk::qlerp(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U);
vertices[v].texCoord[1] = gk::qlerp(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V);

if (Config::isSunSmoothLightingEnabled && block.drawType() != BlockDrawType::Liquid)
if (Config::isSmoothLightingEnabled && block.drawType() != BlockDrawType::Liquid)
vertices[v].lightValue[0] = getLightForVertex(Light::Sun, x, y, z, *neighbourOfs[v], normal, chunk);
else
vertices[v].lightValue[0] = chunk.lightmap().getSunlight(x + normal.x, y + normal.y, z + normal.z);

int torchlight = chunk.lightmap().getTorchlight(x, y, z);
if (Config::isTorchSmoothLightingEnabled && torchlight == 0 && block.drawType() != BlockDrawType::Liquid)
if (Config::isSmoothLightingEnabled && torchlight == 0 && block.drawType() != BlockDrawType::Liquid)
vertices[v].lightValue[1] = getLightForVertex(Light::Torch, x, y, z, *neighbourOfs[v], normal, chunk);
else
vertices[v].lightValue[1] = chunk.lightmap().getTorchlight(x + normal.x, y + normal.y, z + normal.z);
Expand Down

0 comments on commit abbf55f

Please sign in to comment.