From 9feb51764077093a95a7b98af4b936a242096087 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sat, 25 Dec 2021 11:37:53 +0500 Subject: Added smooth lighting settings parameter --- cwd/assets/altcraft/scripts/ui.lua | 1 + cwd/assets/altcraft/ui/options-styles.rcss | 2 +- cwd/assets/altcraft/ui/options.rml | 6 ++++++ src/Render.cpp | 3 ++- src/RendererSectionData.cpp | 9 ++++----- src/RendererSectionData.hpp | 2 +- src/RendererWorld.cpp | 7 ++++--- src/RendererWorld.hpp | 5 ++--- 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua index 5973fc4..b8a7329 100644 --- a/cwd/assets/altcraft/scripts/ui.lua +++ b/cwd/assets/altcraft/scripts/ui.lua @@ -8,6 +8,7 @@ local options = { targetFps = 60, vsync = false, wireframe = false, + smoothlight = false, ssaoSamples = 0, ssaoScale = 0.5, } diff --git a/cwd/assets/altcraft/ui/options-styles.rcss b/cwd/assets/altcraft/ui/options-styles.rcss index 4822580..13c20d2 100644 --- a/cwd/assets/altcraft/ui/options-styles.rcss +++ b/cwd/assets/altcraft/ui/options-styles.rcss @@ -80,5 +80,5 @@ input.range sliderarrowinc { width: 45%; height: 8%; position: fixed; - margin: 3% auto auto; + margin: 0% auto auto; } diff --git a/cwd/assets/altcraft/ui/options.rml b/cwd/assets/altcraft/ui/options.rml index 7211ef2..4529487 100644 --- a/cwd/assets/altcraft/ui/options.rml +++ b/cwd/assets/altcraft/ui/options.rml @@ -61,6 +61,12 @@ +
+ + + +
+
diff --git a/src/Render.cpp b/src/Render.cpp index 304f25f..fe9dc04 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -534,7 +534,7 @@ void Render::InitEvents() { listener.RegisterHandler("PlayerConnected", [this](const Event&) { stateString = "Loading terrain..."; - world = std::make_unique(fbTarget, Settings::ReadBool("deffered", false)); + world = std::make_unique(fbTarget, Settings::ReadBool("deffered", false), Settings::ReadBool("smoothlight", false)); world->MaxRenderingDistance = Settings::ReadDouble("renderDistance", 2.0f); PUSH_EVENT("UpdateSectionsRender", 0); }); @@ -606,6 +606,7 @@ void Render::InitEvents() { listener.RegisterHandler("SettingsUpdate", [this](const Event& eventData) { if (world) { + world->smoothLighting = Settings::ReadBool("smoothlight", false); float renderDistance = Settings::ReadDouble("renderDistance", 2.0f); if (renderDistance != world->MaxRenderingDistance) { world->MaxRenderingDistance = renderDistance; diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index b5260f4..761dd14 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -59,7 +59,7 @@ float InterpolateBlockLightness(const BlockLightness& light, const glm::vec3 &po return (glm::max)(xLight, (glm::max)(yLight, zLight)); } -void AddFacesByBlockModel(RendererSectionData& data, const BlockFaces& model, const glm::mat4& transform, bool visibility[FaceDirection::none], const Vector &pos, const SectionsData §ions) { +void AddFacesByBlockModel(RendererSectionData& data, const BlockFaces& model, const glm::mat4& transform, bool visibility[FaceDirection::none], const Vector &pos, const SectionsData §ions, bool smoothLighting) { glm::vec3 absPos = (sections.data[1][1][1].GetPosition() * 16).glm(); for (const auto& face : model.faces) { if (face.visibility != FaceDirection::none) { @@ -100,8 +100,7 @@ void AddFacesByBlockModel(RendererSectionData& data, const BlockFaces& model, co vertexData.layerAnimationAo.g = face.frames; vertexData.colors = face.color; - bool useSmoothLighting = true; - if (useSmoothLighting) { + if (smoothLighting) { for (size_t i = 0; i < 4; i++) { glm::vec3 baseLightPos = vertexData.positions[i] - absPos; glm::vec3 lightPos = baseLightPos + normal * 0.5f; @@ -188,7 +187,7 @@ std::array SetBlockIdData(const SectionsData §ions) { return blockIdData; } -RendererSectionData ParseSection(const SectionsData §ions) { +RendererSectionData ParseSection(const SectionsData §ions, bool smoothLighting) { OPTICK_EVENT(); RendererSectionData data; @@ -214,7 +213,7 @@ RendererSectionData ParseSection(const SectionsData §ions) { transform = glm::translate(baseOffset, vec.glm()); BlockFaces *model = GetInternalBlockModel(block, idModels); - AddFacesByBlockModel(data, *model, transform, blockVisibility[y * 256 + z * 16 + x], vec, sections); + AddFacesByBlockModel(data, *model, transform, blockVisibility[y * 256 + z * 16 + x], vec, sections, smoothLighting); } } } diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index 9eb99ad..0f9ade6 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -74,4 +74,4 @@ struct RendererSectionData { bool forced = false; }; -RendererSectionData ParseSection(const SectionsData §ions); \ No newline at end of file +RendererSectionData ParseSection(const SectionsData §ions, bool smoothLighting); diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index 057cf1e..af177d7 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -26,7 +26,7 @@ void RendererWorld::WorkerFunction(size_t workerId) { return; size_t id = std::get<1>(data); bool forced = std::get<2>(data); - parsing[id].renderer = ParseSection(parsing[id].data); + parsing[id].renderer = ParseSection(parsing[id].data, smoothLighting); parsing[id].renderer.forced = forced; PUSH_EVENT("SectionParsed", id); }); @@ -153,8 +153,9 @@ void RendererWorld::UpdateAllSections(VectorF playerPos) { } } -RendererWorld::RendererWorld(std::shared_ptr target, bool defferedShading) { - OPTICK_EVENT(); +RendererWorld::RendererWorld(std::shared_ptr target, bool defferedShading, bool smoothLighting) { + OPTICK_EVENT(); + this->smoothLighting = smoothLighting; MaxRenderingDistance = 2; numOfWorkers = _max(1, (signed int) std::thread::hardware_concurrency() - 2); diff --git a/src/RendererWorld.hpp b/src/RendererWorld.hpp index 184323d..438c022 100644 --- a/src/RendererWorld.hpp +++ b/src/RendererWorld.hpp @@ -55,7 +55,7 @@ class RendererWorld { std::shared_ptr skyPipelineInstance; std::shared_ptr skyBuffer; public: - RendererWorld(std::shared_ptr target, bool defferedShading); + RendererWorld(std::shared_ptr target, bool defferedShading, bool smoothLighting); ~RendererWorld(); void Render(float screenRatio); @@ -63,8 +63,7 @@ public: double MaxRenderingDistance; - float shaderDayTime; - void Update(double timeToUpdate); + bool smoothLighting; }; -- cgit v1.2.3