diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectModel.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectModel.java index c7c1932b0..afd722489 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectModel.java @@ -32,6 +32,9 @@ public class IndirectModel { public void write(long ptr) { MemoryUtil.memPutInt(ptr, 0); // instanceCount - to be incremented by the cull shader MemoryUtil.memPutInt(ptr + 4, baseInstance); // baseInstance - boundingSphere.getToAddress(ptr + 8); // boundingSphere + MemoryUtil.memPutFloat(ptr + 8, boundingSphere.x()); // boundingSphere + MemoryUtil.memPutFloat(ptr + 12, boundingSphere.y()); + MemoryUtil.memPutFloat(ptr + 16, boundingSphere.z()); + MemoryUtil.memPutFloat(ptr + 20, boundingSphere.w()); } } diff --git a/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java index 76b23fd00..f4029d89e 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/lib/model/ModelUtil.java @@ -114,6 +114,7 @@ public final class ModelUtil { int baseVertex = 0; for (Mesh mesh : meshes) { vertexList.ptr(block.ptr() + (long) baseVertex * PosVertexView.STRIDE); + vertexList.vertexCount(mesh.vertexCount()); mesh.write(vertexList); baseVertex += mesh.vertexCount(); } diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/EntityVisibilityTester.java b/src/main/java/com/jozufozu/flywheel/lib/visual/EntityVisibilityTester.java index 3262a6c31..a5d4ea5b5 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/EntityVisibilityTester.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/EntityVisibilityTester.java @@ -45,9 +45,16 @@ public class EntityVisibilityTester { public boolean check(FrustumIntersection frustum) { AABB aabb = entity.getBoundingBoxForCulling(); - boolean visible = adjustAndTestAABB(frustum, aabb); + // If we've never seen the entity before assume its visible. + // Fixes entities freezing when they first spawn. + // There might be a more sound solution to that, but this works. + boolean visible = lastVisibleAABB == null; - if (!visible && lastVisibleAABB != null && lastVisibleAABB != aabb) { + if (!visible) { + visible = adjustAndTestAABB(frustum, aabb); + } + + if (!visible && lastVisibleAABB != aabb) { // If the entity isn't visible, check the last visible AABB as well. // This is to avoid Entities freezing when the go offscreen. visible = adjustAndTestAABB(frustum, lastVisibleAABB); diff --git a/src/main/resources/assets/flywheel/flywheel/instance/cull/shadow.glsl b/src/main/resources/assets/flywheel/flywheel/instance/cull/shadow.glsl index ee0afb8dd..de3c2767f 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/cull/shadow.glsl +++ b/src/main/resources/assets/flywheel/flywheel/instance/cull/shadow.glsl @@ -1,5 +1,5 @@ void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) { // We can just ignore the base center/radius. center = i.pos + vec3(i.size.x * 0.5, 0., i.size.y * 0.5); - radius = max(i.size.x, i.size.y) * 0.5; + radius = length(i.size) * 0.5; }