From 8c1607d34b1c8bb13a04df85fca71b1e965f1c1d Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 21 Mar 2024 19:01:51 -0400 Subject: [PATCH] Provide way to usurp frustum culling on actor --- docs/src/progress/renderertodo.md | 10 ++++---- .../engine/loadingthreads/ClientLoading.java | 2 ++ .../electrosphere/entity/DrawableUtils.java | 13 +++++++++++ .../entity/types/fluid/FluidChunk.java | 4 ++-- .../electrosphere/renderer/actor/Actor.java | 23 +++++++++++++++++-- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 98c6896d..83d3ba9d 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -170,16 +170,16 @@ Half pass at cellular automata fluid dynamics system - Streaming chunks over network - Basic model creation - - -# TODO - -Fix character movement +(03/21/2024) +Fix character movement (allegedly fixed -- maybe by camera stuff?) - Walking left or right while turning camera is very jittery - Can lock on moving Fix Frustum Culling for skybox + +# TODO + Fix Character creation preview not working Clean up main method/class diff --git a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java index 33fe9048..7e38a03b 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java @@ -210,6 +210,7 @@ public class ClientLoading { //starry sky true skybox Entity skybox = EntityCreationUtils.createClientSpatialEntity(); EntityCreationUtils.makeEntityDrawable(skybox, "Models/skyboxSphere.fbx"); + DrawableUtils.disableCulling(skybox); EntityUtils.getRotation(skybox).rotateX((float)(-Math.PI/2.0f)); EntityUtils.getScale(skybox).mul(2000.0f); Globals.assetManager.queueOverrideMeshShader("Models/skyboxSphere.fbx", "Sphere", "Shaders/skysphere/skysphere.vs", "Shaders/skysphere/skysphere.fs"); @@ -217,6 +218,7 @@ public class ClientLoading { //cloud ring pseudo skybox Entity cloudRing = EntityCreationUtils.createClientSpatialEntity(); EntityCreationUtils.makeEntityDrawable(cloudRing, "Models/cloudRing.fbx"); + DrawableUtils.disableCulling(cloudRing); EntityUtils.getRotation(cloudRing).rotateX((float)(-Math.PI/2.0f)); EntityUtils.getScale(cloudRing).mul(1000.0f); Globals.clientScene.registerBehaviorTree(new ApplyRotationTree(cloudRing,new Quaterniond().rotationZ(0.0001))); diff --git a/src/main/java/electrosphere/entity/DrawableUtils.java b/src/main/java/electrosphere/entity/DrawableUtils.java index df5fe41a..e0e76db8 100644 --- a/src/main/java/electrosphere/entity/DrawableUtils.java +++ b/src/main/java/electrosphere/entity/DrawableUtils.java @@ -1,5 +1,7 @@ package electrosphere.entity; +import electrosphere.renderer.actor.Actor; + /** * Utilities to manipulating drawable entities (eg making an entity transparent) */ @@ -14,4 +16,15 @@ public class DrawableUtils { entity.removeData(EntityDataStrings.DRAW_SOLID_PASS); } + /** + * Disables culling for the actor on a given entity + * @param entity The entity + */ + public static void disableCulling(Entity entity){ + Actor actor = EntityUtils.getActor(entity); + if(actor != null){ + actor.setFrustumCull(false); + } + } + } diff --git a/src/main/java/electrosphere/entity/types/fluid/FluidChunk.java b/src/main/java/electrosphere/entity/types/fluid/FluidChunk.java index 4086020f..7a6a39e4 100644 --- a/src/main/java/electrosphere/entity/types/fluid/FluidChunk.java +++ b/src/main/java/electrosphere/entity/types/fluid/FluidChunk.java @@ -1,6 +1,7 @@ package electrosphere.entity.types.fluid; import electrosphere.client.fluid.manager.ClientFluidManager; +import electrosphere.entity.DrawableUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityDataStrings; @@ -29,8 +30,7 @@ public class FluidChunk { // } rVal.putData(EntityDataStrings.FLUID_IS_FLUID, true); - rVal.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true); - rVal.removeData(EntityDataStrings.DRAW_SOLID_PASS); + DrawableUtils.makeEntityTransparent(rVal); rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath); return rVal; diff --git a/src/main/java/electrosphere/renderer/actor/Actor.java b/src/main/java/electrosphere/renderer/actor/Actor.java index 204b5e32..02cd5ba8 100644 --- a/src/main/java/electrosphere/renderer/actor/Actor.java +++ b/src/main/java/electrosphere/renderer/actor/Actor.java @@ -61,6 +61,9 @@ public class Actor { //static morph for this specific actor ActorStaticMorph staticMorph; + + //Controls whether the actor should obey frustum culling + boolean frustumCull = true; public Actor(String modelPath){ this.modelPath = modelPath; @@ -198,7 +201,7 @@ public class Actor { public void draw(RenderPipelineState renderPipelineState, OpenGLState openGLState){ Model model = Globals.assetManager.fetchModel(modelPath); boolean hasDrawn = false; - if(model != null && isWithinFrustumBox(renderPipelineState,model)){ + if(model != null && isWithinFrustumBox(renderPipelineState,model,frustumCull)){ applyAnimationMasks(model); meshMask.processMeshMaskQueue(); model.setMeshMask(meshMask); @@ -362,14 +365,30 @@ public class Actor { public ActorStaticMorph getStaticMorph(){ return this.staticMorph; } + + //set should frustum cull + public void setFrustumCull(boolean frustumCull){ + this.frustumCull = frustumCull; + } + + //get should frustum cull + public boolean getFrustumCull(){ + return frustumCull; + } + + /** * Checks if a given model is within the render pipeline state's frustum box * @param renderPipelineState The render pipeline state * @param model The model + * @param frustumCull Controls whether the frustum cull should actually be executed or not * @return true if it is within the box, false otherwise */ - static boolean isWithinFrustumBox(RenderPipelineState renderPipelineState, Model model){ + static boolean isWithinFrustumBox(RenderPipelineState renderPipelineState, Model model, boolean frustumCull){ + if(!frustumCull){ + return true; + } Sphered sphere = model.getBoundingSphere(); Vector3d modelPosition = model.getModelMatrix().getTranslation(new Vector3d()); return renderPipelineState.getFrustumIntersection().testSphere((float)(sphere.x + modelPosition.x), (float)(sphere.y + modelPosition.y), (float)(sphere.z + modelPosition.z), (float)sphere.r);