move matricies inside rendering engine
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-15 14:48:25 -04:00
parent e62671d239
commit ce0a834117
9 changed files with 50 additions and 27 deletions

View File

@ -64,7 +64,7 @@ public class CharacterCustomizer {
//spawn camera so renderer doesn't crash (once render pipeline is modularized this shouldn't be necessary)
Globals.clientState.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3d(0,0,0), new Vector3d(0,0.3f,1).normalize());
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.clientState.playerCamera);
Globals.renderingEngine.getViewMatrix().set(CameraEntityUtils.getCameraViewMatrix(Globals.clientState.playerCamera));
//create actor panel
Actor characterActor = ActorUtils.createActorFromModelPath(selectedRaceType.getGraphicsTemplate().getModel().getPath());

View File

@ -163,7 +163,7 @@ public class CameraHandler {
}
//the view matrix
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.clientState.playerCamera);
Globals.renderingEngine.getViewMatrix().set(CameraEntityUtils.getCameraViewMatrix(Globals.clientState.playerCamera));
//update the cursor on client side
Globals.cursorState.updatePlayerCursor();

View File

@ -2,8 +2,6 @@ package electrosphere.engine;
import java.lang.management.ManagementFactory;
import org.joml.Matrix4d;
import electrosphere.audio.AudioEngine;
import electrosphere.audio.VirtualAudioSourceManager;
import electrosphere.audio.collision.HitboxAudioService;
@ -200,11 +198,6 @@ public class Globals {
public static float aspectRatio = 2.0f;
public static float nearClip = 0.01f;
//matrices for drawing models
public static Matrix4d viewMatrix = new Matrix4d();
public static Matrix4d projectionMatrix;
public static Matrix4d lightDepthMatrix = new Matrix4d();
//locations for shadow map specific variables
public static int depthMapShaderProgramLoc = 0;

View File

@ -120,7 +120,7 @@ public class ClientParticleTree implements BehaviorTree {
}
//rotate the model to face the camera
Matrix4f rotationMatrix = new Matrix4f(Globals.viewMatrix).invert();
Matrix4f rotationMatrix = new Matrix4f(Globals.renderingEngine.getViewMatrix()).invert();
Quaternionf rotation = new Quaternionf(rotationMatrix.getRotation(new AxisAngle4f()));
EntityUtils.getRotation(parent).set(rotation);

View File

@ -146,6 +146,11 @@ public class RenderingEngine {
static float aspectRatio = 1.0f;
static float verticalFOV = 90.0f;
//matrices for drawing models
private Matrix4d viewMatrix = new Matrix4d();
private Matrix4d projectionMatrix = new Matrix4d();
private Matrix4d lightDepthMatrix = new Matrix4d();
/**
* The default material
*/
@ -466,13 +471,11 @@ public class RenderingEngine {
//
// Projection and View matrix creation
//
Globals.projectionMatrix = new Matrix4d();
Globals.viewMatrix = new Matrix4d();
verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
//set local aspect ratio and global aspect ratio at the same time
aspectRatio = Globals.aspectRatio = Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT;
Globals.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, Globals.nearClip, Globals.userSettings.getGraphicsViewDistance());
Globals.viewMatrix.translation(new Vector3d(0.0f,0.0f,-3.0f));
this.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, Globals.nearClip, Globals.userSettings.getGraphicsViewDistance());
this.viewMatrix.translation(new Vector3d(0.0f,0.0f,-3.0f));
/**
* Alert everyone that the rendering engine is ready
@ -574,7 +577,7 @@ public class RenderingEngine {
* Updates the frustum box of the render pipeline
*/
private void updateFrustumBox(){
renderPipelineState.updateFrustumIntersection(Globals.projectionMatrix, Globals.viewMatrix);
renderPipelineState.updateFrustumIntersection(this.projectionMatrix, this.viewMatrix);
}
public void bindFramebuffer(int framebufferPointer){
@ -614,18 +617,21 @@ public class RenderingEngine {
public static void setFOV(float verticalFOV){
RenderingEngine.verticalFOV = verticalFOV;
calculateProjectionMatrix();
Globals.renderingEngine.calculateProjectionMatrix();
}
public static void setAspectRatio(float aspectRatio){
RenderingEngine.aspectRatio = aspectRatio;
calculateProjectionMatrix();
Globals.renderingEngine.calculateProjectionMatrix();
}
static void calculateProjectionMatrix(){
/**
* Calculates the projection matrix
*/
public void calculateProjectionMatrix(){
float radVerticalFOV = (float)(RenderingEngine.verticalFOV * Math.PI /180.0f);
float nearClip = 0.001f;
Globals.projectionMatrix.setPerspective(radVerticalFOV, RenderingEngine.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
this.projectionMatrix.setPerspective(radVerticalFOV, RenderingEngine.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
}
/**
@ -700,6 +706,30 @@ public class RenderingEngine {
return this.materialDefault;
}
/**
* Gets the view matrix
* @return The view matrix
*/
public Matrix4d getViewMatrix(){
return viewMatrix;
}
/**
* Gets the projection matrix
* @return The projection matrix
*/
public Matrix4d getProjectionMatrix(){
return projectionMatrix;
}
/**
* Gets the light depth matrix
* @return The light depth matrix
*/
public Matrix4d getLightDepthMatrix(){
return lightDepthMatrix;
}
/**
* Tries to recapture the screen
*/

View File

@ -204,7 +204,7 @@ public class LightManager {
openGLState.setActiveShader(renderPipelineState, clusterComp);
clusterComp.setUniform(openGLState, "zNear", CameraEntityUtils.getNearClip(camera));
clusterComp.setUniform(openGLState, "zFar", CameraEntityUtils.getFarClip(camera));
clusterComp.setUniform(openGLState, "inverseProjection", new Matrix4d(Globals.projectionMatrix).invert());
clusterComp.setUniform(openGLState, "inverseProjection", new Matrix4d(Globals.renderingEngine.getViewMatrix()).invert());
clusterComp.setUniform(openGLState, "gridSize", new Vector3i(LIGHT_CLUSTER_WIDTH_X,LIGHT_CLUSTER_WIDTH_Y,LIGHT_CLUSTER_WIDTH_Z));
clusterComp.setUniform(openGLState, "screenDimensions", openGLState.getViewport());
@ -216,7 +216,7 @@ public class LightManager {
//cull lights
ComputeShader lightCull = Globals.assetManager.fetchComputeShader(AssetDataStrings.COMPUTE_LIGHT_CULL);
openGLState.setActiveShader(renderPipelineState, lightCull);
lightCull.setUniform(openGLState, "viewMatrix", Globals.viewMatrix);
lightCull.setUniform(openGLState, "viewMatrix", Globals.renderingEngine.getViewMatrix());
lightCull.setUniform(openGLState, "lightCount", this.entityPointLightMap.values().size());
int dispatchLocal = (LIGHT_CLUSTER_WIDTH_X * LIGHT_CLUSTER_WIDTH_Y * LIGHT_CLUSTER_WIDTH_Z) / CULL_LOCAL_SIZE;

View File

@ -481,12 +481,12 @@ public class Mesh {
//buffer model/view/proj matrices
try(MemoryStack stack = MemoryStack.stackPush()){
openGLState.getActiveShader().setUniform(openGLState, "model", parent.getModelMatrix());
openGLState.getActiveShader().setUniform(openGLState, "view", Globals.viewMatrix);
openGLState.getActiveShader().setUniform(openGLState, "projection", Globals.projectionMatrix);
openGLState.getActiveShader().setUniform(openGLState, "view", Globals.renderingEngine.getViewMatrix());
openGLState.getActiveShader().setUniform(openGLState, "projection", Globals.renderingEngine.getProjectionMatrix());
openGLState.getActiveShader().setUniform(openGLState, "viewPos", CameraEntityUtils.getCameraEye(Globals.clientState.playerCamera));
Vector3f worldPos = new Vector3f((float)parent.getWorldPos().x,(float)parent.getWorldPos().y,(float)parent.getWorldPos().z);
openGLState.getActiveShader().setUniform(openGLState, "modelWorldPos", worldPos);
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.lightDepthMatrix);
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.renderingEngine.getLightDepthMatrix());
openGLState.getActiveShader().setUniform(openGLState, "frame", (int)Globals.engineState.timekeeper.getNumberOfRenderFramesElapsed());
openGLState.getActiveShader().setUniform(openGLState, "time", (float)Globals.engineState.timekeeper.getCurrentRendererTime());
}

View File

@ -82,9 +82,9 @@ public class ShadowMapPipeline implements RenderPipeline {
new Vector3d( 0.0f, 0.0f, 0.0f),
SpatialMathUtils.getUpVector()
);
Globals.lightDepthMatrix = lightProjection.mul(lightView);
Globals.renderingEngine.getLightDepthMatrix().set(lightProjection.mul(lightView));
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.lightDepthMatrix);
openGLState.getActiveShader().setUniform(openGLState, "lightSpaceMatrix", Globals.renderingEngine.getLightDepthMatrix());
// glCullFace(GL_FRONT);

View File

@ -47,7 +47,7 @@ public class VolumeBufferPipeline implements RenderPipeline {
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "view"), false, Globals.viewMatrix.get(new float[16]));
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "view"), false, Globals.renderingEngine.getViewMatrix().get(new float[16]));
GL40.glUniformMatrix4fv(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "projection"), false, RenderingEngine.nearVolumeProjectionMatrix.get(new float[16]));
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "linearCoef"), RenderingEngine.volumeDepthLinearCoef);
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "quadCoef"), RenderingEngine.volumeDepthQuadCoef);