move matricies inside rendering engine
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
e62671d239
commit
ce0a834117
@ -64,7 +64,7 @@ public class CharacterCustomizer {
|
|||||||
|
|
||||||
//spawn camera so renderer doesn't crash (once render pipeline is modularized this shouldn't be necessary)
|
//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.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
|
//create actor panel
|
||||||
Actor characterActor = ActorUtils.createActorFromModelPath(selectedRaceType.getGraphicsTemplate().getModel().getPath());
|
Actor characterActor = ActorUtils.createActorFromModelPath(selectedRaceType.getGraphicsTemplate().getModel().getPath());
|
||||||
|
|||||||
@ -163,7 +163,7 @@ public class CameraHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//the view matrix
|
//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
|
//update the cursor on client side
|
||||||
Globals.cursorState.updatePlayerCursor();
|
Globals.cursorState.updatePlayerCursor();
|
||||||
|
|||||||
@ -2,8 +2,6 @@ package electrosphere.engine;
|
|||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
|
||||||
import org.joml.Matrix4d;
|
|
||||||
|
|
||||||
import electrosphere.audio.AudioEngine;
|
import electrosphere.audio.AudioEngine;
|
||||||
import electrosphere.audio.VirtualAudioSourceManager;
|
import electrosphere.audio.VirtualAudioSourceManager;
|
||||||
import electrosphere.audio.collision.HitboxAudioService;
|
import electrosphere.audio.collision.HitboxAudioService;
|
||||||
@ -200,11 +198,6 @@ public class Globals {
|
|||||||
public static float aspectRatio = 2.0f;
|
public static float aspectRatio = 2.0f;
|
||||||
public static float nearClip = 0.01f;
|
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
|
//locations for shadow map specific variables
|
||||||
public static int depthMapShaderProgramLoc = 0;
|
public static int depthMapShaderProgramLoc = 0;
|
||||||
|
|
||||||
|
|||||||
@ -120,7 +120,7 @@ public class ClientParticleTree implements BehaviorTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//rotate the model to face the camera
|
//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()));
|
Quaternionf rotation = new Quaternionf(rotationMatrix.getRotation(new AxisAngle4f()));
|
||||||
EntityUtils.getRotation(parent).set(rotation);
|
EntityUtils.getRotation(parent).set(rotation);
|
||||||
|
|
||||||
|
|||||||
@ -146,6 +146,11 @@ public class RenderingEngine {
|
|||||||
static float aspectRatio = 1.0f;
|
static float aspectRatio = 1.0f;
|
||||||
static float verticalFOV = 90.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
|
* The default material
|
||||||
*/
|
*/
|
||||||
@ -466,13 +471,11 @@ public class RenderingEngine {
|
|||||||
//
|
//
|
||||||
// Projection and View matrix creation
|
// Projection and View matrix creation
|
||||||
//
|
//
|
||||||
Globals.projectionMatrix = new Matrix4d();
|
|
||||||
Globals.viewMatrix = new Matrix4d();
|
|
||||||
verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
|
verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
|
||||||
//set local aspect ratio and global aspect ratio at the same time
|
//set local aspect ratio and global aspect ratio at the same time
|
||||||
aspectRatio = Globals.aspectRatio = Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT;
|
aspectRatio = Globals.aspectRatio = Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT;
|
||||||
Globals.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, Globals.nearClip, Globals.userSettings.getGraphicsViewDistance());
|
this.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, Globals.nearClip, Globals.userSettings.getGraphicsViewDistance());
|
||||||
Globals.viewMatrix.translation(new Vector3d(0.0f,0.0f,-3.0f));
|
this.viewMatrix.translation(new Vector3d(0.0f,0.0f,-3.0f));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alert everyone that the rendering engine is ready
|
* Alert everyone that the rendering engine is ready
|
||||||
@ -574,7 +577,7 @@ public class RenderingEngine {
|
|||||||
* Updates the frustum box of the render pipeline
|
* Updates the frustum box of the render pipeline
|
||||||
*/
|
*/
|
||||||
private void updateFrustumBox(){
|
private void updateFrustumBox(){
|
||||||
renderPipelineState.updateFrustumIntersection(Globals.projectionMatrix, Globals.viewMatrix);
|
renderPipelineState.updateFrustumIntersection(this.projectionMatrix, this.viewMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindFramebuffer(int framebufferPointer){
|
public void bindFramebuffer(int framebufferPointer){
|
||||||
@ -614,18 +617,21 @@ public class RenderingEngine {
|
|||||||
|
|
||||||
public static void setFOV(float verticalFOV){
|
public static void setFOV(float verticalFOV){
|
||||||
RenderingEngine.verticalFOV = verticalFOV;
|
RenderingEngine.verticalFOV = verticalFOV;
|
||||||
calculateProjectionMatrix();
|
Globals.renderingEngine.calculateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAspectRatio(float aspectRatio){
|
public static void setAspectRatio(float aspectRatio){
|
||||||
RenderingEngine.aspectRatio = 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 radVerticalFOV = (float)(RenderingEngine.verticalFOV * Math.PI /180.0f);
|
||||||
float nearClip = 0.001f;
|
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;
|
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
|
* Tries to recapture the screen
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -204,7 +204,7 @@ public class LightManager {
|
|||||||
openGLState.setActiveShader(renderPipelineState, clusterComp);
|
openGLState.setActiveShader(renderPipelineState, clusterComp);
|
||||||
clusterComp.setUniform(openGLState, "zNear", CameraEntityUtils.getNearClip(camera));
|
clusterComp.setUniform(openGLState, "zNear", CameraEntityUtils.getNearClip(camera));
|
||||||
clusterComp.setUniform(openGLState, "zFar", CameraEntityUtils.getFarClip(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, "gridSize", new Vector3i(LIGHT_CLUSTER_WIDTH_X,LIGHT_CLUSTER_WIDTH_Y,LIGHT_CLUSTER_WIDTH_Z));
|
||||||
clusterComp.setUniform(openGLState, "screenDimensions", openGLState.getViewport());
|
clusterComp.setUniform(openGLState, "screenDimensions", openGLState.getViewport());
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ public class LightManager {
|
|||||||
//cull lights
|
//cull lights
|
||||||
ComputeShader lightCull = Globals.assetManager.fetchComputeShader(AssetDataStrings.COMPUTE_LIGHT_CULL);
|
ComputeShader lightCull = Globals.assetManager.fetchComputeShader(AssetDataStrings.COMPUTE_LIGHT_CULL);
|
||||||
openGLState.setActiveShader(renderPipelineState, lightCull);
|
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());
|
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;
|
int dispatchLocal = (LIGHT_CLUSTER_WIDTH_X * LIGHT_CLUSTER_WIDTH_Y * LIGHT_CLUSTER_WIDTH_Z) / CULL_LOCAL_SIZE;
|
||||||
|
|||||||
@ -481,12 +481,12 @@ public class Mesh {
|
|||||||
//buffer model/view/proj matrices
|
//buffer model/view/proj matrices
|
||||||
try(MemoryStack stack = MemoryStack.stackPush()){
|
try(MemoryStack stack = MemoryStack.stackPush()){
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "model", parent.getModelMatrix());
|
openGLState.getActiveShader().setUniform(openGLState, "model", parent.getModelMatrix());
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "view", Globals.viewMatrix);
|
openGLState.getActiveShader().setUniform(openGLState, "view", Globals.renderingEngine.getViewMatrix());
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "projection", Globals.projectionMatrix);
|
openGLState.getActiveShader().setUniform(openGLState, "projection", Globals.renderingEngine.getProjectionMatrix());
|
||||||
openGLState.getActiveShader().setUniform(openGLState, "viewPos", CameraEntityUtils.getCameraEye(Globals.clientState.playerCamera));
|
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);
|
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, "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, "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());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,9 +82,9 @@ public class ShadowMapPipeline implements RenderPipeline {
|
|||||||
new Vector3d( 0.0f, 0.0f, 0.0f),
|
new Vector3d( 0.0f, 0.0f, 0.0f),
|
||||||
SpatialMathUtils.getUpVector()
|
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);
|
// glCullFace(GL_FRONT);
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class VolumeBufferPipeline implements RenderPipeline {
|
|||||||
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
|
GL40.glClear(GL40.GL_DEPTH_BUFFER_BIT);
|
||||||
openGLState.glActiveTexture(GL40.GL_TEXTURE0);
|
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.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(), "linearCoef"), RenderingEngine.volumeDepthLinearCoef);
|
||||||
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "quadCoef"), RenderingEngine.volumeDepthQuadCoef);
|
GL40.glUniform1f(GL40.glGetUniformLocation(openGLState.getActiveShader().getId(), "quadCoef"), RenderingEngine.volumeDepthQuadCoef);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user