main content pipeline uses accumulator
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-21 16:38:03 -04:00
parent cac1893d6e
commit b47503b996
3 changed files with 133 additions and 30 deletions

View File

@ -717,6 +717,14 @@ public class RenderingEngine {
return this.shadowMapPipeline; return this.shadowMapPipeline;
} }
/**
* Gets the main content pipeline
* @return The main content pipeline
*/
public MainContentPipeline getMainContentPipeline(){
return this.mainContentPipeline;
}
/** /**
* Gets the post processing pipeline * Gets the post processing pipeline
* @return The post processing pipeline * @return The post processing pipeline

View File

@ -1,6 +1,7 @@
package electrosphere.renderer.pipelines; package electrosphere.renderer.pipelines;
import java.util.Set; import java.util.LinkedList;
import java.util.List;
import org.joml.Matrix4d; import org.joml.Matrix4d;
import org.joml.Quaterniond; import org.joml.Quaterniond;
@ -21,6 +22,9 @@ import electrosphere.renderer.RenderPipelineState.SelectedShaderEnum;
import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.actor.instance.InstancedActor; import electrosphere.renderer.actor.instance.InstancedActor;
import electrosphere.renderer.buffer.ShaderAttribute; import electrosphere.renderer.buffer.ShaderAttribute;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.target.DrawTargetAccumulator;
import electrosphere.renderer.target.DrawTargetAccumulator.ModelAccumulatorData;
/** /**
* The main render pipeline with OIT pass * The main render pipeline with OIT pass
@ -30,6 +34,16 @@ public class MainContentPipeline implements RenderPipeline {
//First person drawing routine //First person drawing routine
FirstPersonItemsPipeline firstPersonSubPipeline; FirstPersonItemsPipeline firstPersonSubPipeline;
/**
* The draw target accumulator
*/
private DrawTargetAccumulator drawTargetAccumulator = new DrawTargetAccumulator();
/**
* The queue for non-static entities to draw
*/
private List<Entity> standardDrawCall = new LinkedList<Entity>();
@Override @Override
public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) { public void render(OpenGLState openGLState, RenderPipelineState renderPipelineState) {
Globals.profiler.beginCpuSample("MainContentPipeline.render"); Globals.profiler.beginCpuSample("MainContentPipeline.render");
@ -72,27 +86,45 @@ public class MainContentPipeline implements RenderPipeline {
// D R A W A L L E N T I T I E S // D R A W A L L E N T I T I E S
// //
Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids non-instanced"); Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids non-instanced");
Set<Entity> solidsNonInstanced = Globals.clientState.clientScene.getEntitiesWithTag(EntityTags.DRAWABLE);
Vector3d positionVec = new Vector3d(); Vector3d positionVec = new Vector3d();
Vector3d scaleVec = new Vector3d(); Vector3d scaleVec = new Vector3d();
Vector3d cameraCenterVec = CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera); Vector3d cameraCenterVec = CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera);
for(Entity currentEntity : solidsNonInstanced){ for(Entity currentEntity : this.standardDrawCall){
Vector3d position = EntityUtils.getPosition(currentEntity); Vector3d position = EntityUtils.getPosition(currentEntity);
if(MainContentPipeline.shouldDrawSolidPass(currentEntity)){ if(
currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)!=null
){
//fetch actor //fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity); Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate camera-modified vector3d //calculate camera-modified vector3d
Vector3d cameraModifiedPosition = positionVec.set(position).sub(cameraCenterVec); Vector3d cameraCenter = scaleVec.set(cameraCenterVec);
Vector3d cameraModifiedPosition = positionVec.set(position).sub(cameraCenter);
//calculate and apply model transform //calculate and apply model transform
modelTransformMatrix.identity(); modelTransformMatrix = modelTransformMatrix.identity();
modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(positionVec.set(EntityUtils.getScale(currentEntity))); modelTransformMatrix.scale(scaleVec.set(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position); currentActor.applySpatialData(new Matrix4d(modelTransformMatrix),new Vector3d(position));
//draw //draw
currentActor.draw(renderPipelineState,openGLState); currentActor.draw(renderPipelineState,openGLState);
} }
} }
for(ModelAccumulatorData accumulator : this.drawTargetAccumulator.getCalls()){
Model model = Globals.assetManager.fetchModel(accumulator.getModelPath());
if(model != null){
int count = accumulator.getCount();
List<Matrix4d> transforms = accumulator.getTransforms();
List<Vector3d> positions = accumulator.getPositions();
model.setMeshMask(null);
for(int i = 0; i < count; i++){
Vector3d position = positions.get(i);
Matrix4d transform = transforms.get(i);
model.setWorldPos(position);
model.setModelMatrix(transform);
model.draw(renderPipelineState, openGLState);
}
}
}
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids Foliage"); Globals.profiler.beginCpuSample("MainContentPipeline.render - Solids Foliage");
Globals.renderingEngine.getFoliagePipeline().render(openGLState, renderPipelineState); Globals.renderingEngine.getFoliagePipeline().render(openGLState, renderPipelineState);
@ -235,11 +267,11 @@ public class MainContentPipeline implements RenderPipeline {
* @param entity The entity * @param entity The entity
* @return true if should draw, false otherwise * @return true if should draw, false otherwise
*/ */
static boolean shouldDrawSolidPass(Entity entity){ public static boolean shouldDrawSolidPass(Entity entity){
return return
( (
(boolean)entity.getData(EntityDataStrings.DATA_STRING_DRAW) && (boolean)entity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
entity.getData(EntityDataStrings.DRAW_SOLID_PASS) != null entity.containsKey(EntityDataStrings.DRAW_SOLID_PASS)
) && ) &&
( (
!MainContentPipeline.entityBlacklist(entity) !MainContentPipeline.entityBlacklist(entity)
@ -302,5 +334,21 @@ public class MainContentPipeline implements RenderPipeline {
public void setFirstPersonPipeline(FirstPersonItemsPipeline firstPersonItemsPipeline){ public void setFirstPersonPipeline(FirstPersonItemsPipeline firstPersonItemsPipeline){
this.firstPersonSubPipeline = firstPersonItemsPipeline; this.firstPersonSubPipeline = firstPersonItemsPipeline;
} }
/**
* Gets the draw target accumulator
* @return The draw target accumulator
*/
public DrawTargetAccumulator getDrawTargetAccumulator(){
return drawTargetAccumulator;
}
/**
* Gets the queue of standard entities to draw
* @return The queue of standard entites
*/
public List<Entity> getStandardEntityQueue(){
return standardDrawCall;
}
} }

View File

@ -1,6 +1,7 @@
package electrosphere.renderer.target; package electrosphere.renderer.target;
import java.util.List; import java.util.List;
import java.util.Set;
import org.joml.Matrix4d; import org.joml.Matrix4d;
import org.joml.Vector3d; import org.joml.Vector3d;
@ -8,10 +9,10 @@ import org.joml.Vector3d;
import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.entity.camera.CameraEntityUtils;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags; import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.pipelines.MainContentPipeline;
/** /**
* Evaluates the draw targets * Evaluates the draw targets
@ -22,43 +23,89 @@ public class DrawTargetEvaluator {
* Evaluates the draw targets * Evaluates the draw targets
*/ */
public static void evaluate(){ public static void evaluate(){
//main content pipeline structures
DrawTargetAccumulator mainAccumulator = Globals.renderingEngine.getMainContentPipeline().getDrawTargetAccumulator();
List<Entity> mainQueue = Globals.renderingEngine.getMainContentPipeline().getStandardEntityQueue();
mainAccumulator.clearCalls();
mainQueue.clear();
//shadow map pipeline structures
DrawTargetAccumulator shadowAccumulator = Globals.renderingEngine.getShadowMapPipeline().getDrawTargetAccumulator(); DrawTargetAccumulator shadowAccumulator = Globals.renderingEngine.getShadowMapPipeline().getDrawTargetAccumulator();
List<Entity> shadowQueue = Globals.renderingEngine.getShadowMapPipeline().getStandardEntityQueue(); List<Entity> shadowQueue = Globals.renderingEngine.getShadowMapPipeline().getStandardEntityQueue();
shadowAccumulator.clearCalls(); shadowAccumulator.clearCalls();
shadowQueue.clear(); shadowQueue.clear();
//reused objects //reused objects
Vector3d scaleVec = new Vector3d();
Vector3d posVec = new Vector3d(); Vector3d posVec = new Vector3d();
Matrix4d modelTransformMatrix = new Matrix4d(); Matrix4d modelTransformMatrix = new Matrix4d();
//calculate camera-modified vector3d //calculate camera-modified vector3d
Vector3d cameraCenter = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera)); Vector3d cameraCenter = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera));
//iterate over all shadow cast entities Vector3d positionVec = new Vector3d();
for(Entity currentEntity : Globals.clientState.clientScene.getEntitiesWithTag(EntityTags.DRAW_CAST_SHADOW)){
if(currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)!=null){ //different entity lists
Vector3d position = EntityUtils.getPosition(currentEntity); Set<Entity> drawables = Globals.clientState.clientScene.getEntitiesWithTag(EntityTags.DRAWABLE);
//fetch actor Set<Entity> shadowList = Globals.clientState.clientScene.getEntitiesWithTag(EntityTags.DRAW_CAST_SHADOW);
Actor currentActor = EntityUtils.getActor(currentEntity);
if(currentActor.isStaticDrawCall()){ for(Entity currentEntity : drawables){
Vector3d cameraModifiedPosition = posVec.set(position).sub(cameraCenter); Vector3d position = EntityUtils.getPosition(currentEntity);
//calculate and apply model transform //fetch actor
modelTransformMatrix = modelTransformMatrix.identity(); Actor currentActor = EntityUtils.getActor(currentEntity);
modelTransformMatrix.translate(cameraModifiedPosition); if(currentActor.isStaticDrawCall()){
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); //calculate camera-modified vector3d
modelTransformMatrix.scale(scaleVec.set(EntityUtils.getScale(currentEntity))); Vector3d cameraModifiedPosition = positionVec.set(position).sub(cameraCenter);
posVec.set(0,0,0); //calculate and apply model transform
if(currentActor.frustumTest(Globals.renderingEngine.getRenderPipelineState(), modelTransformMatrix.getTranslation(posVec))){ modelTransformMatrix.identity();
//queue for batching modelTransformMatrix.translate(cameraModifiedPosition);
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(positionVec.set(EntityUtils.getScale(currentEntity)));
currentActor.applySpatialData(modelTransformMatrix,position);
//draw
if(currentActor.frustumTest(Globals.renderingEngine.getRenderPipelineState(), modelTransformMatrix.getTranslation(posVec))){
//queue for batching
if(MainContentPipeline.shouldDrawSolidPass(currentEntity)){
mainAccumulator.addCall(currentActor.getModelPath(), position, modelTransformMatrix);
}
if(shadowList.contains(currentEntity)){
shadowAccumulator.addCall(currentActor.getModelPath(), position, modelTransformMatrix); shadowAccumulator.addCall(currentActor.getModelPath(), position, modelTransformMatrix);
} }
} else { }
//queue for not-batching } else {
if(MainContentPipeline.shouldDrawSolidPass(currentEntity)){
mainQueue.add(currentEntity);
}
if(shadowList.contains(currentEntity)){
shadowQueue.add(currentEntity); shadowQueue.add(currentEntity);
} }
} }
} }
// //iterate over all shadow cast entities
// for(Entity currentEntity : Globals.clientState.clientScene.getEntitiesWithTag(EntityTags.DRAW_CAST_SHADOW)){
// if(currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW)!=null){
// Vector3d position = EntityUtils.getPosition(currentEntity);
// //fetch actor
// Actor currentActor = EntityUtils.getActor(currentEntity);
// if(currentActor.isStaticDrawCall()){
// Vector3d cameraModifiedPosition = posVec.set(position).sub(cameraCenter);
// //calculate and apply model transform
// modelTransformMatrix = modelTransformMatrix.identity();
// modelTransformMatrix.translate(cameraModifiedPosition);
// modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
// modelTransformMatrix.scale(scaleVec.set(EntityUtils.getScale(currentEntity)));
// posVec.set(0,0,0);
// if(currentActor.frustumTest(Globals.renderingEngine.getRenderPipelineState(), modelTransformMatrix.getTranslation(posVec))){
// //queue for batching
// shadowAccumulator.addCall(currentActor.getModelPath(), position, modelTransformMatrix);
// }
// } else {
// //queue for not-batching
// shadowQueue.add(currentEntity);
// }
// }
// }
} }
} }