standard uniform manager impl
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
4442256566
commit
4a23339807
44
assets/Shaders/lib/standarduniform.fs
Normal file
44
assets/Shaders/lib/standarduniform.fs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Bind point for the standard uniform SSBO
|
||||||
|
*/
|
||||||
|
#define STANDARD_UNIFORM_SSBO_BIND_POINT 4
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The standard uniforms
|
||||||
|
*/
|
||||||
|
struct StandardUniforms {
|
||||||
|
/**
|
||||||
|
* The view matrix
|
||||||
|
*/
|
||||||
|
mat4 view;
|
||||||
|
/**
|
||||||
|
* The projection matrix
|
||||||
|
*/
|
||||||
|
mat4 projection;
|
||||||
|
/**
|
||||||
|
* The light-space matrix
|
||||||
|
*/
|
||||||
|
mat4 lightSpaceMatrix;
|
||||||
|
/**
|
||||||
|
* The view position
|
||||||
|
*/
|
||||||
|
vec4 viewPos;
|
||||||
|
/**
|
||||||
|
* The current frame count
|
||||||
|
*/
|
||||||
|
uint frame;
|
||||||
|
/**
|
||||||
|
* The current engine time
|
||||||
|
*/
|
||||||
|
float time;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cutoff for fragment alpha
|
||||||
|
*/
|
||||||
|
#define FRAGMENT_ALPHA_CUTOFF 0.001
|
||||||
|
|
||||||
|
layout(std430, binding = STANDARD_UNIFORM_SSBO_BIND_POINT) restrict buffer standardUniformSSBO {
|
||||||
|
StandardUniforms standardUniforms;
|
||||||
|
};
|
||||||
@ -1942,6 +1942,7 @@ Main content pipeline tracking
|
|||||||
Error checking on mesh rendering (making sure not trying to draw 0-element meshes)
|
Error checking on mesh rendering (making sure not trying to draw 0-element meshes)
|
||||||
Fix generating rendering geometry for blocks/terrain with 0 elements
|
Fix generating rendering geometry for blocks/terrain with 0 elements
|
||||||
GriddedDataCellManager filtering optimization
|
GriddedDataCellManager filtering optimization
|
||||||
|
StandardUniformManager implementation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,7 @@ import electrosphere.renderer.pipelines.ShadowMapPipeline;
|
|||||||
import electrosphere.renderer.pipelines.UIPipeline;
|
import electrosphere.renderer.pipelines.UIPipeline;
|
||||||
import electrosphere.renderer.pipelines.VolumeBufferPipeline;
|
import electrosphere.renderer.pipelines.VolumeBufferPipeline;
|
||||||
import electrosphere.renderer.pipelines.debug.DebugContentPipeline;
|
import electrosphere.renderer.pipelines.debug.DebugContentPipeline;
|
||||||
|
import electrosphere.renderer.shader.StandardUniformManager;
|
||||||
import electrosphere.renderer.shader.VisualShader;
|
import electrosphere.renderer.shader.VisualShader;
|
||||||
import electrosphere.renderer.target.DrawTargetEvaluator;
|
import electrosphere.renderer.target.DrawTargetEvaluator;
|
||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
@ -173,6 +174,11 @@ public class RenderingEngine {
|
|||||||
* The light manager for the rendering engine
|
* The light manager for the rendering engine
|
||||||
*/
|
*/
|
||||||
LightManager lightManager;
|
LightManager lightManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The standard uniform manager
|
||||||
|
*/
|
||||||
|
private StandardUniformManager standardUniformManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The output framebuffer
|
* The output framebuffer
|
||||||
@ -473,6 +479,10 @@ public class RenderingEngine {
|
|||||||
|
|
||||||
//instantiate light manager
|
//instantiate light manager
|
||||||
lightManager = LightManager.create();
|
lightManager = LightManager.create();
|
||||||
|
|
||||||
|
//
|
||||||
|
//instantiate standard uniform manager
|
||||||
|
standardUniformManager = StandardUniformManager.create();
|
||||||
|
|
||||||
//
|
//
|
||||||
//Fog
|
//Fog
|
||||||
@ -545,6 +555,9 @@ public class RenderingEngine {
|
|||||||
this.updateFrustumBox();
|
this.updateFrustumBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update standard uniforms
|
||||||
|
this.standardUniformManager.update();
|
||||||
|
|
||||||
//determine draw targets
|
//determine draw targets
|
||||||
if(this.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT && shouldRunPipelines()){
|
if(this.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT && shouldRunPipelines()){
|
||||||
DrawTargetEvaluator.evaluate();
|
DrawTargetEvaluator.evaluate();
|
||||||
@ -805,6 +818,14 @@ public class RenderingEngine {
|
|||||||
return this.windowPtr;
|
return this.windowPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the standard uniform manager
|
||||||
|
* @return The standard uniform manager
|
||||||
|
*/
|
||||||
|
public StandardUniformManager getStandardUniformManager(){
|
||||||
|
return this.standardUniformManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to recapture the screen
|
* Tries to recapture the screen
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import electrosphere.renderer.RenderingEngine;
|
|||||||
import electrosphere.renderer.actor.ActorTextureMask;
|
import electrosphere.renderer.actor.ActorTextureMask;
|
||||||
import electrosphere.renderer.actor.instance.InstanceData;
|
import electrosphere.renderer.actor.instance.InstanceData;
|
||||||
import electrosphere.renderer.light.LightManager;
|
import electrosphere.renderer.light.LightManager;
|
||||||
|
import electrosphere.renderer.shader.StandardUniformManager;
|
||||||
import electrosphere.renderer.shader.VisualShader;
|
import electrosphere.renderer.shader.VisualShader;
|
||||||
import electrosphere.renderer.texture.Texture;
|
import electrosphere.renderer.texture.Texture;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
@ -558,6 +559,7 @@ public class Mesh {
|
|||||||
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.renderingEngine.getLightDepthMatrix());
|
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.renderingEngine.getLightDepthMatrix());
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "frame", (int)Globals.engineState.timekeeper.getNumberOfRenderFramesElapsed());
|
openGLState.getActiveShader().setUniform(openGLState, "frame", (int)Globals.engineState.timekeeper.getNumberOfRenderFramesElapsed());
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "time", (float)Globals.engineState.timekeeper.getCurrentRendererTime());
|
openGLState.getActiveShader().setUniform(openGLState, "time", (float)Globals.engineState.timekeeper.getCurrentRendererTime());
|
||||||
|
openGLState.glBindBufferBase(StandardUniformManager.STANDARD_UNIFORM_BUFFER_BIND_POINT, Globals.renderingEngine.getStandardUniformManager().getStandardUnifomSSBO());
|
||||||
}
|
}
|
||||||
Globals.renderingEngine.checkError();
|
Globals.renderingEngine.checkError();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,164 @@
|
|||||||
|
package electrosphere.renderer.shader;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import org.joml.Matrix4d;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
import electrosphere.client.entity.camera.CameraEntityUtils;
|
||||||
|
import electrosphere.engine.Globals;
|
||||||
|
import electrosphere.renderer.buffer.ShaderStorageBuffer;
|
||||||
|
import electrosphere.renderer.buffer.BufferEnums.BufferAccess;
|
||||||
|
import electrosphere.renderer.buffer.BufferEnums.BufferUsage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the standard uniforms
|
||||||
|
*/
|
||||||
|
public class StandardUniformManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind point of the standard uniform buffer
|
||||||
|
*/
|
||||||
|
public static final int STANDARD_UNIFORM_BUFFER_BIND_POINT = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Size of the standard uniform ssbo
|
||||||
|
*/
|
||||||
|
public static final int STANDARD_UNIFORM_SSBO_SIZE = 216;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The standard uniform ssbo
|
||||||
|
Standard uniform struct:
|
||||||
|
{
|
||||||
|
mat4 view; //64 bytes
|
||||||
|
mat4 projection; //64 bytes
|
||||||
|
mat4 lightSpaceMatrix; //64 bytes
|
||||||
|
vec4 viewPos; //16 bytes
|
||||||
|
unsigned int frame; //4 bytes
|
||||||
|
float time; //4 bytes
|
||||||
|
}
|
||||||
|
Totals to 216 bytes
|
||||||
|
*/
|
||||||
|
private ShaderStorageBuffer standardUniformSSBO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor
|
||||||
|
*/
|
||||||
|
private StandardUniformManager(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the standard uniform manager
|
||||||
|
* @return The standard uniform manager
|
||||||
|
*/
|
||||||
|
public static StandardUniformManager create(){
|
||||||
|
StandardUniformManager rVal = new StandardUniformManager();
|
||||||
|
rVal.standardUniformSSBO = new ShaderStorageBuffer(STANDARD_UNIFORM_SSBO_SIZE, BufferUsage.DYNAMIC, BufferAccess.DRAW);
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the standard uniform manager
|
||||||
|
*/
|
||||||
|
public void update(){
|
||||||
|
ByteBuffer buff = standardUniformSSBO.getBuffer();
|
||||||
|
|
||||||
|
//put the view matrix
|
||||||
|
Matrix4d viewMat = Globals.renderingEngine.getViewMatrix();
|
||||||
|
buff.putFloat((float)viewMat.m00());
|
||||||
|
buff.putFloat((float)viewMat.m01());
|
||||||
|
buff.putFloat((float)viewMat.m02());
|
||||||
|
buff.putFloat((float)viewMat.m03());
|
||||||
|
|
||||||
|
buff.putFloat((float)viewMat.m10());
|
||||||
|
buff.putFloat((float)viewMat.m11());
|
||||||
|
buff.putFloat((float)viewMat.m12());
|
||||||
|
buff.putFloat((float)viewMat.m13());
|
||||||
|
|
||||||
|
buff.putFloat((float)viewMat.m20());
|
||||||
|
buff.putFloat((float)viewMat.m21());
|
||||||
|
buff.putFloat((float)viewMat.m22());
|
||||||
|
buff.putFloat((float)viewMat.m23());
|
||||||
|
|
||||||
|
buff.putFloat((float)viewMat.m30());
|
||||||
|
buff.putFloat((float)viewMat.m31());
|
||||||
|
buff.putFloat((float)viewMat.m32());
|
||||||
|
buff.putFloat((float)viewMat.m33());
|
||||||
|
|
||||||
|
//put the projection matrix
|
||||||
|
Matrix4d projectionMat = Globals.renderingEngine.getProjectionMatrix();
|
||||||
|
buff.putFloat((float)projectionMat.m00());
|
||||||
|
buff.putFloat((float)projectionMat.m01());
|
||||||
|
buff.putFloat((float)projectionMat.m02());
|
||||||
|
buff.putFloat((float)projectionMat.m03());
|
||||||
|
|
||||||
|
buff.putFloat((float)projectionMat.m10());
|
||||||
|
buff.putFloat((float)projectionMat.m11());
|
||||||
|
buff.putFloat((float)projectionMat.m12());
|
||||||
|
buff.putFloat((float)projectionMat.m13());
|
||||||
|
|
||||||
|
buff.putFloat((float)projectionMat.m20());
|
||||||
|
buff.putFloat((float)projectionMat.m21());
|
||||||
|
buff.putFloat((float)projectionMat.m22());
|
||||||
|
buff.putFloat((float)projectionMat.m23());
|
||||||
|
|
||||||
|
buff.putFloat((float)projectionMat.m30());
|
||||||
|
buff.putFloat((float)projectionMat.m31());
|
||||||
|
buff.putFloat((float)projectionMat.m32());
|
||||||
|
buff.putFloat((float)projectionMat.m33());
|
||||||
|
|
||||||
|
//put the light space matrix
|
||||||
|
Matrix4d lightSpaceMat = Globals.renderingEngine.getLightDepthMatrix();
|
||||||
|
buff.putFloat((float)lightSpaceMat.m00());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m01());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m02());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m03());
|
||||||
|
|
||||||
|
buff.putFloat((float)lightSpaceMat.m10());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m11());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m12());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m13());
|
||||||
|
|
||||||
|
buff.putFloat((float)lightSpaceMat.m20());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m21());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m22());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m23());
|
||||||
|
|
||||||
|
buff.putFloat((float)lightSpaceMat.m30());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m31());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m32());
|
||||||
|
buff.putFloat((float)lightSpaceMat.m33());
|
||||||
|
|
||||||
|
//put the view pos
|
||||||
|
Vector3d viewPos = CameraEntityUtils.getCameraEye(Globals.clientState.playerCamera);
|
||||||
|
if(viewPos != null){
|
||||||
|
buff.putFloat((float)viewPos.x);
|
||||||
|
buff.putFloat((float)viewPos.y);
|
||||||
|
buff.putFloat((float)viewPos.z);
|
||||||
|
buff.putFloat((float)1);
|
||||||
|
} else {
|
||||||
|
buff.putFloat((float)1);
|
||||||
|
buff.putFloat((float)0);
|
||||||
|
buff.putFloat((float)0);
|
||||||
|
buff.putFloat((float)1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//put the frame count
|
||||||
|
buff.putInt((int)Globals.engineState.timekeeper.getNumberOfRenderFramesElapsed());
|
||||||
|
|
||||||
|
//put the engine time
|
||||||
|
buff.putFloat((float)Globals.engineState.timekeeper.getCurrentRendererTime());
|
||||||
|
|
||||||
|
|
||||||
|
buff.flip();
|
||||||
|
standardUniformSSBO.upload(Globals.renderingEngine.getOpenGLState());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the standard uniform ssbo
|
||||||
|
* @return The standard uniform ssbo
|
||||||
|
*/
|
||||||
|
public ShaderStorageBuffer getStandardUnifomSSBO(){
|
||||||
|
return this.standardUniformSSBO;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user