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

This commit is contained in:
austin 2025-05-29 16:06:48 -04:00
parent 897b867641
commit a5d4e2348e
7 changed files with 60 additions and 166 deletions

View File

@ -2063,6 +2063,7 @@ Actor code cleanup
Refactor animation logic into dedicated actor class Refactor animation logic into dedicated actor class
Simplify draw call logic Simplify draw call logic
Error report on window.java Error report on window.java
Delete ActorShaderMask

View File

@ -6,8 +6,8 @@ import electrosphere.collision.CollisionEngine;
import electrosphere.collision.collidable.Collidable; import electrosphere.collision.collidable.Collidable;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.queue.QueuedAsset; import electrosphere.engine.assetmanager.queue.QueuedAsset;
import electrosphere.engine.assetmanager.queue.QueuedShader;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.actor.mask.ActorShaderMask;
import electrosphere.renderer.buffer.HomogenousInstancedArray; import electrosphere.renderer.buffer.HomogenousInstancedArray;
import electrosphere.renderer.buffer.HomogenousUniformBuffer; import electrosphere.renderer.buffer.HomogenousUniformBuffer;
import electrosphere.renderer.loading.ModelLoader; import electrosphere.renderer.loading.ModelLoader;
@ -58,7 +58,7 @@ public class AssetManager {
Map<String,VisualShader> shadersLoadedIntoMemory = new HashMap<String,VisualShader>(); Map<String,VisualShader> shadersLoadedIntoMemory = new HashMap<String,VisualShader>();
List<String> shadersInDeleteQueue = new LinkedList<String>(); List<String> shadersInDeleteQueue = new LinkedList<String>();
List<ActorShaderMask> shadersInQueue = new LinkedList<ActorShaderMask>(); List<QueuedShader> shadersInQueue = new LinkedList<QueuedShader>();
// //
//Compute shader related //Compute shader related
@ -147,7 +147,7 @@ public class AssetManager {
//shaders //shaders
LoggerInterface.loggerEngine.DEBUG_LOOP("AssetManager - Load visual shaders"); LoggerInterface.loggerEngine.DEBUG_LOOP("AssetManager - Load visual shaders");
Globals.profiler.beginCpuSample("AssetManager.loadAssetsInQueue - Load visual shaders"); Globals.profiler.beginCpuSample("AssetManager.loadAssetsInQueue - Load visual shaders");
for(ActorShaderMask currentShader : shadersInQueue){ for(QueuedShader currentShader : shadersInQueue){
String key = getShaderKey(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath()); String key = getShaderKey(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath());
shadersLoadedIntoMemory.put( shadersLoadedIntoMemory.put(
key, key,
@ -662,7 +662,7 @@ public class AssetManager {
// //
public void addShaderToQueue(String vertexShader, String fragmentShader){ public void addShaderToQueue(String vertexShader, String fragmentShader){
lock.lock(); lock.lock();
shadersInQueue.add(new ActorShaderMask("","",vertexShader,fragmentShader)); shadersInQueue.add(new QueuedShader(vertexShader,fragmentShader));
lock.unlock(); lock.unlock();
} }
@ -688,7 +688,7 @@ public class AssetManager {
lock.lock(); lock.lock();
for(String shaderKey : shadersLoadedIntoMemory.keySet()){ for(String shaderKey : shadersLoadedIntoMemory.keySet()){
String shaderPaths[] = shaderKey.split("-"); String shaderPaths[] = shaderKey.split("-");
shadersInQueue.add(new ActorShaderMask("","",shaderPaths[0],shaderPaths[1])); shadersInQueue.add(new QueuedShader(shaderPaths[0],shaderPaths[1]));
} }
shadersLoadedIntoMemory.clear(); shadersLoadedIntoMemory.clear();
lock.unlock(); lock.unlock();

View File

@ -0,0 +1,46 @@
package electrosphere.engine.assetmanager.queue;
/**
* A shader queued to be created
*/
public class QueuedShader {
/**
* The vertex shader's path
*/
private String vertexShaderPath;
/**
* The fragment shader's path
*/
private String fragmentShaderPath;
/**
* A queued shader
* @param vertexShaderPath The vertex shader path
* @param fragmentShaderPath The fragment shader path
*/
public QueuedShader(String vertexShaderPath, String fragmentShaderPath) {
this.vertexShaderPath = vertexShaderPath;
this.fragmentShaderPath = fragmentShaderPath;
}
/**
* Gets the vertex shader's path
* @return The vertex shader's path
*/
public String getVertexShaderPath() {
return vertexShaderPath;
}
/**
* Gets the fragment shader's path
* @return The fragment shader's path
*/
public String getFragmentShaderPath() {
return fragmentShaderPath;
}
}

View File

@ -6,14 +6,12 @@ import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.actor.mask.ActorAnimationData; import electrosphere.renderer.actor.mask.ActorAnimationData;
import electrosphere.renderer.actor.mask.ActorMeshMask; import electrosphere.renderer.actor.mask.ActorMeshMask;
import electrosphere.renderer.actor.mask.ActorShaderMask;
import electrosphere.renderer.actor.mask.ActorTextureMask; import electrosphere.renderer.actor.mask.ActorTextureMask;
import electrosphere.renderer.actor.mask.ActorUniformMap; import electrosphere.renderer.actor.mask.ActorUniformMap;
import electrosphere.renderer.actor.mask.ActorUniformMap.UniformValue; import electrosphere.renderer.actor.mask.ActorUniformMap.UniformValue;
import electrosphere.renderer.model.Model; import electrosphere.renderer.model.Model;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -119,11 +117,6 @@ public class Actor {
*/ */
private ActorMeshMask meshMask = new ActorMeshMask(); private ActorMeshMask meshMask = new ActorMeshMask();
/**
* optional overrides for specific shaders
*/
private List<ActorShaderMask> shaderMasks = new LinkedList<ActorShaderMask>();
/** /**
* optional overrides for textures * optional overrides for textures
*/ */
@ -203,11 +196,6 @@ public class Actor {
meshMask.processMeshMaskQueue(); meshMask.processMeshMaskQueue();
model.setMeshMask(meshMask); model.setMeshMask(meshMask);
model.setTextureMask(textureMap); model.setTextureMask(textureMap);
for(ActorShaderMask shaderMask : shaderMasks){
if(shaderMask.getModelName().equals(pathToFetch)){
model.getShaderMask().put(shaderMask.getMeshName(),shaderMask);
}
}
this.animationData.calculateNodeTransforms(model); this.animationData.calculateNodeTransforms(model);
//apply uniform overrides //apply uniform overrides
if(this.uniformMap.getMeshes() != null && this.uniformMap.getMeshes().size() > 0){ if(this.uniformMap.getMeshes() != null && this.uniformMap.getMeshes().size() > 0){
@ -219,7 +207,6 @@ public class Actor {
} }
} }
model.draw(renderPipelineState,openGLState); model.draw(renderPipelineState,openGLState);
model.getShaderMask().clear();
model.setTextureMask(null); model.setTextureMask(null);
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }
@ -242,7 +229,6 @@ public class Actor {
this.animationData.isPlayingAnimation() && this.animationData.isPlayingAnimation() &&
this.meshMask.getBlockedMeshes().size() == 0 && this.meshMask.getBlockedMeshes().size() == 0 &&
this.textureMap == null && this.textureMap == null &&
this.shaderMasks.size() == 0 &&
this.uniformMap.isEmpty() && this.uniformMap.isEmpty() &&
this.animationData.getStaticMorph() == null this.animationData.getStaticMorph() == null
) )
@ -264,7 +250,6 @@ public class Actor {
rVal = rVal + this.animationData.isPlayingAnimation() + "\n"; rVal = rVal + this.animationData.isPlayingAnimation() + "\n";
rVal = rVal + (this.meshMask.getBlockedMeshes().size() == 0) + "\n"; rVal = rVal + (this.meshMask.getBlockedMeshes().size() == 0) + "\n";
rVal = rVal + (this.textureMap == null) + "\n"; rVal = rVal + (this.textureMap == null) + "\n";
rVal = rVal + (this.shaderMasks.size() == 0) + "\n";
rVal = rVal + this.uniformMap.isEmpty() + "\n"; rVal = rVal + this.uniformMap.isEmpty() + "\n";
rVal = rVal + (this.animationData.getStaticMorph() == null) + "\n"; rVal = rVal + (this.animationData.getStaticMorph() == null) + "\n";
return rVal; return rVal;
@ -323,24 +308,6 @@ public class Actor {
return meshMask; return meshMask;
} }
/**
* Masks a shader with another shader
* @param mesh The mesh to apply the mask on
* @param vertexShader the vertex shader to apply
* @param fragmentShader the fragment shader to apply
*/
public void maskShader(String mesh, String vertexShader, String fragmentShader){
shaderMasks.add(new ActorShaderMask(this.baseModelPath, mesh, vertexShader, fragmentShader));
}
/**
* Unmasks a shader
* @param mesh the mesh to unmask
*/
public void unmaskShader(String mesh){
throw new UnsupportedOperationException("Not implemented yet");
}
/** /**
* Adds a texture mask to this actor * Adds a texture mask to this actor
* @param textureMask The texture mask * @param textureMask The texture mask

View File

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Semaphore; import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
@ -36,7 +36,7 @@ public class ActorMeshMask {
/** /**
* lock for queueing blockers * lock for queueing blockers
*/ */
private Semaphore queueLock = new Semaphore(1); private ReentrantLock lock = new ReentrantLock();
/** /**
* The set of queued meshes * The set of queued meshes
@ -56,9 +56,9 @@ public class ActorMeshMask {
* @param meshName The mesh's name * @param meshName The mesh's name
*/ */
public void queueMesh(String modelName, String meshName){ public void queueMesh(String modelName, String meshName){
queueLock.acquireUninterruptibly(); lock.lock();
queuedMeshes.add(new MeshDrawQueueItem(modelName, meshName)); queuedMeshes.add(new MeshDrawQueueItem(modelName, meshName));
queueLock.release(); lock.unlock();
} }
/** /**
@ -67,7 +67,7 @@ public class ActorMeshMask {
public void processMeshMaskQueue(){ public void processMeshMaskQueue(){
Model model; Model model;
Mesh mesh; Mesh mesh;
if(queueLock.tryAcquire()){ if(lock.tryLock()){
if(queuedMeshes.size() > 0 || queuedBlockers.size() > 0){ if(queuedMeshes.size() > 0 || queuedBlockers.size() > 0){
//process queued meshes //process queued meshes
List<MeshDrawQueueItem> toRemove = new LinkedList<MeshDrawQueueItem>(); List<MeshDrawQueueItem> toRemove = new LinkedList<MeshDrawQueueItem>();
@ -96,7 +96,7 @@ public class ActorMeshMask {
queuedBlockers.remove(item); queuedBlockers.remove(item);
} }
} }
queueLock.release(); lock.unlock();
} }
} }
@ -152,9 +152,9 @@ public class ActorMeshMask {
* @param meshName The name of the mesh * @param meshName The name of the mesh
*/ */
public void blockMesh(String modelName, String meshName){ public void blockMesh(String modelName, String meshName){
queueLock.acquireUninterruptibly(); lock.lock();
queuedBlockers.add(new MeshDrawQueueItem(modelName, meshName)); queuedBlockers.add(new MeshDrawQueueItem(modelName, meshName));
queueLock.release(); lock.unlock();
} }
/** /**

View File

@ -1,74 +0,0 @@
package electrosphere.renderer.actor.mask;
/**
* Masks a shader on a mesh with another shader
*/
public class ActorShaderMask {
/**
* The name of the model
*/
private String modelName;
/**
* The name of the mesh to apply the shader to
*/
private String meshName;
/**
* The vertex shader's path
*/
private String vertexShaderPath;
/**
* The fragment shader's path
*/
private String fragmentShaderPath;
/**
* Constructor
* @param modelName
* @param meshName
* @param vertexShaderPath
* @param fragmentShaderPath
*/
public ActorShaderMask(String modelName, String meshName, String vertexShaderPath, String fragmentShaderPath){
this.modelName = modelName;
this.meshName = meshName;
this.vertexShaderPath = vertexShaderPath;
this.fragmentShaderPath = fragmentShaderPath;
}
/**
* Gets the model name
* @return the model name
*/
public String getModelName(){
return modelName;
}
/**
* Gets the mesh name
* @return the mesh name
*/
public String getMeshName(){
return meshName;
}
/**
* Gets the vertex shader path
* @return the vertex shader path
*/
public String getVertexShaderPath(){
return vertexShaderPath;
}
/**
* Gets the fragment shader path
* @return the fragment shader path
*/
public String getFragmentShaderPath(){
return fragmentShaderPath;
}
}

View File

@ -5,13 +5,11 @@ import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.actor.ActorBoneRotator; import electrosphere.renderer.actor.ActorBoneRotator;
import electrosphere.renderer.actor.ActorStaticMorph; import electrosphere.renderer.actor.ActorStaticMorph;
import electrosphere.renderer.actor.mask.ActorMeshMask; import electrosphere.renderer.actor.mask.ActorMeshMask;
import electrosphere.renderer.actor.mask.ActorShaderMask;
import electrosphere.renderer.actor.mask.ActorTextureMask; import electrosphere.renderer.actor.mask.ActorTextureMask;
import electrosphere.renderer.anim.AnimChannel; import electrosphere.renderer.anim.AnimChannel;
import electrosphere.renderer.anim.Animation; import electrosphere.renderer.anim.Animation;
import electrosphere.renderer.loading.ModelPretransforms; import electrosphere.renderer.loading.ModelPretransforms;
import electrosphere.renderer.meshgen.MeshLoader; import electrosphere.renderer.meshgen.MeshLoader;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.anim.AnimNode; import electrosphere.renderer.anim.AnimNode;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
@ -105,11 +103,6 @@ public class Model {
* A mask that overwrites meshes themsselves * A mask that overwrites meshes themsselves
*/ */
private ActorMeshMask meshMask; private ActorMeshMask meshMask;
/**
* A mask that overwrites shaders on a given mesh
*/
private Map<String,ActorShaderMask> shaderMask = new HashMap<String,ActorShaderMask>();
/** /**
* A mask that overwrites textures on a given mesh * A mask that overwrites textures on a given mesh
@ -271,10 +264,6 @@ public class Model {
while(mesh_Iterator.hasNext()){ while(mesh_Iterator.hasNext()){
Mesh currentMesh = mesh_Iterator.next(); Mesh currentMesh = mesh_Iterator.next();
if(meshMask == null || (meshMask != null && !meshMask.isBlockedMesh(currentMesh.getMeshName()))){ if(meshMask == null || (meshMask != null && !meshMask.isBlockedMesh(currentMesh.getMeshName()))){
//set shader
VisualShader original = currentMesh.getShader();
VisualShader shader = getCorrectShader(shaderMask, currentMesh, currentMesh.getShader());
currentMesh.setShader(shader);
//set texture mask //set texture mask
if(this.textureMap != null && textureMap.containsKey(currentMesh.getMeshName())){ if(this.textureMap != null && textureMap.containsKey(currentMesh.getMeshName())){
currentMesh.setTextureMask(textureMap.get(currentMesh.getMeshName())); currentMesh.setTextureMask(textureMap.get(currentMesh.getMeshName()));
@ -283,22 +272,14 @@ public class Model {
currentMesh.complexDraw(renderPipelineState, openGLState); currentMesh.complexDraw(renderPipelineState, openGLState);
//reset texture mask //reset texture mask
currentMesh.setTextureMask(null); currentMesh.setTextureMask(null);
//reset shader
currentMesh.setShader(original);
} }
} }
if(meshMask != null){ if(meshMask != null){
for(Mesh toDraw : meshMask.getToDrawMeshes()){ for(Mesh toDraw : meshMask.getToDrawMeshes()){
toDraw.setBones(bones); toDraw.setBones(bones);
toDraw.setParent(this); toDraw.setParent(this);
//set shader
VisualShader original = toDraw.getShader();
VisualShader shader = getCorrectShader(shaderMask, toDraw, toDraw.getShader());
toDraw.setShader(shader);
//draw //draw
toDraw.complexDraw(renderPipelineState, openGLState); toDraw.complexDraw(renderPipelineState, openGLState);
//reset shader
toDraw.setShader(original);
} }
} }
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
@ -322,25 +303,6 @@ public class Model {
public int getMeshCount(){ public int getMeshCount(){
return this.meshes.size(); return this.meshes.size();
} }
/**
* Determines the correct shader to use for a given mesh
* @param shaderMask The shader mask
* @param mesh The mesh
* @param oldShader The original shader on the mesh
* @return The correct shader program to use for this mesh
*/
private VisualShader getCorrectShader(Map<String,ActorShaderMask> shaderMask, Mesh mesh, VisualShader oldShader){
VisualShader rVal = oldShader;
if(shaderMask.containsKey(mesh.getMeshName())){
ActorShaderMask specificMask = shaderMask.get(mesh.getMeshName());
VisualShader overwriteShader = null;
if((overwriteShader = Globals.assetManager.fetchShader(specificMask.getVertexShaderPath(), specificMask.getFragmentShaderPath())) != null){
rVal = overwriteShader;
}
}
return rVal;
}
/** /**
@ -662,14 +624,6 @@ public class Model {
this.textureMap = textureMask; this.textureMap = textureMask;
} }
/**
* Gets the shader mask map
* @return The shader mask map
*/
public Map<String,ActorShaderMask> getShaderMask(){
return shaderMask;
}
/** /**
* Utility method to attempt overwriting the model's meshes with a new material * Utility method to attempt overwriting the model's meshes with a new material