Show internal leaves faces.

Fixes #217 at a heavy performance cost.
This commit is contained in:
IntegratedQuantum 2024-05-17 20:50:04 +02:00
parent 2d73ebdc0a
commit bb25c0181e
4 changed files with 11 additions and 4 deletions

View File

@ -6,7 +6,7 @@
"0.1 cubyz:apple" "0.1 cubyz:apple"
], ],
"degradable" : true, "degradable" : true,
"viewThrough" : true, "alwaysViewThrough" : true,
"absorbedLight" : 0x121012, "absorbedLight" : 0x121012,
"model" : "cube", "model" : "cube",
"texture" : "cubyz:oak_leaves_transparent" "texture" : "cubyz:oak_leaves_transparent"

View File

@ -6,7 +6,7 @@
"0.1 cubyz:apple" "0.1 cubyz:apple"
], ],
"degradable" : true, "degradable" : true,
"viewThrough" : true, "alwaysViewThrough" : true,
"absorbedLight" : 0x121012, "absorbedLight" : 0x121012,
"model" : "cube", "model" : "cube",
"texture" : "cubyz:pine_needles" "texture" : "cubyz:pine_needles"

View File

@ -70,6 +70,7 @@ var _blockDrops: [maxBlockCount][]BlockDrop = undefined;
/// Meaning undegradable parts of trees or other structures can grow through this block. /// Meaning undegradable parts of trees or other structures can grow through this block.
var _degradable: [maxBlockCount]bool = undefined; var _degradable: [maxBlockCount]bool = undefined;
var _viewThrough: [maxBlockCount]bool = undefined; var _viewThrough: [maxBlockCount]bool = undefined;
var _alwaysViewThrough: [maxBlockCount]bool = undefined;
var _hasBackFace: [maxBlockCount]bool = undefined; var _hasBackFace: [maxBlockCount]bool = undefined;
var _blockClass: [maxBlockCount]BlockClass = undefined; var _blockClass: [maxBlockCount]BlockClass = undefined;
var _light: [maxBlockCount]u32 = undefined; var _light: [maxBlockCount]u32 = undefined;
@ -114,7 +115,8 @@ pub fn register(_: []const u8, id: []const u8, json: JsonElement) u16 {
_solid[size] = json.get(bool, "solid", true); _solid[size] = json.get(bool, "solid", true);
_gui[size] = allocator.dupe(u8, json.get([]const u8, "GUI", "")); _gui[size] = allocator.dupe(u8, json.get([]const u8, "GUI", ""));
_transparent[size] = json.get(bool, "transparent", false); _transparent[size] = json.get(bool, "transparent", false);
_viewThrough[size] = json.get(bool, "viewThrough", false) or _transparent[size]; _alwaysViewThrough[size] = json.get(bool, "alwaysViewThrough", false);
_viewThrough[size] = json.get(bool, "viewThrough", false) or _transparent[size] or _alwaysViewThrough[size];
_hasBackFace[size] = json.get(bool, "hasBackFace", false); _hasBackFace[size] = json.get(bool, "hasBackFace", false);
const oreProperties = json.getChild("ore"); const oreProperties = json.getChild("ore");
@ -256,6 +258,11 @@ pub const Block = packed struct {
return _viewThrough[self.typ]; return _viewThrough[self.typ];
} }
/// shows backfaces even when next to the same block type
pub inline fn alwaysViewThrough(self: Block) bool {
return _alwaysViewThrough[self.typ];
}
pub inline fn hasBackFace(self: Block) bool { pub inline fn hasBackFace(self: Block) bool {
return _hasBackFace[self.typ]; return _hasBackFace[self.typ];
} }

View File

@ -606,7 +606,7 @@ pub const ChunkMesh = struct {
_ = model; // TODO: Check if the neighbor model occludes this one. (maybe not that relevant) _ = model; // TODO: Check if the neighbor model occludes this one. (maybe not that relevant)
return block.typ != 0 and ( return block.typ != 0 and (
other.typ == 0 other.typ == 0
or (!std.meta.eql(block, other) and other.viewThrough()) or (!std.meta.eql(block, other) and other.viewThrough()) or other.alwaysViewThrough()
or !models.models.items[blocks.meshes.model(other)].isNeighborOccluded[neighbor ^ 1] or !models.models.items[blocks.meshes.model(other)].isNeighborOccluded[neighbor ^ 1]
); );
} }