optimizations
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
austin 2025-03-28 20:36:26 -04:00
parent da021f889f
commit 50a816adc0
6 changed files with 134 additions and 137 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Fri Mar 28 12:07:10 EDT 2025
buildNumber=611
#Fri Mar 28 19:50:10 EDT 2025
buildNumber=612

View File

@ -1363,6 +1363,8 @@ Lower duplicate physics frame count
Various code cleanup
Stop sleeping during high frame time
Actor bone spatial data caching for performance
Volumetric pipeline optimization
Collidable tree simplification

View File

@ -75,7 +75,7 @@ public class CollisionEngine {
* IE, if this value is 3, every main game engine frame, the physics simulation will run 3 frames.
* This keeps the physics simulation much more stable than it would be otherwise.
*/
public static final int PHYSICS_SIMULATION_RESOLUTION = 2;
public static final int PHYSICS_SIMULATION_RESOLUTION = 3;
/**
* Threshold after which the engine warns about collidable count

View File

@ -1,18 +1,12 @@
package electrosphere.entity.state.collidable;
import electrosphere.collision.PhysicsUtils;
import electrosphere.collision.collidable.Collidable;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.gravity.ServerGravityTree;
import electrosphere.entity.state.movement.fall.ServerFallTree;
import electrosphere.server.datacell.Realm;
import org.joml.Quaterniond;
import org.joml.Vector3d;
import org.ode4j.ode.DBody;
/**
@ -42,9 +36,6 @@ public class ServerCollidableTree implements BehaviorTree {
static int incrementer = 0;
public void simulate(float deltaTime){
Vector3d position = EntityUtils.getPosition(parent);
Quaterniond rotation = EntityUtils.getRotation(parent);
Vector3d newPosition = new Vector3d(position);
//have we hit a terrain impulse?
//handle impulses
for(Impulse impulse : collidable.getImpulses()){
@ -57,18 +48,6 @@ public class ServerCollidableTree implements BehaviorTree {
this.resetGravityFall();
}
}
Realm realm = Globals.realmManager.getEntityRealm(parent);
//bound to world bounds
if(newPosition.x < realm.getServerWorldData().getWorldBoundMin().x){
newPosition.x = realm.getServerWorldData().getWorldBoundMin().x;
}
if(newPosition.y < realm.getServerWorldData().getWorldBoundMin().y){
newPosition.y = realm.getServerWorldData().getWorldBoundMin().y;
}
if(newPosition.z < realm.getServerWorldData().getWorldBoundMin().z){
newPosition.z = realm.getServerWorldData().getWorldBoundMin().z;
}
PhysicsUtils.setRigidBodyTransform(realm.getCollisionEngine(), newPosition, rotation, body);
}

View File

@ -69,6 +69,7 @@ public class MainContentPipeline implements RenderPipeline {
//
// D R A W A L L E N T I T I E S
//
Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids non-instanced");
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(shouldDrawSolidPass(currentEntity)){
@ -86,7 +87,11 @@ public class MainContentPipeline implements RenderPipeline {
currentActor.draw(renderPipelineState,openGLState);
}
}
Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids Foliage");
Globals.renderingEngine.getFoliagePipeline().render(openGLState, renderPipelineState);
Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids instanced");
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_INSTANCED)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(shouldDrawSolidPass(currentEntity)){
@ -115,6 +120,7 @@ public class MainContentPipeline implements RenderPipeline {
}
//draw all instanced models
Globals.clientInstanceManager.draw(renderPipelineState, openGLState);
Globals.profiler.endCpuSample();
this.firstPersonSubPipeline.render(openGLState, renderPipelineState);
//
@ -149,7 +155,7 @@ public class MainContentPipeline implements RenderPipeline {
//TLDR OF ABOVE: DO NOT DRAW TRANSPARENT OBJECTS IN OPAQUE PASS
//
Globals.profiler.beginCpuSample("MainContentPipeline.render - Transparents non-instanced");
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(shouldDrawTransparentPass(currentEntity)){
@ -167,6 +173,8 @@ public class MainContentPipeline implements RenderPipeline {
currentActor.draw(renderPipelineState,openGLState);
}
}
Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("MainContentPipeline.render - Transparents instanced");
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_INSTANCED)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(shouldDrawTransparentPass(currentEntity)){
@ -195,6 +203,7 @@ public class MainContentPipeline implements RenderPipeline {
}
//draw all instanced models
Globals.clientInstanceManager.draw(renderPipelineState,openGLState);
Globals.profiler.endCpuSample();
//

View File

@ -1,5 +1,7 @@
package electrosphere.renderer.pipelines;
import java.util.Set;
import org.joml.Matrix4d;
import org.joml.Vector3d;
import org.lwjgl.opengl.GL40;
@ -23,133 +25,138 @@ public class VolumeBufferPipeline implements RenderPipeline {
@Override
public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) {
Globals.profiler.beginCpuSample("VolumeBufferPipeline.render");
Matrix4d modelTransformMatrix = new Matrix4d();
//set the viewport to shadow map size
openGLState.glViewport(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
openGLState.glDepthTest(true);
openGLState.glDepthFunc(GL40.GL_LESS);
GL40.glDepthMask(true);
//stop rendering front faces
GL40.glEnable(GL40.GL_CULL_FACE);
GL40.glCullFace(GL40.GL_FRONT);
//setup rendering for back faces
openGLState.setActiveShader(renderPipelineState, RenderingEngine.volumeDepthShaderProgram);
RenderingEngine.volumeDepthBackfaceFramebuffer.bind(openGLState);
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
Set<Entity> depthEntities = Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_DEPTH_PASS);
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "view"), false, Globals.viewMatrix.get(new float[16]));
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "projection"), false, RenderingEngine.nearVolumeProjectionMatrix.get(new float[16]));
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "linearCoef"), RenderingEngine.volumeDepthLinearCoef);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "quadCoef"), RenderingEngine.volumeDepthQuadCoef);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "near"), 0.1f);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "far"), 100f);
//
// Set render pipeline state
//
renderPipelineState.setUseMeshShader(false);
renderPipelineState.setBufferStandardUniforms(false);
renderPipelineState.setBufferNonStandardUniforms(true);
renderPipelineState.setUseMaterial(false);
renderPipelineState.setUseShadowMap(false);
renderPipelineState.setUseBones(true);
renderPipelineState.setUseLight(false);
if(depthEntities != null && depthEntities.size() > 0){
Matrix4d modelTransformMatrix = new Matrix4d();
//set the viewport to shadow map size
openGLState.glViewport(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
openGLState.glDepthTest(true);
openGLState.glDepthFunc(GL40.GL_LESS);
GL40.glDepthMask(true);
//stop rendering front faces
GL40.glEnable(GL40.GL_CULL_FACE);
GL40.glCullFace(GL40.GL_FRONT);
//setup rendering for back faces
openGLState.setActiveShader(renderPipelineState, RenderingEngine.volumeDepthShaderProgram);
RenderingEngine.volumeDepthBackfaceFramebuffer.bind(openGLState);
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "view"), false, Globals.viewMatrix.get(new float[16]));
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "projection"), false, RenderingEngine.nearVolumeProjectionMatrix.get(new float[16]));
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "linearCoef"), RenderingEngine.volumeDepthLinearCoef);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "quadCoef"), RenderingEngine.volumeDepthQuadCoef);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "near"), 0.1f);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "far"), 100f);
//
// Set render pipeline state
//
renderPipelineState.setUseMeshShader(false);
renderPipelineState.setBufferStandardUniforms(false);
renderPipelineState.setBufferNonStandardUniforms(true);
renderPipelineState.setUseMaterial(false);
renderPipelineState.setUseShadowMap(false);
renderPipelineState.setUseBones(true);
renderPipelineState.setUseLight(false);
//
// D R A W A L L E N T I T I E S
//
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_DEPTH_PASS)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)!=null
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d
Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
currentActor.draw(renderPipelineState,openGLState);
//
// D R A W A L L E N T I T I E S
//
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_DEPTH_PASS)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)!=null
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d
Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
currentActor.draw(renderPipelineState,openGLState);
}
}
}
//
//Draw front faces of all non-volumetrics
//
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_SOLIDS_PASS)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d
Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//set projection matrix
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
currentActor.draw(renderPipelineState,openGLState);
//
//Draw front faces of all non-volumetrics
//
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_SOLIDS_PASS)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d
Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//set projection matrix
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
currentActor.draw(renderPipelineState,openGLState);
}
}
}
//stop rendering front faces
GL40.glEnable(GL40.GL_CULL_FACE);
GL40.glCullFace(GL40.GL_BACK);
//stop rendering front faces
GL40.glEnable(GL40.GL_CULL_FACE);
GL40.glCullFace(GL40.GL_BACK);
//setup state for depth testing front faces
openGLState.setActiveShader(renderPipelineState, RenderingEngine.volumeDepthShaderProgram);
RenderingEngine.volumeDepthFrontfaceFramebuffer.bind(openGLState);
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
//setup state for depth testing front faces
openGLState.setActiveShader(renderPipelineState, RenderingEngine.volumeDepthShaderProgram);
RenderingEngine.volumeDepthFrontfaceFramebuffer.bind(openGLState);
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
//
// D R A W A L L E N T I T I E S
//
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_DEPTH_PASS)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d
Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
//draw
currentActor.draw(renderPipelineState,openGLState);
//
// D R A W A L L E N T I T I E S
//
for(Entity currentEntity : Globals.clientScene.getEntitiesWithTag(EntityTags.DRAW_VOLUMETIC_DEPTH_PASS)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d
Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(new Vector3d(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
//draw
currentActor.draw(renderPipelineState,openGLState);
}
}
}
GL40.glCullFace(GL40.GL_BACK);
//now cull back faces
//reset texture
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, 0);
//bind default framebuffer
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER,0);
//resume culling backface
GL40.glDisable(GL40.GL_CULL_FACE);
GL40.glCullFace(GL40.GL_BACK);
//now cull back faces
//reset texture
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, 0);
//bind default framebuffer
openGLState.glBindFramebuffer(GL40.GL_FRAMEBUFFER,0);
//resume culling backface
GL40.glDisable(GL40.GL_CULL_FACE);
}
Globals.profiler.endCpuSample();
}