bug fixes + shader refactor
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-11-20 20:14:53 -05:00
parent b892bea3d3
commit 3db6180c0e
28 changed files with 255 additions and 314 deletions

View File

@ -13,7 +13,7 @@
"graphicsPerformanceEnableVSync" : false,
"graphicsPerformanceDrawShadows" : true,
"graphicsPerformanceOIT" : true,
"graphicsPerformanceEnableFoliageManager" : false,
"graphicsPerformanceEnableFoliageManager" : true,
"graphicsViewRange" : 20000.0,
"renderResolutionX": 1920,

View File

@ -26,7 +26,7 @@
"name" : "Add",
"first" : {
"name" : "Const",
"value" : 1.0
"value" : 0.5
},
"second" : {
"name" : "OpenSimplex"

View File

@ -1097,6 +1097,9 @@ Up threshold on tests for approximate color matching
Refactor signal service subscription mechanism
Add main thread signal service
Fix backing out to main menu
Refactor ShaderProgram -> VisualShader
Break out shader uniform setting into shared file
Fix being able to walk off far side of the world (ie in level editor)
# TODO
@ -1126,21 +1129,17 @@ Implement gadgets
Bug Fixes
- Fix hitbox placement does not scale with entity scale on server
- Fix not all grass tiles update when updating a nearby voxel (ie it doesn't go into negative coordinates to scan for foliage updates)
- Fix typescript load error
- Calculate bounding sphere for meshes by deforming vertices with bone default pose instead of no bone deform
- Fix threads not synchronizing when returning to main menu (rendering still running when player entity deleted, race condition)
- Fix light cluster mapping for foliage shader
- Fix foliage placement
- Fix lights not being deleted
- Not sending a "light count" var to light calculations, so the data stays in buffer even though it is not being updated
- Fix block tree preventing initiating an attack
- Fix return to title menu synchronization bug
- Fix particles not spawning in correct positions
- Fix flickering when applying yoga signal (may need to rethink arch here)
- Fix virtual scrollables not working
Startup Performance
- Cache loaded typescript
- Allow texture map to bind multiple model paths to a single set of mesh->textures
- Cache texture atlas for terrain
- Separate thread loads non-critical assets async while on title menu, but blocks main game display until completed
@ -1167,20 +1166,12 @@ Rearchitecting
Code cleanup
- Rename "BehaviorTree" to be "Component" (what it actually is)
- Refactor ground movement components
- Refactor menu clases to be under electrosphere.client package
- Rename "ShaderProgram" to "VisualShader"
- Have ComputeShader and VisualShader use same static method for uploading uniforms
Build system to allow specifying certain audio files to load as stereo
Rework how chunks are written to disk to make them more cache friendly
- IE, write consecutively higher LOD levels the further into the file, so that you can read just the first few bytes if its a far away chunk
Bug fixes
- Fix voxel type selection menu not showing textures
- The quads are off screen because the calculation for ndcX/ndcY are putting it wayyy to the right -- will need to revisit calcs for all that
- Fix being able to walk off far side of the world (ie in level editor)
Debug
- Draw all bones with orientations

View File

@ -12,7 +12,7 @@ import electrosphere.entity.ClientEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.types.fluid.FluidChunk;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
/**
@ -27,7 +27,7 @@ public class FluidCell {
Entity modelEntity;
ShaderProgram program;
VisualShader program;
DBody physicsObject;
@ -47,7 +47,7 @@ public class FluidCell {
public static FluidCell generateFluidCell(
Vector3i worldPos,
FluidChunkData data,
ShaderProgram program
VisualShader program
){
FluidCell rVal = new FluidCell();
rVal.worldPos = worldPos;

View File

@ -13,7 +13,7 @@ import electrosphere.client.terrain.manager.ClientTerrainManager;
import electrosphere.engine.Globals;
import electrosphere.entity.EntityUtils;
import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
/**
@ -45,7 +45,7 @@ public class FluidCellManager {
Set<String> updateable;
ShaderProgram program;
VisualShader program;

View File

@ -16,7 +16,7 @@ import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.engine.Globals;
import electrosphere.entity.EntityUtils;
import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
@Deprecated
@ -73,7 +73,7 @@ public class DrawCellManager {
VoxelTextureAtlas atlas;
//shader program for drawable cells
ShaderProgram program;
VisualShader program;

View File

@ -22,6 +22,7 @@ import electrosphere.entity.state.physicssync.ClientPhysicsSyncTree;
import electrosphere.entity.state.physicssync.ServerPhysicsSyncTree;
import electrosphere.entity.types.terrain.TerrainChunkData;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.server.datacell.Realm;
import electrosphere.server.datacell.utils.ServerEntityTagUtils;
@ -45,6 +46,11 @@ public class PhysicsEntityUtils {
*/
static final int STEP_THRESHOLD = 4;
/**
* How close to the edge to position an entity if it overruns the edge
*/
static final double WORLD_MARGIN = 0.001;
/**
* [CLIENT ONLY] Attaches a collidable template to a given entity
* @param rVal The entity
@ -510,7 +516,7 @@ public class PhysicsEntityUtils {
* Repositions all active physics-scoped entities on a given realm
* @param collisionEngine The realm's collision engine
*/
public static void serverRepositionEntities(CollisionEngine collisionEngine){
public static void serverRepositionEntities(Realm realm, CollisionEngine collisionEngine){
List<Entity> toReposition = new LinkedList<Entity>();
List<Collidable> collidableList = collisionEngine.getCollidables();
if(collidableList == null){
@ -524,8 +530,19 @@ public class PhysicsEntityUtils {
toReposition.add(entity);
}
}
ServerWorldData worldDat = realm.getServerWorldData();
for(Entity parent : toReposition){
ServerEntityUtils.repositionEntity(parent,EntityUtils.getPosition(parent));
Vector3d parentPos = EntityUtils.getPosition(parent);
if(worldDat.convertRealToChunkSpace(parentPos.x) >= worldDat.getWorldSizeDiscrete()){
parentPos.x = worldDat.convertWorldToReal(worldDat.getWorldSizeDiscrete()) - WORLD_MARGIN;
}
if(worldDat.convertRealToChunkSpace(parentPos.y) >= worldDat.getWorldSizeDiscrete()){
parentPos.y = worldDat.convertWorldToReal(worldDat.getWorldSizeDiscrete()) - WORLD_MARGIN;
}
if(worldDat.convertRealToChunkSpace(parentPos.z) >= worldDat.getWorldSizeDiscrete()){
parentPos.z = worldDat.convertWorldToReal(worldDat.getWorldSizeDiscrete()) - WORLD_MARGIN;
}
ServerEntityUtils.repositionEntity(parent,parentPos);
}
}

View File

@ -69,7 +69,7 @@ import electrosphere.renderer.loading.ModelPretransforms;
import electrosphere.renderer.meshgen.FluidChunkModelGeneration;
import electrosphere.renderer.model.Material;
import electrosphere.renderer.shader.ShaderOptionMap;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.TextureMap;
import electrosphere.renderer.ui.ElementService;
import electrosphere.renderer.ui.elements.ImagePanel;
@ -294,8 +294,8 @@ public class Globals {
public static TextureMap textureMapDefault;
public static ModelPretransforms modelPretransforms;
public static ShaderProgram defaultMeshShader;
public static ShaderProgram terrainShaderProgram;
public static VisualShader defaultMeshShader;
public static VisualShader terrainShaderProgram;
//
// Particle stuff
@ -641,11 +641,11 @@ public class Globals {
//initialize required windows
WindowUtils.initBaseWindows();
//init default shaderProgram
defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true);
defaultMeshShader = VisualShader.smart_assemble_shader(false,true);
//init terrain shader program
terrainShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/entities/terrain2/terrain2.vs", "/Shaders/entities/terrain2/terrain2.fs");
terrainShaderProgram = VisualShader.loadSpecificShader("/Shaders/entities/terrain2/terrain2.vs", "/Shaders/entities/terrain2/terrain2.fs");
//init fluid shader program
FluidChunkModelGeneration.fluidChunkShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/entities/fluid2/fluid2.vs", "/Shaders/entities/fluid2/fluid2.fs");
FluidChunkModelGeneration.fluidChunkShaderProgram = VisualShader.loadSpecificShader("/Shaders/entities/fluid2/fluid2.vs", "/Shaders/entities/fluid2/fluid2.fs");
//init models
assetManager.registerModelToSpecificString(RenderUtils.createUnitsphere(), AssetDataStrings.UNITSPHERE);
assetManager.registerModelToSpecificString(RenderUtils.createUnitCylinder(), AssetDataStrings.UNITCYLINDER);

View File

@ -14,7 +14,7 @@ import electrosphere.renderer.loading.ModelLoader;
import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ComputeShader;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.texture.TextureMap;
import electrosphere.server.poseactor.PoseModel;
@ -51,7 +51,7 @@ public class AssetManager {
Map<String,AudioBuffer> audioLoadedIntoMemory = new ConcurrentHashMap<String,AudioBuffer>();
List<String> audioInQueue = new CopyOnWriteArrayList<String>();
Map<String,ShaderProgram> shadersLoadedIntoMemory = new ConcurrentHashMap<String,ShaderProgram>();
Map<String,VisualShader> shadersLoadedIntoMemory = new ConcurrentHashMap<String,VisualShader>();
List<ActorShaderMask> shadersInQueue = new CopyOnWriteArrayList<ActorShaderMask>();
//
@ -132,7 +132,7 @@ public class AssetManager {
String key = getShaderKey(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath());
shadersLoadedIntoMemory.put(
key,
ShaderProgram.loadSpecificShader(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath())
VisualShader.loadSpecificShader(currentShader.getVertexShaderPath(),currentShader.getFragmentShaderPath())
);
}
//compute shaders
@ -266,7 +266,7 @@ public class AssetManager {
if((model = fetchModel(shaderOverride.modelName)) != null){
for(Mesh mesh : model.getMeshes()){
if(mesh.getMeshName().equals(shaderOverride.getMeshName())){
mesh.setShader(ShaderProgram.loadSpecificShader(shaderOverride.vertPath, shaderOverride.fragPath));
mesh.setShader(VisualShader.loadSpecificShader(shaderOverride.vertPath, shaderOverride.fragPath));
}
}
toRemove.add(shaderOverride);
@ -443,9 +443,9 @@ public class AssetManager {
shadersInQueue.add(new ActorShaderMask("","",vertexShader,fragmentShader));
}
public ShaderProgram fetchShader(String vertexPath, String fragmentPath){
public VisualShader fetchShader(String vertexPath, String fragmentPath){
String path = getShaderKey(vertexPath,fragmentPath);
ShaderProgram rVal = null;
VisualShader rVal = null;
if(shadersLoadedIntoMemory.containsKey(path)){
rVal = shadersLoadedIntoMemory.get(path);
}

View File

@ -8,6 +8,7 @@ import electrosphere.engine.Globals;
import electrosphere.entity.state.attach.AttachUtils;
import electrosphere.entity.state.hitbox.HitboxCollectionState;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.server.datacell.Realm;
@ -67,7 +68,15 @@ public class ServerEntityUtils {
throw new Error("Trying to reposition attached entity!");
}
Realm realm = Globals.realmManager.getEntityRealm(entity);
if(position.x < 0 || position.y < 0 || position.z < 0){
ServerWorldData worldDat = realm.getServerWorldData();
if(
position.x < 0 ||
position.y < 0 ||
position.z < 0 ||
worldDat.convertRealToChunkSpace(position.x) >= worldDat.getWorldSizeDiscrete() ||
worldDat.convertRealToChunkSpace(position.y) >= worldDat.getWorldSizeDiscrete() ||
worldDat.convertRealToChunkSpace(position.z) >= worldDat.getWorldSizeDiscrete()
){
throw new Error("Providing invalid location to reposition! " + position);
}
ServerEntityUtils.repositionEntityRecursive(realm, entity, position);
@ -99,6 +108,7 @@ public class ServerEntityUtils {
"Trying to reposition entity on server when it's new cell is null!\n" +
"Entity new position: " + position + "\n"
);
return;
}
}
ServerDataCell.moveEntityFromCellToCell(entity, oldDataCell, newDataCell);

View File

@ -12,7 +12,7 @@ import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.buffer.OpenGLBuffer;
import electrosphere.renderer.buffer.UniformBlockBinding;
import electrosphere.renderer.shader.Shader;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
/**
* Encapsulates the state of opengl.
@ -256,7 +256,7 @@ public class OpenGLState {
* @param program The program to check
* @return true if the provided program is the active program, false otherwise
*/
public boolean isCurrentShader(ShaderProgram program){
public boolean isCurrentShader(VisualShader program){
return this.activeShader == program;
}

View File

@ -12,7 +12,7 @@ import electrosphere.renderer.actor.ActorTextureMask;
import electrosphere.renderer.model.Material;
import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.Texture;
import org.joml.Vector3f;
@ -204,7 +204,7 @@ public class RenderUtils {
particleMesh.setShader(ShaderProgram.smartAssembleOITProgram(false, true));
particleMesh.setShader(VisualShader.smartAssembleOITProgram(false, true));
@ -317,7 +317,7 @@ public class RenderUtils {
planeMesh.setShader(ShaderProgram.loadSpecificShader(vertexShader,fragmentShader));
planeMesh.setShader(VisualShader.loadSpecificShader(vertexShader,fragmentShader));
@ -386,7 +386,7 @@ public class RenderUtils {
Material mat = new Material();
mat.set_diffuse("Textures/color/transparent_teal.png");
sphereMesh.setMaterial(mat);
sphereMesh.setShader(ShaderProgram.smart_assemble_shader(false, true));
sphereMesh.setShader(VisualShader.smart_assemble_shader(false, true));
GL40.glBindVertexArray(0);
sphereMesh.setParent(model);
model.getMeshes().add(sphereMesh);
@ -441,7 +441,7 @@ public class RenderUtils {
Material mat = new Material();
mat.set_diffuse("Textures/color/transparent_teal.png");
sphereMesh.setMaterial(mat);
sphereMesh.setShader(ShaderProgram.smart_assemble_shader(false, true));
sphereMesh.setShader(VisualShader.smart_assemble_shader(false, true));
GL40.glBindVertexArray(0);
sphereMesh.setParent(model);
model.getMeshes().add(sphereMesh);
@ -528,7 +528,7 @@ public class RenderUtils {
Material mat = new Material();
mat.set_diffuse("Textures/color/transparent_teal.png");
sphereMesh.setMaterial(mat);
sphereMesh.setShader(ShaderProgram.smart_assemble_shader(false, true));
sphereMesh.setShader(VisualShader.smart_assemble_shader(false, true));
GL40.glBindVertexArray(0);
sphereMesh.setParent(model);
model.getMeshes().add(sphereMesh);
@ -609,7 +609,7 @@ public class RenderUtils {
m.bufferTextureCoords(textureArrayBufferData, 2);
m.setShader(ShaderProgram.loadSpecificShader("/Shaders/ui/font/basicbitmap/basicbitmap.vs", "/Shaders/ui/font/basicbitmap/basicbitmap.fs"));
m.setShader(VisualShader.loadSpecificShader("/Shaders/ui/font/basicbitmap/basicbitmap.vs", "/Shaders/ui/font/basicbitmap/basicbitmap.fs"));
GL40.glBindVertexArray(0);
@ -706,7 +706,7 @@ public class RenderUtils {
m.bufferTextureCoords(textureArrayBufferData, 2);
m.setShader(ShaderProgram.loadSpecificShader("/Shaders/ui/font/bitmapchar/bitmapchar.vs", "/Shaders/ui/font/bitmapchar/bitmapchar.fs"));
m.setShader(VisualShader.loadSpecificShader("/Shaders/ui/font/bitmapchar/bitmapchar.vs", "/Shaders/ui/font/bitmapchar/bitmapchar.fs"));
GL40.glBindVertexArray(0);
@ -790,7 +790,7 @@ public class RenderUtils {
m.bufferTextureCoords(textureArrayBufferData, 2);
m.setShader(ShaderProgram.loadSpecificShader(vertexShader, fragmentShader));
m.setShader(VisualShader.loadSpecificShader(vertexShader, fragmentShader));
GL40.glBindVertexArray(0);
@ -804,7 +804,7 @@ public class RenderUtils {
public static Model createTerrainModelPrecomputedShader(float[][] heightfield, float[][] texturemap, ShaderProgram program, int stride){
public static Model createTerrainModelPrecomputedShader(float[][] heightfield, float[][] texturemap, VisualShader program, int stride){
Model rVal = new Model();
Mesh m = new Mesh("terrain");
int width = heightfield.length;
@ -979,7 +979,7 @@ public class RenderUtils {
static float MINIMIZATION_DIFF_MAX = 0.001f;
public static Model createMinimizedTerrainModelPrecomputedShader(float[][] heightfield, float[][] texturemap, ShaderProgram program, int stride){
public static Model createMinimizedTerrainModelPrecomputedShader(float[][] heightfield, float[][] texturemap, VisualShader program, int stride){
class QuadToGenerate {
//coords are inclusive

View File

@ -44,7 +44,7 @@ import electrosphere.renderer.pipelines.ShadowMapPipeline;
import electrosphere.renderer.pipelines.UIPipeline;
import electrosphere.renderer.pipelines.VolumeBufferPipeline;
import electrosphere.renderer.pipelines.debug.DebugContentPipeline;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.Texture;
public class RenderingEngine {
@ -58,8 +58,8 @@ public class RenderingEngine {
public static Framebuffer screenFramebuffer;
public static Renderbuffer screenRenderbuffer;
public static int screenTextureVAO;
public static ShaderProgram screenTextureShaders;
public static ShaderProgram drawChannel;
public static VisualShader screenTextureShaders;
public static VisualShader drawChannel;
public Framebuffer defaultFramebuffer;
@ -76,7 +76,7 @@ public class RenderingEngine {
//depth framebuffer/shader for shadow mapping
public static ShaderProgram lightDepthShaderProgram;
public static VisualShader lightDepthShaderProgram;
public static Framebuffer lightDepthBuffer;
//framebuffers for transparent textures
@ -85,14 +85,14 @@ public class RenderingEngine {
public static float[] transparencyRevealageClear;
public static Texture transparencyRevealageTexture;
public static Framebuffer transparencyBuffer;
public static ShaderProgram oitCompositeProgram;
public static VisualShader oitCompositeProgram;
/*
render normals
*/
public static Texture gameImageNormalsTexture;
public static Framebuffer gameImageNormalsFramebuffer;
public static ShaderProgram renderNormalsShader;
public static VisualShader renderNormalsShader;
/*
Perspective volumetrics
@ -100,7 +100,7 @@ public class RenderingEngine {
public static Matrix4f nearVolumeProjectionMatrix = new Matrix4f();
public static Matrix4f midVolumeProjectionMatrix = new Matrix4f();
public static Matrix4f farVolumeProjectionMatrix = new Matrix4f();
public static ShaderProgram volumeDepthShaderProgram;
public static VisualShader volumeDepthShaderProgram;
public static Framebuffer volumeDepthBackfaceFramebuffer;
public static Texture volumeDepthBackfaceTexture;
public static Framebuffer volumeDepthFrontfaceFramebuffer;
@ -127,12 +127,12 @@ public class RenderingEngine {
*/
public static Texture normalsOutlineTexture;
public static Framebuffer normalsOutlineFrambuffer;
public static ShaderProgram normalsOutlineShader;
public static VisualShader normalsOutlineShader;
/*
compositing functions
*/
public static ShaderProgram compositeAnimeOutline;
public static VisualShader compositeAnimeOutline;
// public static boolean renderHitboxes = false;
@ -308,7 +308,7 @@ public class RenderingEngine {
//init screen rendering quadrant
screenTextureVAO = createScreenTextureVAO();
// initScreenTextureShaderProgram();
screenTextureShaders = ShaderProgram.loadSpecificShader("/Shaders/core/screentexture/simple1/simple1.vs", "/Shaders/core/screentexture/simple1/simple1.fs");
screenTextureShaders = VisualShader.loadSpecificShader("/Shaders/core/screentexture/simple1/simple1.vs", "/Shaders/core/screentexture/simple1/simple1.fs");
// screenTextureShaders = ShaderProgram.loadSpecificShader("/Shaders/screentexture/drawDepthBuffer/drawDepthBuffer.vs", "/Shaders/screentexture/drawDepthBuffer/drawDepthBuffer.fs");
//default framebuffer
@ -333,12 +333,12 @@ public class RenderingEngine {
//
//Channel debug program
//
drawChannel = ShaderProgram.loadSpecificShader("/Shaders/core/screentexture/drawChannel/drawChannel.vs", "/Shaders/core/screentexture/drawChannel/drawChannel.fs");
drawChannel = VisualShader.loadSpecificShader("/Shaders/core/screentexture/drawChannel/drawChannel.vs", "/Shaders/core/screentexture/drawChannel/drawChannel.fs");
//
//create light depth framebuffer/shader for shadowmapping
//
lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/lightDepth/lightDepth.vs", "/Shaders/core/lightDepth/lightDepth.fs");
lightDepthShaderProgram = VisualShader.loadSpecificShader("/Shaders/core/lightDepth/lightDepth.vs", "/Shaders/core/lightDepth/lightDepth.fs");
Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.getId();
try {
Framebuffer lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState);
@ -354,7 +354,7 @@ public class RenderingEngine {
//create volume depth framebuffer/shader for volumetric rendering
//
try {
volumeDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/core/volumeBuffer/volumetric.vs", "/Shaders/core/volumeBuffer/volumetric.fs");
volumeDepthShaderProgram = VisualShader.loadSpecificShader("/Shaders/core/volumeBuffer/volumetric.vs", "/Shaders/core/volumeBuffer/volumetric.fs");
volumeDepthBackfaceTexture = FramebufferUtils.generateDepthBufferTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
volumeDepthBackfaceFramebuffer = FramebufferUtils.generateDepthBuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthBackfaceTexture);
volumeDepthFrontfaceTexture = FramebufferUtils.generateDepthBufferTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
@ -375,7 +375,7 @@ public class RenderingEngine {
gameImageNormalsTexture = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
Texture gameImageNormalsDepthTexture = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
gameImageNormalsFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), gameImageNormalsTexture, gameImageNormalsDepthTexture);
renderNormalsShader = ShaderProgram.loadSpecificShader("Shaders/core/anime/renderNormals.vs", "Shaders/core/anime/renderNormals.fs");
renderNormalsShader = VisualShader.loadSpecificShader("Shaders/core/anime/renderNormals.vs", "Shaders/core/anime/renderNormals.fs");
} catch(Exception e){
LoggerInterface.loggerRenderer.ERROR(e);
}
@ -389,7 +389,7 @@ public class RenderingEngine {
transparencyRevealageClear = new float[]{1.0f, 1.0f, 1.0f, 1.0f};
transparencyRevealageTexture = FramebufferUtils.generateOITRevealageTexture(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY());
transparencyBuffer = FramebufferUtils.generateOITFramebuffer(openGLState, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), transparencyAccumulatorTexture, transparencyRevealageTexture, screenTextureDepth);
oitCompositeProgram = ShaderProgram.loadSpecificShader("Shaders/core/oit/composite.vs", "Shaders/core/oit/composite.fs");
oitCompositeProgram = VisualShader.loadSpecificShader("Shaders/core/oit/composite.vs", "Shaders/core/oit/composite.fs");
} catch(Exception e){
LoggerInterface.loggerRenderer.ERROR(e);
}
@ -412,7 +412,7 @@ public class RenderingEngine {
//
//Compositing shaders
//
compositeAnimeOutline = ShaderProgram.loadSpecificShader("Shaders/core/anime/compositeAnimeOutline.vs", "Shaders/core/anime/compositeAnimeOutline.fs");
compositeAnimeOutline = VisualShader.loadSpecificShader("Shaders/core/anime/compositeAnimeOutline.vs", "Shaders/core/anime/compositeAnimeOutline.fs");
//
//Post processing pipeline init

View File

@ -11,7 +11,7 @@ import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.buffer.HomogenousUniformBuffer.HomogenousBufferTypes;
import electrosphere.renderer.buffer.ShaderAttribute;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
/**
* Manages all instanced actors. This is what actually does the draw call in opengl.
@ -110,7 +110,7 @@ public class InstanceManager {
data.fillBuffers();
//fetch model/shader and draw if both available
ShaderProgram shader = Globals.assetManager.fetchShader(data.getVertexShader(), data.getFragmentShader());
VisualShader shader = Globals.assetManager.fetchShader(data.getVertexShader(), data.getFragmentShader());
Model model = Globals.assetManager.fetchModel(modelPath);
if(model != null && shader != null){
openGLState.setActiveShader(renderPipelineState, shader);

View File

@ -10,7 +10,7 @@ import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.model.Material;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.Texture;
/**
@ -62,7 +62,7 @@ public class TextureInstancedActor {
*/
public void draw(RenderPipelineState renderPipelineState, OpenGLState openGLState){
Model model = Globals.assetManager.fetchModel(modelPath);
ShaderProgram shader = Globals.assetManager.fetchShader(vertexShaderPath, fragmentShaderPath);
VisualShader shader = Globals.assetManager.fetchShader(vertexShaderPath, fragmentShaderPath);
if(model != null && shader != null){
//setup render pipeline
boolean instancedState = renderPipelineState.getInstanced();

View File

@ -13,7 +13,7 @@ import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.elementtypes.ContainerElement;
import electrosphere.renderer.ui.elementtypes.DrawableElement;
@ -56,8 +56,8 @@ public class DebugRendering {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
static ShaderProgram windowDrawDebugProgram = null;
static ShaderProgram elementDrawDebugProgram = null;
static VisualShader windowDrawDebugProgram = null;
static VisualShader elementDrawDebugProgram = null;
static Model planeModel = null;
public static void drawUIBounds(Framebuffer parentFramebuffer, Vector3f boxPosition, Vector3f boxDimensions, Vector3f color){
if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS){

View File

@ -15,7 +15,7 @@ import electrosphere.entity.types.fluid.FluidChunkModelData;
import electrosphere.renderer.model.Material;
import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
import static org.lwjgl.opengl.GL30.glBindVertexArray;
@ -366,7 +366,7 @@ public class FluidChunkModelGeneration {
public static ShaderProgram fluidChunkShaderProgram = null;
public static VisualShader fluidChunkShaderProgram = null;

View File

@ -19,7 +19,7 @@ import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.loading.ModelPretransforms;
import electrosphere.renderer.model.Bone;
import electrosphere.renderer.model.Mesh;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
/**
* Main class for loading meshes from assimp scenes
@ -331,9 +331,9 @@ public class MeshLoader {
if(!Globals.HEADLESS){
rVal.setShader(ShaderProgram.smart_assemble_shader(has_bones, apply_lighting));
rVal.setShader(ShaderProgram.smart_assemble_shader(has_bones, apply_lighting));
rVal.setOITShader(ShaderProgram.smartAssembleOITProgram(has_bones, apply_lighting));
rVal.setShader(VisualShader.smart_assemble_shader(has_bones, apply_lighting));
rVal.setShader(VisualShader.smart_assemble_shader(has_bones, apply_lighting));
rVal.setOITShader(VisualShader.smartAssembleOITProgram(has_bones, apply_lighting));
}

View File

@ -8,7 +8,7 @@ import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.actor.ActorTextureMask;
import electrosphere.renderer.actor.instance.InstanceData;
import electrosphere.renderer.light.LightManager;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.Texture;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@ -84,8 +84,8 @@ public class Mesh {
private ActorTextureMask textureMask;
//the shaders currently associated with the mesh
private ShaderProgram shader;
private ShaderProgram oitShader;
private VisualShader shader;
private VisualShader oitShader;
//the uniforms to be sent to the gpu
private HashMap<String,Object> uniforms = new HashMap<String,Object>();
@ -285,7 +285,7 @@ public class Mesh {
* Sets the shader of this mesh
* @param shader The shader
*/
public void setShader(ShaderProgram shader){
public void setShader(VisualShader shader){
this.shader = shader;
}
@ -293,7 +293,7 @@ public class Mesh {
* Gets the shader of this mesh
* @return The shader
*/
public ShaderProgram getShader(){
public VisualShader getShader(){
return shader;
}
@ -301,7 +301,7 @@ public class Mesh {
* Sets the order independent transparency shader
* @param shader The shader
*/
public void setOITShader(ShaderProgram shader){
public void setOITShader(VisualShader shader){
this.oitShader = shader;
}
@ -348,7 +348,7 @@ public class Mesh {
Globals.renderingEngine.checkError();
if(renderPipelineState.getUseMeshShader()){
ShaderProgram selectedProgram = null;
VisualShader selectedProgram = null;
switch(renderPipelineState.getSelectedShader()){
case PRIMARY: {
selectedProgram = shader;

View File

@ -11,7 +11,7 @@ import electrosphere.renderer.anim.AnimChannel;
import electrosphere.renderer.anim.Animation;
import electrosphere.renderer.loading.ModelPretransforms;
import electrosphere.renderer.meshgen.MeshLoader;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.anim.AnimNode;
import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
@ -216,8 +216,8 @@ public class Model {
Mesh currentMesh = mesh_Iterator.next();
if(meshMask == null || (meshMask != null && !meshMask.isBlockedMesh(currentMesh.getMeshName()))){
//set shader
ShaderProgram original = currentMesh.getShader();
ShaderProgram shader = getCorrectShader(shaderMask, currentMesh, currentMesh.getShader());
VisualShader original = currentMesh.getShader();
VisualShader shader = getCorrectShader(shaderMask, currentMesh, currentMesh.getShader());
currentMesh.setShader(shader);
//set texture mask
if(this.textureMap != null && textureMap.containsKey(currentMesh.getMeshName())){
@ -236,8 +236,8 @@ public class Model {
toDraw.setBones(bones);
toDraw.setParent(this);
//set shader
ShaderProgram original = toDraw.getShader();
ShaderProgram shader = getCorrectShader(shaderMask, toDraw, toDraw.getShader());
VisualShader original = toDraw.getShader();
VisualShader shader = getCorrectShader(shaderMask, toDraw, toDraw.getShader());
toDraw.setShader(shader);
//draw
toDraw.complexDraw(renderPipelineState, openGLState);
@ -254,11 +254,11 @@ public class Model {
* @param oldShader The original shader on the mesh
* @return The correct shader program to use for this mesh
*/
ShaderProgram getCorrectShader(Map<String,ActorShaderMask> shaderMask, Mesh mesh, ShaderProgram oldShader){
ShaderProgram rVal = oldShader;
VisualShader getCorrectShader(Map<String,ActorShaderMask> shaderMask, Mesh mesh, VisualShader oldShader){
VisualShader rVal = oldShader;
if(shaderMask.containsKey(mesh.getMeshName())){
ActorShaderMask specificMask = shaderMask.get(mesh.getMeshName());
ShaderProgram overwriteShader = null;
VisualShader overwriteShader = null;
if((overwriteShader = Globals.assetManager.fetchShader(specificMask.getVertexShaderPath(), specificMask.getFragmentShaderPath())) != null){
rVal = overwriteShader;
}

View File

@ -6,7 +6,7 @@ import electrosphere.engine.Globals;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
/**
* Post processing pipeline
@ -21,7 +21,7 @@ public class OutlineNormalsPipeline implements RenderPipeline {
//
RenderingEngine.normalsOutlineFrambuffer.bind(openGLState);
ShaderProgram program = Globals.assetManager.fetchShader("Shaders/core/anime/outlineNormals.vs", "Shaders/core/anime/outlineNormals.fs");
VisualShader program = Globals.assetManager.fetchShader("Shaders/core/anime/outlineNormals.vs", "Shaders/core/anime/outlineNormals.fs");
if(program != null){
openGLState.setActiveShader(renderPipelineState, program);

View File

@ -9,7 +9,7 @@ import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.renderer.texture.Texture;
/**
@ -20,7 +20,7 @@ public class PostProcessingPipeline implements RenderPipeline {
/**
* The shader to render with
*/
ShaderProgram postProcessingShader;
VisualShader postProcessingShader;
/**
* The buffer to render post processing effects to
@ -36,7 +36,7 @@ public class PostProcessingPipeline implements RenderPipeline {
* Init the pipeline
*/
public void init(OpenGLState openGLState){
postProcessingShader = ShaderProgram.loadSpecificShader("Shaders/core/postprocessing/postprocessing.vs", "Shaders/core/postprocessing/postprocessing.fs");
postProcessingShader = VisualShader.loadSpecificShader("Shaders/core/postprocessing/postprocessing.vs", "Shaders/core/postprocessing/postprocessing.fs");
Texture screenTextureColor = FramebufferUtils.generateScreenTextureColorAlpha(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Texture screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
try {

View File

@ -3,17 +3,8 @@ package electrosphere.renderer.shader;
import java.util.HashMap;
import java.util.Map;
import org.joml.Matrix4d;
import org.joml.Matrix4f;
import org.joml.Vector2d;
import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL40;
import org.lwjgl.opengl.GL45;
import org.lwjgl.system.MemoryStack;
import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
@ -39,7 +30,7 @@ public class ComputeShader implements Shader {
public Map<Integer,Object> uniformMap = new HashMap<Integer,Object>();
//keeps track of programs that have already been compiled and returns them instead of recompiling from scratch
static Map<String,ShaderProgram> alreadyCompiledMap = new HashMap<String,ShaderProgram>();
static Map<String,VisualShader> alreadyCompiledMap = new HashMap<String,VisualShader>();
/**
* Creates a compute shader
@ -127,99 +118,11 @@ public class ComputeShader implements Shader {
if(uniformLocation == INVALID_UNIFORM_NAME){
LoggerInterface.loggerRenderer.DEBUG_LOOP("Searched for uniform in a shader that does not contain it. Uniform name: \"" + uniformName + "\"");
} else {
this.setUniform(openGLState, uniformLocation, value);
ShaderUtils.setUniform(openGLState, this.uniformMap, uniformLocation, value);
}
}
/**
* Sets the value of a uniform on this shader
* @param uniformLocation the uniform location
* @param value the value
*/
public void setUniform(OpenGLState openGLState, int uniformLocation, Object value){
if(
OpenGLState.DISABLE_CACHING ||
!uniformMap.containsKey(uniformLocation) ||
!uniformMap.get(uniformLocation).equals(value)
){
try(MemoryStack stack = MemoryStack.stackPush()){
//
//matrix4f
if(value instanceof Matrix4f){
Matrix4f currentUniform = (Matrix4f)value;
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Matrix4f(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//matrix4d
} else if(value instanceof Matrix4d){
Matrix4d currentUniform = (Matrix4d)value;
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Matrix4d(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//vector3f
} else if(value instanceof Vector3f){
Vector3f currentUniform = (Vector3f)value;
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3f(currentUniform)); //create new vector3f to break pointer-matching with equals on cache check
//
//vector3d
} else if(value instanceof Vector3d){
Vector3d currentUniform = (Vector3d)value;
GL40.glUniform3dv(uniformLocation, currentUniform.get(BufferUtils.createDoubleBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3d(currentUniform)); //create new vector3d to break pointer-matching with equals on cache check
//
//vector2d
} else if(value instanceof Vector2d){
Vector2d currentUniform = (Vector2d)value;
GL40.glUniform2dv(uniformLocation, currentUniform.get(BufferUtils.createDoubleBuffer(2)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector2d(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//Vector3i
} else if(value instanceof Vector3i){
Vector3i currentUniform = (Vector3i)value;
GL40.glUniform3uiv(uniformLocation, currentUniform.get(BufferUtils.createIntBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3i(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//Vector2i
} else if(value instanceof Vector2i){
Vector2i currentUniform = (Vector2i)value;
GL40.glUniform2uiv(uniformLocation, currentUniform.get(BufferUtils.createIntBuffer(2)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector2i(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//integer
} else if(value instanceof Integer){
GL40.glUniform1i(uniformLocation, (Integer)value);
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,(Integer)value);
//
//float
} else if(value instanceof Float){
GL40.glUniform1f(uniformLocation, (Float)value);
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,(Float)value);
} else {
throw new UnsupportedOperationException("Tried to set uniform with unsupported type!");
}
}
}
}
@Override
public int getId() {

View File

@ -0,0 +1,114 @@
package electrosphere.renderer.shader;
import java.util.Map;
import org.joml.Matrix4d;
import org.joml.Matrix4f;
import org.joml.Vector2d;
import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL40;
import org.lwjgl.system.MemoryStack;
import electrosphere.engine.Globals;
import electrosphere.renderer.OpenGLState;
/**
* Utility functions for shaders
*/
public class ShaderUtils {
/**
* Sets the value of a uniform on this shader
* @param uniformLocation the uniform location
* @param value the value
*/
protected static void setUniform(OpenGLState openGLState, Map<Integer,Object> uniformMap, int uniformLocation, Object value){
if(
OpenGLState.DISABLE_CACHING ||
!uniformMap.containsKey(uniformLocation) ||
!uniformMap.get(uniformLocation).equals(value)
){
try(MemoryStack stack = MemoryStack.stackPush()){
//
//matrix4f
if(value instanceof Matrix4f){
Matrix4f currentUniform = (Matrix4f)value;
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Matrix4f(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//matrix4d
} else if(value instanceof Matrix4d){
Matrix4d currentUniform = (Matrix4d)value;
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Matrix4d(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//vector3f
} else if(value instanceof Vector3f){
Vector3f currentUniform = (Vector3f)value;
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3f(currentUniform)); //create new vector3f to break pointer-matching with equals on cache check
//
//vector3d
} else if(value instanceof Vector3d){
Vector3d currentUniform = (Vector3d)value;
GL40.glUniform3dv(uniformLocation, currentUniform.get(BufferUtils.createDoubleBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3d(currentUniform)); //create new vector3d to break pointer-matching with equals on cache check
//
//vector2d
} else if(value instanceof Vector2d){
Vector2d currentUniform = (Vector2d)value;
GL40.glUniform2dv(uniformLocation, currentUniform.get(BufferUtils.createDoubleBuffer(2)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector2d(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//Vector3i
} else if(value instanceof Vector3i){
Vector3i currentUniform = (Vector3i)value;
GL40.glUniform3uiv(uniformLocation, currentUniform.get(BufferUtils.createIntBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3i(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//Vector2i
} else if(value instanceof Vector2i){
Vector2i currentUniform = (Vector2i)value;
GL40.glUniform2uiv(uniformLocation, currentUniform.get(BufferUtils.createIntBuffer(2)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector2i(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//integer
} else if(value instanceof Integer){
GL40.glUniform1i(uniformLocation, (Integer)value);
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,(Integer)value);
//
//float
} else if(value instanceof Float){
GL40.glUniform1f(uniformLocation, (Float)value);
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,(Float)value);
} else {
throw new UnsupportedOperationException("Tried to set uniform with unsupported type!");
}
}
}
}
}

View File

@ -27,17 +27,8 @@ import java.util.Map;
import javax.management.RuntimeErrorException;
import org.joml.Matrix4d;
import org.joml.Matrix4f;
import org.joml.Vector2d;
import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector3i;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL40;
import org.lwjgl.system.MemoryStack;
import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface;
@ -48,7 +39,7 @@ import electrosphere.util.FileUtils;
/**
* A shader program
*/
public class ShaderProgram implements Shader {
public class VisualShader implements Shader {
//
//Program stuff
@ -68,9 +59,9 @@ public class ShaderProgram implements Shader {
public Map<Integer,Object> uniformMap = new HashMap<Integer,Object>();
//keeps track of programs that have already been compiled and returns them instead of recompiling from scratch
static Map<String,ShaderProgram> alreadyCompiledMap = new HashMap<String,ShaderProgram>();
static Map<String,VisualShader> alreadyCompiledMap = new HashMap<String,VisualShader>();
public static ShaderProgram smart_assemble_shader(boolean ContainsBones, boolean apply_lighting){
public static VisualShader smart_assemble_shader(boolean ContainsBones, boolean apply_lighting){
//return shader if it has already been compiled
String shaderKey = ContainsBones + "-" + apply_lighting;
@ -89,7 +80,7 @@ public class ShaderProgram implements Shader {
//
//Create ShaderProgram object
//
ShaderProgram rVal = new ShaderProgram();
VisualShader rVal = new VisualShader();
//
//Read in shader programs
//
@ -190,7 +181,7 @@ public class ShaderProgram implements Shader {
* @param apply_lighting True if should apply lighting
* @return The int-pointer to the shader compiled
*/
public static ShaderProgram smartAssembleOITProgram(boolean ContainsBones, boolean apply_lighting){
public static VisualShader smartAssembleOITProgram(boolean ContainsBones, boolean apply_lighting){
//return shader if it has already been compiled
String shaderKey = "oit" + ContainsBones + "-" + apply_lighting;
@ -209,7 +200,7 @@ public class ShaderProgram implements Shader {
//
//Create ShaderProgram object
//
ShaderProgram rVal = new ShaderProgram();
VisualShader rVal = new VisualShader();
//
//Read in shader programs
//
@ -304,13 +295,13 @@ public class ShaderProgram implements Shader {
}
public static ShaderProgram load_default_shader_program(){
public static VisualShader load_default_shader_program(){
//
//Create ShaderProgram object
//
ShaderProgram rVal = new ShaderProgram();
VisualShader rVal = new VisualShader();
//
//Read in shader programs
//
@ -402,8 +393,8 @@ public class ShaderProgram implements Shader {
return rVal;
}
public static ShaderProgram loadSpecificShader(String vertexPath, String fragmentPath){
ShaderProgram rVal = new ShaderProgram();
public static VisualShader loadSpecificShader(String vertexPath, String fragmentPath){
VisualShader rVal = new VisualShader();
//
//Read in shader programs
@ -583,8 +574,8 @@ public class ShaderProgram implements Shader {
return rVal;
}
public static ShaderProgram loadSpecificShader(String vertexPath, String geometryPath, String fragmentPath){
ShaderProgram rVal = new ShaderProgram();
public static VisualShader loadSpecificShader(String vertexPath, String geometryPath, String fragmentPath){
VisualShader rVal = new VisualShader();
//
//Read in shader programs
@ -671,95 +662,7 @@ public class ShaderProgram implements Shader {
return rVal;
}
/**
* Sets the value of a uniform on this shader
* @param uniformLocation the uniform location
* @param value the value
*/
public void setUniform(OpenGLState openGLState, int uniformLocation, Object value){
if(
OpenGLState.DISABLE_CACHING ||
!uniformMap.containsKey(uniformLocation) ||
!uniformMap.get(uniformLocation).equals(value)
){
try(MemoryStack stack = MemoryStack.stackPush()){
//
//matrix4f
if(value instanceof Matrix4f){
Matrix4f currentUniform = (Matrix4f)value;
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Matrix4f(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//matrix4d
} else if(value instanceof Matrix4d){
Matrix4d currentUniform = (Matrix4d)value;
GL40.glUniformMatrix4fv(uniformLocation, false, currentUniform.get(new float[16]));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Matrix4d(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//vector3f
} else if(value instanceof Vector3f){
Vector3f currentUniform = (Vector3f)value;
GL40.glUniform3fv(uniformLocation, currentUniform.get(BufferUtils.createFloatBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3f(currentUniform)); //create new matrix4f to break pointer-matching with equals on cache check
//
//vector3d
} else if(value instanceof Vector3d){
Vector3d currentUniform = (Vector3d)value;
GL40.glUniform3dv(uniformLocation, currentUniform.get(BufferUtils.createDoubleBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3d(currentUniform)); //create new vector3d to break pointer-matching with equals on cache check
//
//vector2d
} else if(value instanceof Vector2d){
Vector2d currentUniform = (Vector2d)value;
GL40.glUniform2dv(uniformLocation, currentUniform.get(BufferUtils.createDoubleBuffer(2)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector2d(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//Vector3i
} else if(value instanceof Vector3i){
Vector3i currentUniform = (Vector3i)value;
GL40.glUniform3uiv(uniformLocation, currentUniform.get(BufferUtils.createIntBuffer(3)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector3i(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//Vector2i
} else if(value instanceof Vector2i){
Vector2i currentUniform = (Vector2i)value;
GL40.glUniform2uiv(uniformLocation, currentUniform.get(BufferUtils.createIntBuffer(2)));
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,new Vector2i(currentUniform)); //create new vector2d to break pointer-matching with equals on cache check
//
//integer
} else if(value instanceof Integer){
GL40.glUniform1i(uniformLocation, (Integer)value);
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,(Integer)value);
//
//float
} else if(value instanceof Float){
GL40.glUniform1f(uniformLocation, (Float)value);
Globals.renderingEngine.checkError();
uniformMap.put(uniformLocation,(Float)value);
} else {
throw new UnsupportedOperationException("Tried to set uniform with unsupported type!");
}
}
}
}
/**
* Tries to set a uniform
@ -790,7 +693,7 @@ public class ShaderProgram implements Shader {
if(uniformLocation == INVALID_UNIFORM_NAME){
LoggerInterface.loggerRenderer.DEBUG_LOOP("Searched for uniform in a shader that does not contain it. Uniform name: \"" + uniformName + "\"");
} else {
this.setUniform(openGLState, uniformLocation, value);
ShaderUtils.setUniform(openGLState, this.uniformMap, uniformLocation, value);
}
}

View File

@ -199,7 +199,7 @@ public class Realm {
if(Globals.RUN_PHYSICS){
collisionEngine.simulatePhysics((float)Globals.timekeeper.getSimFrameTime());
collisionEngine.updateDynamicObjectTransforms();
PhysicsEntityUtils.serverRepositionEntities(collisionEngine);
PhysicsEntityUtils.serverRepositionEntities(this,collisionEngine);
chemistryEngine.collide();
}
//

View File

@ -1,7 +1,7 @@
package electrosphere.server.datacell.physics;
import electrosphere.engine.Globals;
import electrosphere.renderer.shader.ShaderProgram;
import electrosphere.renderer.shader.VisualShader;
import electrosphere.server.datacell.Realm;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
@ -31,7 +31,7 @@ public class DataCellPhysicsManager {
Set<String> hasRequested;
ShaderProgram program;
VisualShader program;

View File

@ -84,8 +84,11 @@ public class NoiseVoxelGen implements VoxelGenerator {
//surface
double sample = this.sampler.getValue(0, realX, realY, realZ);
if(sample > 0){
double surfacePercent = heightDiff / -strideMultiplier;
double finalHeight = MathUtils.clamp(sample,0,1) * MathUtils.clamp(surfacePercent,0,1);
double surfacePercent = -heightDiff / strideMultiplier;
if(surfacePercent > 1.0 || surfacePercent < 0){
throw new Error("surfacePercent " + surfacePercent + " " + realY + " " + surfaceHeight + " " + heightDiff + " " + strideMultiplier);
}
double finalHeight = MathUtils.clamp(sample,0,1) * surfacePercent;
voxel.weight = (float)finalHeight * 2 - 1;
voxel.type = 2;
} else {