From f43e378bc02f37ff4d3b9bed0fc5fe5cfa8be1df Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Dec 2024 02:01:52 +0300 Subject: [PATCH 1/6] update leaves --- res/content/base/blocks/leaves.json | 4 +++- res/content/base/textures/blocks/leaves.png | Bin 6541 -> 753 bytes .../base/textures/blocks/leaves_culled.png | Bin 0 -> 6541 bytes 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 res/content/base/textures/blocks/leaves_culled.png diff --git a/res/content/base/blocks/leaves.json b/res/content/base/blocks/leaves.json index cdf9f014c..91182bc88 100644 --- a/res/content/base/blocks/leaves.json +++ b/res/content/base/blocks/leaves.json @@ -1,5 +1,7 @@ { "texture": "leaves", "material": "base:grass", - "base:durability": 0.7 + "base:durability": 0.7, + "culling": "optional", + "model": "aabb" } diff --git a/res/content/base/textures/blocks/leaves.png b/res/content/base/textures/blocks/leaves.png index 3beaf7ab9ad7c6304fc4ac43642e7103c425cfa3..9ea91852924b13e86424d2d03df46a5db0f463ea 100644 GIT binary patch delta 730 zcmV<00ww*8Gw}tGBYy(8Nkl+UY>)&Qd@$AX^C%2#BD@AVhue z%{MhB{wv=whF4zH2V$Z^N(2Hz1O=pp7?!e>j$LO;x8wAV9U)fzVCi>zwa`* z3{$idF}y!8o3uW#z)zR!Qy}33g@`?0@QU0}cu_{d(^LxTT&T zVzZOYCPHZ;82E!GL2N6H`pfH?HwV~!*G(pQMKJ@=oxcU_>>@-DDvL51_@%DX<(r(4b)(QOKs@4)6!HN zN9$~)Y6X+vcz@#z)eI4e0;ED2KARy1)h!~iWa|Im!IDArZ9WDdNTo5}AAaehuWt|e zn!7_HW%CS=kFpTkE+A`bk|2bPl#Mtx-FDONyn?zk^YH8)4%+{b1piPatO7;8N4$mnpig86*ONR%Ea{XMX^GPRCJhsW1-JGE`8)!wtZ5f=qHU|#{lGs$$Ul2#Gb{^NFN#A>dibi2K8}ZZgavj5@;UQYp#c=m+%ymxA7Zt~=UI$2lz7b4t3c!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res/content/base/textures/blocks/leaves_culled.png b/res/content/base/textures/blocks/leaves_culled.png new file mode 100644 index 0000000000000000000000000000000000000000..3beaf7ab9ad7c6304fc4ac43642e7103c425cfa3 GIT binary patch literal 6541 zcmeHKc{r5o`ya`^q=l1x42m+VVU}i4h*8!QkuqjpW0*xVgON}wdkLW|$$CVoIF+Jg zi>$4p#S%&)iW73G?>kyf=lXsBIoI|3{?}aBJMa5G_kDlv`~KYb^SsX!=j33cAgd+| zfj|@}wpK3ST}gCFOM?H}(_g3%h!ka?tGmF38UhXEaebLA04fL#1fYPB=?j4fpA@-y zrt7X({EML+B4b-qI5O4B_m!&rOZ|YY+xEwfUHG!>)v24TY;}4&zI=YQ_sc+&PC~+2 z+wN@gZs!7Clf_@5k3Kn=y$x9ym>hUo6IScJRpMF0yg_ewf9U&uBj+ZAaJ1g@n|}SZ zcl|z$#ORn^y-4yHqDDWImoVFNT(#ttyII+Z3pRe!&zi|`*^yWK^7n@_z2x2!;k3#%1?q)E6+WsYQCt98C+cs_m-IWm#X* zACzjDzww1QY4B+dRs!ogz56P`sRIdh= zfPlS$@CM(_@-lDVxa^85c`JQnu$o&%G(?Z?Gq``oZdph8KpAIku+8y$<s+ zXFwhUUEyAE+#nU%eni?rR=PA$Q>IZt-pP(Mpx3N~san39L9<+m0d zw-m#vt!s%#>qOYCYIL&KX*%KJpijB)%5Opcp3T3rWmSNT{`C|)M3L=17k%3kdOPD| zOI!g3rH;a#3Gt=f@#OVJZX~ZuXS#30|L92xxR$oY-g81aS1WAnS_Z-^Op{c9AR>{} zdOWYdAyc|Ym5~{mZn%vRuH^3+=(zuWYVP}%0>|*3#vWg)K1Z2gx`oD8DIVF%w;7+6?Lzi5|hYDu`(bjoe>4!!79=3Y}jw4~&ap2IS)w;I};f8&4o zja%Nxt$FvQHQV#yCw+e8`w!{?w6wgNsvCAzS^O#1ixb<}q#aE*%e#QS>g;yS;Fe$b zSZY`RdU>FZcW`u(MO$a#ZQ}#MmxH9H;tq6Sx;K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7(Yu|!cD5id|o_$#R5L`}8 ptgf(OVtak}^&^JL+RL_mmMS!%tP7X3EfvirinW7P`6lnE{{TaJeggmi literal 0 HcmV?d00001 From d021b443dd98b52a24215678b87882917795b0be Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Dec 2024 05:38:30 +0300 Subject: [PATCH 2/6] update leaves texture --- res/content/base/textures/blocks/leaves.png | Bin 753 -> 896 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/res/content/base/textures/blocks/leaves.png b/res/content/base/textures/blocks/leaves.png index 9ea91852924b13e86424d2d03df46a5db0f463ea..a9cd60e3e88fcc465db4b9933f6daf962ae574b8 100644 GIT binary patch delta 874 zcmV-w1C{*o1%L;TBYy)&Nkl>1D4<40mAXJqU)Y+!>B3-~RtV%LJivI`a{PzY5;XrWCT@*paW6E%)aY{%H1u{~pZJaf1n zDdBAHc|X2$uK4a}GqkdzV}9NbB@)E;mX7*{!A5g3_1i8Is(*;stb+CLYD`H-DB`!E z+d*7f3}SQ3f_Ur8f@j#9oJQwH1k|cM z3}q3V-nkma{-KF{-oau{#>QF$qvJ9T*6J+25GB_QU@7CruX_L!1yoN45a43@<0)x#KOo$ddBNI^hLs?duj#QklHcO~J{Wes<4{^PZkyAq{@VPa$5K$0gl@_@eEWJ}AVbkcC} z_f{L}iy?GvK0>A3M^qZXWenFo8mHSg%Ixlq0)LBURC4(?^J@k>9V0O-!-j>zA8mFR z^pi8-YwYZ`Sce-+J0%au;mI-#kXumE?K-%h@0{V_bZktXld#44@wU!LRC-~af1GCwJ5PH2mIXw)E*uSD=c)7m7Gytx_{FWS=%hgmKObE1foL|&%|5lA@&xdJjLO>+qgE(w?nBY17St>;bb+UY>)&Qd@$AX^C%2#BD@AVhue z%{MhB{wv=whF4zH2V$Z^N(2Hz1O=pp7?!e>j$LO;x8wAV9U)fzVCi>zwa`* z3{$idF}y!8o3uW#z)zR!Qy}33g@`?0@QU0}cu_{d(^LxTT&T zVzZOYCPHZ;82E!GL2N6H`pfH?HwV~!*G(pQMKJ@=oxcU_>>@-DDvL51_@%DX<(r(4b)(QOKs@4)6!HN zN9$~)Y6X+vcz@#z)eI4e0;ED2KARy1)h!~iWa|Im!IDArZ9WDdNTo5}AAaehuWt|e zn!7_HW%CS=kFpTkE+A`bk|2bPl#Mtx-FDONyn?zk^YH8)4%+{b1piPatO7;8N4$mnpig86*ONR%Ea{XMX^GPRCJhsW1-JGE`8)!wtZ5f=qHU|#{lGs$$Ul2#Gb{^NFN#A>dibi2K8}ZZgavj5@;UQYp#c=m+%ymxA7Zt~=UI$2lz7b4t3c!U&AmH+?% M07*qoM6N<$f^m3T-2eap From 954724c8378da525fc7349c018e9351c5bdfdf8f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Dec 2024 06:41:03 +0300 Subject: [PATCH 3/6] add 'culling' property & optimize generated chunk meshes & fix faces culling when 'light-passing' is false --- res/content/base/blocks/leaves.json | 4 +-- .../{leaves_culled.png => leaves_opaque.png} | Bin src/content/ContentLoader.cpp | 10 +++++++- src/graphics/render/BlocksRenderer.cpp | 24 +++++++++--------- src/graphics/render/BlocksRenderer.hpp | 8 ++++-- src/voxels/Block.cpp | 24 ++++++++++++++++++ src/voxels/Block.hpp | 12 +++++++++ 7 files changed, 65 insertions(+), 17 deletions(-) rename res/content/base/textures/blocks/{leaves_culled.png => leaves_opaque.png} (100%) diff --git a/res/content/base/blocks/leaves.json b/res/content/base/blocks/leaves.json index 91182bc88..e3ddae22d 100644 --- a/res/content/base/blocks/leaves.json +++ b/res/content/base/blocks/leaves.json @@ -1,7 +1,7 @@ { "texture": "leaves", "material": "base:grass", - "base:durability": 0.7, + "draw-group": 5, "culling": "optional", - "model": "aabb" + "base:durability": 0.7 } diff --git a/res/content/base/textures/blocks/leaves_culled.png b/res/content/base/textures/blocks/leaves_opaque.png similarity index 100% rename from res/content/base/textures/blocks/leaves_culled.png rename to res/content/base/textures/blocks/leaves_opaque.png diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index fee559e4f..1dc676ea4 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -239,10 +239,18 @@ void ContentLoader::loadBlock( } def.model = *model; } else if (!modelTypeName.empty()) { - logger.error() << "unknown model " << modelTypeName; + logger.error() << "unknown model: " << modelTypeName; def.model = BlockModel::none; } + std::string cullingModeName = to_string(def.culling); + root.at("culling").get(cullingModeName); + if (auto mode = CullingMode_from(cullingModeName)) { + def.culling = *mode; + } else { + logger.error() << "unknown culling mode: " << cullingModeName; + } + root.at("material").get(def.material); // rotation profile diff --git a/src/graphics/render/BlocksRenderer.cpp b/src/graphics/render/BlocksRenderer.cpp index cb590bcb4..f1e8001f1 100644 --- a/src/graphics/render/BlocksRenderer.cpp +++ b/src/graphics/render/BlocksRenderer.cpp @@ -342,41 +342,41 @@ void BlocksRenderer::blockCube( } if (ao) { - if (isOpen(coord + Z, group)) { + if (isOpen(coord + Z, block)) { faceAO(coord, X, Y, Z, texfaces[5], lights); } - if (isOpen(coord - Z, group)) { + if (isOpen(coord - Z, block)) { faceAO(coord, -X, Y, -Z, texfaces[4], lights); } - if (isOpen(coord + Y, group)) { + if (isOpen(coord + Y, block)) { faceAO(coord, X, -Z, Y, texfaces[3], lights); } - if (isOpen(coord - Y, group)) { + if (isOpen(coord - Y, block)) { faceAO(coord, X, Z, -Y, texfaces[2], lights); } - if (isOpen(coord + X, group)) { + if (isOpen(coord + X, block)) { faceAO(coord, -Z, Y, X, texfaces[1], lights); } - if (isOpen(coord - X, group)) { + if (isOpen(coord - X, block)) { faceAO(coord, Z, Y, -X, texfaces[0], lights); } } else { - if (isOpen(coord + Z, group)) { + if (isOpen(coord + Z, block)) { face(coord, X, Y, Z, texfaces[5], pickLight(coord + Z), lights); } - if (isOpen(coord - Z, group)) { + if (isOpen(coord - Z, block)) { face(coord, -X, Y, -Z, texfaces[4], pickLight(coord - Z), lights); } - if (isOpen(coord + Y, group)) { + if (isOpen(coord + Y, block)) { face(coord, X, -Z, Y, texfaces[3], pickLight(coord + Y), lights); } - if (isOpen(coord - Y, group)) { + if (isOpen(coord - Y, block)) { face(coord, X, Z, -Y, texfaces[2], pickLight(coord - Y), lights); } - if (isOpen(coord + X, group)) { + if (isOpen(coord + X, block)) { face(coord, -Z, Y, X, texfaces[1], pickLight(coord + X), lights); } - if (isOpen(coord - X, group)) { + if (isOpen(coord - X, block)) { face(coord, Z, Y, -X, texfaces[0], pickLight(coord - X), lights); } } diff --git a/src/graphics/render/BlocksRenderer.hpp b/src/graphics/render/BlocksRenderer.hpp index c0e0086e0..d27f681bb 100644 --- a/src/graphics/render/BlocksRenderer.hpp +++ b/src/graphics/render/BlocksRenderer.hpp @@ -118,7 +118,7 @@ class BlocksRenderer { bool isOpenForLight(int x, int y, int z) const; // Does block allow to see other blocks sides (is it transparent) - inline bool isOpen(const glm::ivec3& pos, ubyte group) const { + inline bool isOpen(const glm::ivec3& pos, const Block& def) const { auto id = voxelsBuffer->pickBlockId( chunk->x * CHUNK_W + pos.x, pos.y, chunk->z * CHUNK_D + pos.z ); @@ -126,7 +126,11 @@ class BlocksRenderer { return false; } const auto& block = *blockDefsCache[id]; - if ((block.drawGroup != group && block.lightPassing) || !block.rt.solid) { + if (((block.drawGroup != def.drawGroup) && block.drawGroup) || !block.rt.solid) { + return true; + } + if (def.culling == CullingMode::DISABLED || + (def.culling == CullingMode::OPTIONAL && id == def.rt.id)) { return true; } return !id; diff --git a/src/voxels/Block.cpp b/src/voxels/Block.cpp index 520f9f99b..96bca2458 100644 --- a/src/voxels/Block.cpp +++ b/src/voxels/Block.cpp @@ -49,6 +49,30 @@ std::optional BlockModel_from(std::string_view str) { return std::nullopt; } +std::string to_string(CullingMode mode) { + switch (mode) { + case CullingMode::DEFAULT: + return "default"; + case CullingMode::OPTIONAL: + return "optional"; + case CullingMode::DISABLED: + return "disabled"; + default: + return "unknown"; + } +} + +std::optional CullingMode_from(std::string_view str) { + if (str == "default") { + return CullingMode::DEFAULT; + } else if (str == "optional") { + return CullingMode::OPTIONAL; + } else if (str == "disabled") { + return CullingMode::DISABLED; + } + return std::nullopt; +} + CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ) : axisX(axisX), axisY(axisY), axisZ(axisZ) { fix = glm::ivec3(0); diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index 557bf04cb..eb232e8d8 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -97,6 +97,15 @@ enum class BlockModel { std::string to_string(BlockModel model); std::optional BlockModel_from(std::string_view str); +enum class CullingMode { + DEFAULT, + OPTIONAL, + DISABLED, +}; + +std::string to_string(CullingMode mode); +std::optional CullingMode_from(std::string_view str); + using BoxModel = AABB; /// @brief Common kit of block properties applied to groups of blocks @@ -142,6 +151,9 @@ class Block { std::string modelName = ""; + /// @brief Culling mode + CullingMode culling = CullingMode::DEFAULT; + /// @brief Does the block passing lights into itself bool lightPassing = false; From dc8f5e7873de10b966a43e172b070af753f998b8 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Dec 2024 08:13:05 +0300 Subject: [PATCH 4/6] add 'graphics.dense-render' setting --- res/layouts/pages/settings_graphics.xml.lua | 1 + res/texts/en_US.txt | 1 + res/texts/ru_RU.txt | 2 + src/files/settings_io.cpp | 1 + src/frontend/ContentGfxCache.cpp | 80 +++++++++++++-------- src/frontend/ContentGfxCache.hpp | 18 ++++- src/frontend/LevelFrontend.cpp | 21 ++++-- src/frontend/LevelFrontend.hpp | 9 ++- src/frontend/screens/LevelScreen.cpp | 8 ++- src/graphics/render/BlocksRenderer.cpp | 3 - src/graphics/render/BlocksRenderer.hpp | 8 ++- src/settings.hpp | 6 ++ 12 files changed, 111 insertions(+), 47 deletions(-) diff --git a/res/layouts/pages/settings_graphics.xml.lua b/res/layouts/pages/settings_graphics.xml.lua index 8a479a1c6..c4503e52c 100644 --- a/res/layouts/pages/settings_graphics.xml.lua +++ b/res/layouts/pages/settings_graphics.xml.lua @@ -41,4 +41,5 @@ function on_open() create_setting("graphics.fog-curve", "Fog Curve", 0.1) create_setting("graphics.gamma", "Gamma", 0.05, "", "graphics.gamma.tooltip") create_checkbox("graphics.backlight", "Backlight", "graphics.backlight.tooltip") + create_checkbox("graphics.dense-render", "Dense blocks render", "graphics.dense-render.tooltip") end diff --git a/res/texts/en_US.txt b/res/texts/en_US.txt index c19fe00a8..e9b238970 100644 --- a/res/texts/en_US.txt +++ b/res/texts/en_US.txt @@ -16,6 +16,7 @@ devtools.traceback=Traceback (most recent call first) # Tooltips graphics.gamma.tooltip=Lighting brightness curve graphics.backlight.tooltip=Backlight to prevent total darkness +graphics.dense-render.tooltip=Enables transparency in blocks like leaves # settings settings.Controls Search Mode=Search by attached button name diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index ae591042a..e78b5f729 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -28,6 +28,7 @@ pack.remove-confirm=Удалить весь поставляемый паком/ # Подсказки graphics.gamma.tooltip=Кривая яркости освещения graphics.backlight.tooltip=Подсветка, предотвращающая полную темноту +graphics.dense-render.tooltip=Включает прозрачность блоков, таких как листья. # Меню menu.Apply=Применить @@ -67,6 +68,7 @@ world.delete-confirm=Удалить мир безвозвратно? # Настройки settings.Ambient=Фон settings.Backlight=Подсветка +settings.Dense blocks render=Плотный рендер блоков settings.Camera Shaking=Тряска Камеры settings.Camera Inertia=Инерция Камеры settings.Camera FOV Effects=Эффекты поля зрения diff --git a/src/files/settings_io.cpp b/src/files/settings_io.cpp index d2a85f6a1..fe251a11e 100644 --- a/src/files/settings_io.cpp +++ b/src/files/settings_io.cpp @@ -68,6 +68,7 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) { builder.section("graphics"); builder.add("fog-curve", &settings.graphics.fogCurve); builder.add("backlight", &settings.graphics.backlight); + builder.add("dense-render", &settings.graphics.denseRender); builder.add("gamma", &settings.graphics.gamma); builder.add("frustum-culling", &settings.graphics.frustumCulling); builder.add("skybox-resolution", &settings.graphics.skyboxResolution); diff --git a/src/frontend/ContentGfxCache.cpp b/src/frontend/ContentGfxCache.cpp index c6ba4e1c3..844fd4e6d 100644 --- a/src/frontend/ContentGfxCache.cpp +++ b/src/frontend/ContentGfxCache.cpp @@ -6,53 +6,71 @@ #include "assets/Assets.hpp" #include "content/Content.hpp" #include "content/ContentPack.hpp" -#include "core_defs.hpp" #include "graphics/core/Atlas.hpp" #include "maths/UVRegion.hpp" #include "voxels/Block.hpp" +#include "core_defs.hpp" +#include "settings.hpp" -ContentGfxCache::ContentGfxCache(const Content* content, const Assets& assets) - : content(content) { - auto indices = content->getIndices(); - sideregions = std::make_unique(indices->blocks.count() * 6); - const auto& atlas = assets.require("blocks"); - const auto& blocks = indices->blocks.getIterable(); - for (blockid_t i = 0; i < blocks.size(); i++) { - auto def = blocks[i]; - for (uint side = 0; side < 6; side++) { - const std::string& tex = def->textureFaces[side]; - if (atlas.has(tex)) { - sideregions[i * 6 + side] = atlas.get(tex); - } else if (atlas.has(TEXTURE_NOTFOUND)) { - sideregions[i * 6 + side] = atlas.get(TEXTURE_NOTFOUND); - } +ContentGfxCache::ContentGfxCache( + const Content& content, + const Assets& assets, + const GraphicsSettings& settings +) + : content(content), assets(assets), settings(settings) { + refresh(); +} + +void ContentGfxCache::refresh(const Block& def, const Atlas& atlas) { + for (uint side = 0; side < 6; side++) { + std::string tex = def.textureFaces[side]; + if (def.culling == CullingMode::OPTIONAL && + !settings.denseRender.get() && atlas.has(tex + "_opaque")) { + tex = tex + "_opaque"; } - if (def->model == BlockModel::custom) { - auto model = assets.require(def->modelName); - // temporary dirty fix tbh - if (def->modelName.find(':') == std::string::npos) { - for (auto& mesh : model.meshes) { - size_t pos = mesh.texture.find(':'); - if (pos == std::string::npos) { - continue; - } - if (auto region = atlas.getIf(mesh.texture.substr(pos+1))) { - for (auto& vertex : mesh.vertices) { - vertex.uv = region->apply(vertex.uv); - } + if (atlas.has(tex)) { + sideregions[def.rt.id * 6 + side] = atlas.get(tex); + } else if (atlas.has(TEXTURE_NOTFOUND)) { + sideregions[def.rt.id * 6 + side] = atlas.get(TEXTURE_NOTFOUND); + } + } + if (def.model == BlockModel::custom) { + auto model = assets.require(def.modelName); + // temporary dirty fix tbh + if (def.modelName.find(':') == std::string::npos) { + for (auto& mesh : model.meshes) { + size_t pos = mesh.texture.find(':'); + if (pos == std::string::npos) { + continue; + } + if (auto region = atlas.getIf(mesh.texture.substr(pos+1))) { + for (auto& vertex : mesh.vertices) { + vertex.uv = region->apply(vertex.uv); } } } - models[def->rt.id] = std::move(model); } + models[def.rt.id] = std::move(model); + } +} + +void ContentGfxCache::refresh() { + auto indices = content.getIndices(); + sideregions = std::make_unique(indices->blocks.count() * 6); + const auto& atlas = assets.require("blocks"); + + const auto& blocks = indices->blocks.getIterable(); + for (blockid_t i = 0; i < blocks.size(); i++) { + auto def = blocks[i]; + refresh(*def, atlas); } } ContentGfxCache::~ContentGfxCache() = default; const Content* ContentGfxCache::getContent() const { - return content; + return &content; } const model::Model& ContentGfxCache::getModel(blockid_t id) const { diff --git a/src/frontend/ContentGfxCache.hpp b/src/frontend/ContentGfxCache.hpp index 96d46ea59..739d6c1d4 100644 --- a/src/frontend/ContentGfxCache.hpp +++ b/src/frontend/ContentGfxCache.hpp @@ -10,19 +10,29 @@ class Content; class Assets; +class Atlas; +struct Block; struct UVRegion; +struct GraphicsSettings; namespace model { struct Model; } class ContentGfxCache { - const Content* content; + const Content& content; + const Assets& assets; + const GraphicsSettings& settings; + // array of block sides uv regions (6 per block) std::unique_ptr sideregions; std::unordered_map models; public: - ContentGfxCache(const Content* content, const Assets& assets); + ContentGfxCache( + const Content& content, + const Assets& assets, + const GraphicsSettings& settings + ); ~ContentGfxCache(); inline const UVRegion& getRegion(blockid_t id, int side) const { @@ -32,4 +42,8 @@ class ContentGfxCache { const model::Model& getModel(blockid_t id) const; const Content* getContent() const; + + void refresh(const Block& block, const Atlas& atlas); + + void refresh(); }; diff --git a/src/frontend/LevelFrontend.cpp b/src/frontend/LevelFrontend.cpp index 79784375d..d3cbb9e8d 100644 --- a/src/frontend/LevelFrontend.cpp +++ b/src/frontend/LevelFrontend.cpp @@ -14,12 +14,17 @@ #include "world/Level.hpp" LevelFrontend::LevelFrontend( - Player* currentPlayer, LevelController* controller, Assets& assets -) : level(*controller->getLevel()), - controller(controller), - assets(assets), - contentCache(std::make_unique(level.content, assets)) -{ + Player* currentPlayer, + LevelController* controller, + Assets& assets, + const EngineSettings& settings +) + : level(*controller->getLevel()), + controller(controller), + assets(assets), + contentCache(std::make_unique( + *level.content, assets, settings.graphics + )) { assets.store( BlocksPreview::build( *contentCache, assets, *level.content->getIndices() @@ -98,6 +103,10 @@ const Assets& LevelFrontend::getAssets() const { return assets; } +ContentGfxCache& LevelFrontend::getContentGfxCache() { + return *contentCache; +} + const ContentGfxCache& LevelFrontend::getContentGfxCache() const { return *contentCache; } diff --git a/src/frontend/LevelFrontend.hpp b/src/frontend/LevelFrontend.hpp index 163fc678f..b53d267a3 100644 --- a/src/frontend/LevelFrontend.hpp +++ b/src/frontend/LevelFrontend.hpp @@ -7,6 +7,7 @@ class Assets; class Player; class ContentGfxCache; class LevelController; +struct EngineSettings; class LevelFrontend { Level& level; @@ -14,12 +15,18 @@ class LevelFrontend { const Assets& assets; std::unique_ptr contentCache; public: - LevelFrontend(Player* currentPlayer, LevelController* controller, Assets& assets); + LevelFrontend( + Player* currentPlayer, + LevelController* controller, + Assets& assets, + const EngineSettings& settings + ); ~LevelFrontend(); Level& getLevel(); const Level& getLevel() const; const Assets& getAssets() const; const ContentGfxCache& getContentGfxCache() const; + ContentGfxCache& getContentGfxCache(); LevelController* getController() const; }; diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index 34d1db678..e38b3beca 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -17,6 +17,7 @@ #include "graphics/render/Decorator.hpp" #include "graphics/ui/elements/Menu.hpp" #include "graphics/ui/GUI.hpp" +#include "frontend/ContentGfxCache.hpp" #include "logic/LevelController.hpp" #include "logic/scripting/scripting_hud.hpp" #include "util/stringutil.hpp" @@ -42,7 +43,7 @@ LevelScreen::LevelScreen(Engine* engine, std::unique_ptr levelPtr) controller = std::make_unique(engine, std::move(levelPtr)); frontend = std::make_unique( - controller->getPlayer(), controller.get(), assets + controller->getPlayer(), controller.get(), assets, settings ); worldRenderer = std::make_unique( engine, *frontend, controller->getPlayer() @@ -57,6 +58,11 @@ LevelScreen::LevelScreen(Engine* engine, std::unique_ptr levelPtr) controller->getLevel()->chunks->saveAndClear(); worldRenderer->clear(); })); + keepAlive(settings.graphics.denseRender.observe([=](bool) { + controller->getLevel()->chunks->saveAndClear(); + worldRenderer->clear(); + frontend->getContentGfxCache().refresh(); + })); keepAlive(settings.camera.fov.observe([=](double value) { controller->getPlayer()->fpCamera->setFov(glm::radians(value)); })); diff --git a/src/graphics/render/BlocksRenderer.cpp b/src/graphics/render/BlocksRenderer.cpp index f1e8001f1..56f1c4e2f 100644 --- a/src/graphics/render/BlocksRenderer.cpp +++ b/src/graphics/render/BlocksRenderer.cpp @@ -8,9 +8,6 @@ #include "voxels/Chunks.hpp" #include "lighting/Lightmap.hpp" #include "frontend/ContentGfxCache.hpp" -#include "settings.hpp" - -#include const glm::vec3 BlocksRenderer::SUN_VECTOR (0.411934f, 0.863868f, -0.279161f); diff --git a/src/graphics/render/BlocksRenderer.hpp b/src/graphics/render/BlocksRenderer.hpp index d27f681bb..c652b6a08 100644 --- a/src/graphics/render/BlocksRenderer.hpp +++ b/src/graphics/render/BlocksRenderer.hpp @@ -13,6 +13,7 @@ #include "graphics/core/MeshData.hpp" #include "maths/util.hpp" #include "commons.hpp" +#include "settings.hpp" class Content; class Mesh; @@ -22,7 +23,6 @@ class Chunks; class VoxelsVolume; class Chunks; class ContentGfxCache; -struct EngineSettings; struct UVRegion; class BlocksRenderer { @@ -129,8 +129,10 @@ class BlocksRenderer { if (((block.drawGroup != def.drawGroup) && block.drawGroup) || !block.rt.solid) { return true; } - if (def.culling == CullingMode::DISABLED || - (def.culling == CullingMode::OPTIONAL && id == def.rt.id)) { + if ((def.culling == CullingMode::DISABLED || + (def.culling == CullingMode::OPTIONAL && + settings.graphics.denseRender.get())) && + id == def.rt.id) { return true; } return !id; diff --git a/src/settings.hpp b/src/settings.hpp index b0eee035e..48d72b272 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -63,16 +63,22 @@ struct GraphicsSettings { NumberSetting gamma {1.0f, 0.4f, 1.0f}; /// @brief Enable blocks backlight to prevent complete darkness FlagSetting backlight {true}; + /// @brief Disable culling with 'optional' mode + FlagSetting denseRender {true}; /// @brief Enable chunks frustum culling FlagSetting frustumCulling {true}; + /// @brief Skybox texture face resolution IntegerSetting skyboxResolution {64 + 32, 64, 128}; + /// @brief Chunk renderer vertices buffer capacity IntegerSetting chunkMaxVertices {200'000, 0, 4'000'000}; + /// @brief Limit of chunk renderers count IntegerSetting chunkMaxRenderers {6, -4, 32}; }; struct DebugSettings { /// @brief Turns off chunks saving/loading FlagSetting generatorTestMode {false}; + /// @brief Write lights cache FlagSetting doWriteLights {true}; }; From a5a72af796d6bb842538ab6b7ab47c4b8ce9e705 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Dec 2024 08:31:58 +0300 Subject: [PATCH 5/6] fix msvc build --- src/frontend/ContentGfxCache.hpp | 2 +- src/graphics/render/Decorator.hpp | 2 +- src/graphics/render/ModelsGenerator.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/frontend/ContentGfxCache.hpp b/src/frontend/ContentGfxCache.hpp index 739d6c1d4..cb5e2ad74 100644 --- a/src/frontend/ContentGfxCache.hpp +++ b/src/frontend/ContentGfxCache.hpp @@ -11,7 +11,7 @@ class Content; class Assets; class Atlas; -struct Block; +class Block; struct UVRegion; struct GraphicsSettings; diff --git a/src/graphics/render/Decorator.hpp b/src/graphics/render/Decorator.hpp index fbc196aa9..422f6f777 100644 --- a/src/graphics/render/Decorator.hpp +++ b/src/graphics/render/Decorator.hpp @@ -14,7 +14,7 @@ class Chunks; class Camera; class Assets; class Player; -struct Block; +class Block; class Engine; class LevelController; class WorldRenderer; diff --git a/src/graphics/render/ModelsGenerator.hpp b/src/graphics/render/ModelsGenerator.hpp index 52bc56d05..c4665118c 100644 --- a/src/graphics/render/ModelsGenerator.hpp +++ b/src/graphics/render/ModelsGenerator.hpp @@ -7,7 +7,7 @@ struct ItemDef; class Assets; class Content; -struct Block; +class Block; class ModelsGenerator { public: From 6f6421df53caf4a5a87329806f8af22fbf1f7022 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Dec 2024 08:45:30 +0300 Subject: [PATCH 6/6] update doc/*/block-properties.md --- doc/en/block-properties.md | 7 +++++++ doc/ru/block-properties.md | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/en/block-properties.md b/doc/en/block-properties.md index fb874e0ca..6400c910f 100644 --- a/doc/en/block-properties.md +++ b/doc/en/block-properties.md @@ -81,6 +81,13 @@ Turns off block model shading Determines the presence of the vertex AO effect. Turned-on by default. +### *culling* + +Face culling mode: +- **default** - normal face culling +- **optional** - face culling among blocks of the same rendering group can be disabled via the `graphics.dense-render` setting. +- **disabled** - face culling among blocks of the same rendering group disabled. + ## Physics ### *obstacle* diff --git a/doc/ru/block-properties.md b/doc/ru/block-properties.md index 1862e659c..366cf0fb3 100644 --- a/doc/ru/block-properties.md +++ b/doc/ru/block-properties.md @@ -82,7 +82,6 @@ При значении `true` блок не препятствует прохождению вертикального луча солнечного света. - ### Без освещения - *shadeless* Выключает освещение на модели блока. @@ -91,6 +90,13 @@ Определяет наличие эффекта вершинного AO. Включен по-умолчанию. +### Отсечение - *culling* + +Режим отсечения граней: +- **default** - обычное отсечение граней +- **optional** - отсечение граней среди блоков одной группы отрисовки можно отключить через настройку `graphics.dense-render` (Плотный рендер блоков). +- **disabled** - отсечение граней среди блоков одной группы отрисовки отключено. + ## Физика ### Препятствие - *obstacle*