Now you see me

- Fix entities sometimes freezing when they first appear.
- Fix bounding sphere calculation for multiple combined meshes.
- Fix shadow bounding sphere transformer outputting incorrect radius.
This commit is contained in:
Jozufozu 2024-01-31 16:43:56 -08:00
parent 57ae19403f
commit 1fb646e9ef
4 changed files with 15 additions and 4 deletions

View file

@ -32,6 +32,9 @@ public class IndirectModel {
public void write(long ptr) { public void write(long ptr) {
MemoryUtil.memPutInt(ptr, 0); // instanceCount - to be incremented by the cull shader MemoryUtil.memPutInt(ptr, 0); // instanceCount - to be incremented by the cull shader
MemoryUtil.memPutInt(ptr + 4, baseInstance); // baseInstance 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());
} }
} }

View file

@ -114,6 +114,7 @@ public final class ModelUtil {
int baseVertex = 0; int baseVertex = 0;
for (Mesh mesh : meshes) { for (Mesh mesh : meshes) {
vertexList.ptr(block.ptr() + (long) baseVertex * PosVertexView.STRIDE); vertexList.ptr(block.ptr() + (long) baseVertex * PosVertexView.STRIDE);
vertexList.vertexCount(mesh.vertexCount());
mesh.write(vertexList); mesh.write(vertexList);
baseVertex += mesh.vertexCount(); baseVertex += mesh.vertexCount();
} }

View file

@ -45,9 +45,16 @@ public class EntityVisibilityTester {
public boolean check(FrustumIntersection frustum) { public boolean check(FrustumIntersection frustum) {
AABB aabb = entity.getBoundingBoxForCulling(); 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. // If the entity isn't visible, check the last visible AABB as well.
// This is to avoid Entities freezing when the go offscreen. // This is to avoid Entities freezing when the go offscreen.
visible = adjustAndTestAABB(frustum, lastVisibleAABB); visible = adjustAndTestAABB(frustum, lastVisibleAABB);

View file

@ -1,5 +1,5 @@
void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) { void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius) {
// We can just ignore the base center/radius. // We can just ignore the base center/radius.
center = i.pos + vec3(i.size.x * 0.5, 0., i.size.y * 0.5); 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;
} }