add 'culling' property & optimize generated chunk meshes & fix faces culling when 'light-passing' is false
This commit is contained in:
parent
d021b443dd
commit
954724c837
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"texture": "leaves",
|
"texture": "leaves",
|
||||||
"material": "base:grass",
|
"material": "base:grass",
|
||||||
"base:durability": 0.7,
|
"draw-group": 5,
|
||||||
"culling": "optional",
|
"culling": "optional",
|
||||||
"model": "aabb"
|
"base:durability": 0.7
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
@ -239,10 +239,18 @@ void ContentLoader::loadBlock(
|
|||||||
}
|
}
|
||||||
def.model = *model;
|
def.model = *model;
|
||||||
} else if (!modelTypeName.empty()) {
|
} else if (!modelTypeName.empty()) {
|
||||||
logger.error() << "unknown model " << modelTypeName;
|
logger.error() << "unknown model: " << modelTypeName;
|
||||||
def.model = BlockModel::none;
|
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);
|
root.at("material").get(def.material);
|
||||||
|
|
||||||
// rotation profile
|
// rotation profile
|
||||||
|
|||||||
@ -342,41 +342,41 @@ void BlocksRenderer::blockCube(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ao) {
|
if (ao) {
|
||||||
if (isOpen(coord + Z, group)) {
|
if (isOpen(coord + Z, block)) {
|
||||||
faceAO(coord, X, Y, Z, texfaces[5], lights);
|
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);
|
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);
|
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);
|
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);
|
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);
|
faceAO(coord, Z, Y, -X, texfaces[0], lights);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isOpen(coord + Z, group)) {
|
if (isOpen(coord + Z, block)) {
|
||||||
face(coord, X, Y, Z, texfaces[5], pickLight(coord + Z), lights);
|
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);
|
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);
|
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);
|
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);
|
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);
|
face(coord, Z, Y, -X, texfaces[0], pickLight(coord - X), lights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,7 +118,7 @@ class BlocksRenderer {
|
|||||||
bool isOpenForLight(int x, int y, int z) const;
|
bool isOpenForLight(int x, int y, int z) const;
|
||||||
|
|
||||||
// Does block allow to see other blocks sides (is it transparent)
|
// 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(
|
auto id = voxelsBuffer->pickBlockId(
|
||||||
chunk->x * CHUNK_W + pos.x, pos.y, chunk->z * CHUNK_D + pos.z
|
chunk->x * CHUNK_W + pos.x, pos.y, chunk->z * CHUNK_D + pos.z
|
||||||
);
|
);
|
||||||
@ -126,7 +126,11 @@ class BlocksRenderer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto& block = *blockDefsCache[id];
|
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 true;
|
||||||
}
|
}
|
||||||
return !id;
|
return !id;
|
||||||
|
|||||||
@ -49,6 +49,30 @@ std::optional<BlockModel> BlockModel_from(std::string_view str) {
|
|||||||
return std::nullopt;
|
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> 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)
|
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ)
|
||||||
: axisX(axisX), axisY(axisY), axisZ(axisZ) {
|
: axisX(axisX), axisY(axisY), axisZ(axisZ) {
|
||||||
fix = glm::ivec3(0);
|
fix = glm::ivec3(0);
|
||||||
|
|||||||
@ -97,6 +97,15 @@ enum class BlockModel {
|
|||||||
std::string to_string(BlockModel model);
|
std::string to_string(BlockModel model);
|
||||||
std::optional<BlockModel> BlockModel_from(std::string_view str);
|
std::optional<BlockModel> BlockModel_from(std::string_view str);
|
||||||
|
|
||||||
|
enum class CullingMode {
|
||||||
|
DEFAULT,
|
||||||
|
OPTIONAL,
|
||||||
|
DISABLED,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string to_string(CullingMode mode);
|
||||||
|
std::optional<CullingMode> CullingMode_from(std::string_view str);
|
||||||
|
|
||||||
using BoxModel = AABB;
|
using BoxModel = AABB;
|
||||||
|
|
||||||
/// @brief Common kit of block properties applied to groups of blocks
|
/// @brief Common kit of block properties applied to groups of blocks
|
||||||
@ -142,6 +151,9 @@ public:
|
|||||||
|
|
||||||
std::string modelName = "";
|
std::string modelName = "";
|
||||||
|
|
||||||
|
/// @brief Culling mode
|
||||||
|
CullingMode culling = CullingMode::DEFAULT;
|
||||||
|
|
||||||
/// @brief Does the block passing lights into itself
|
/// @brief Does the block passing lights into itself
|
||||||
bool lightPassing = false;
|
bool lightPassing = false;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user