Merge branch 'main' into volume-renderer

This commit is contained in:
MihailRis 2026-01-10 23:28:28 +03:00
commit 305f44d1c6
70 changed files with 802 additions and 580 deletions

View file

@ -81,7 +81,7 @@ void BlocksRenderer::face(
const glm::vec4(&lights)[4],
const glm::vec4& tint
) {
if (vertexCount + 4 >= capacity) {
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
overflow = true;
return;
}
@ -121,7 +121,7 @@ void BlocksRenderer::faceAO(
const UVRegion& region,
bool lights
) {
if (vertexCount + 4 >= capacity) {
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
overflow = true;
return;
}
@ -160,7 +160,7 @@ void BlocksRenderer::face(
glm::vec4 tint,
bool lights
) {
if (vertexCount + 4 >= capacity) {
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
overflow = true;
return;
}
@ -275,19 +275,6 @@ void BlocksRenderer::blockAABB(
}
}
static bool is_aligned(const glm::vec3& v, float e = 1e-6f) {
if (std::abs(v.y) < e && std::abs(v.z) < e && std::abs(v.x) > e) {
return true;
}
if (std::abs(v.x) < e && std::abs(v.z) < e && std::abs(v.y) > e) {
return true;
}
if (std::abs(v.x) < e && std::abs(v.y) < e && std::abs(v.z) > e) {
return true;
}
return false;
}
void BlocksRenderer::blockCustomModel(
const glm::ivec3& icoord, const Block& block, blockstate states, bool lights, bool ao
) {
@ -304,14 +291,34 @@ void BlocksRenderer::blockCustomModel(
Z = orient.axes[2];
}
if (!block.rt.extended) {
glm::ivec3 offsets[6] {
{-1, 0, 0}, {0, -1, 0}, {0, 0, -1},
{1, 0, 0}, {0, 1, 0}, {0, 0, 1},
};
bool culled = true;
for (int i = 0; i < 6; i++) {
if (isOpen(icoord + offsets[i], block, variant)) {
culled = false;
break;
}
}
if (culled) {
return;
}
}
const auto& model = cache.getModel(block.rt.id, block.getVariantIndex(states.userbits));
for (const auto& mesh : model.meshes) {
if (vertexCount + mesh.vertices.size() >= capacity) {
if (vertexCount + mesh.vertices.size() >= capacity
|| indexCount + mesh.vertices.size() >= capacity) {
overflow = true;
return;
}
bool shading = mesh.shading && !block.shadeless;
for (int triangle = 0; triangle < mesh.vertices.size() / 3; triangle++) {
int trianglesCount = mesh.vertices.size() / 3;
for (int triangle = 0; triangle < trianglesCount; triangle++) {
auto r = mesh.vertices[triangle * 3 + (triangle % 2) * 2].coord -
mesh.vertices[triangle * 3 + 1].coord;
r = r.x * X + r.y * Y + r.z * Z;
@ -328,8 +335,7 @@ void BlocksRenderer::blockCustomModel(
vp = vp.x * X + vp.y * Y + vp.z * Z;
if (!block.rt.extended
&& !isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), block, variant)
&& is_aligned(n)) {
&& !isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), block, variant)) {
continue;
}
@ -769,6 +775,10 @@ ChunkMesh BlocksRenderer::render(
const Chunk* chunk, const VoxelsRenderVolume& volume
) {
build(chunk, volume);
assert(vertexCount <= capacity);
assert(indexCount <= capacity);
assert(denseIndexCount <= capacity);
return ChunkMesh{std::make_unique<Mesh<ChunkVertex>>(
vertexBuffer.get(), vertexCount,