shadow fix
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-07-30 12:29:09 -04:00
parent b37f80c18d
commit bfbdf5cf3e
13 changed files with 57 additions and 58 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file #maven.buildNumber.plugin properties file
#Sat Jul 20 11:59:30 EDT 2024 #Mon Jul 29 21:49:03 EDT 2024
buildNumber=186 buildNumber=188

View File

@ -10,7 +10,6 @@
+ bug fixes + bug fixes
fix bug where synchronization packet for non-existant entity crashes engine fix bug where synchronization packet for non-existant entity crashes engine
fix rendering pipelines (black when looking at character from angle with item, shadows are not darker color, etc)
fix items falling through floor fix items falling through floor
fix jump tree not applying force while movement tree is active fix jump tree not applying force while movement tree is active

View File

@ -482,6 +482,8 @@ Option to load all cells on init scene file
Insidious Entity protocol bugfix on server Insidious Entity protocol bugfix on server
Refactor network protocols to enforce async/sync split Refactor network protocols to enforce async/sync split
(07/30/2024)
Fix depth texture for shadow rendering
# TODO # TODO

View File

@ -227,7 +227,6 @@ public class Globals {
public static Matrix4f lightDepthMatrix = new Matrix4f(); public static Matrix4f lightDepthMatrix = new Matrix4f();
//locations for shadow map specific variables //locations for shadow map specific variables
public static int shadowMapTextureLoc = 0;
public static int depthMapShaderProgramLoc = 0; public static int depthMapShaderProgramLoc = 0;

View File

@ -126,6 +126,8 @@ public class RenderingEngine {
private static String glslVersion = null; private static String glslVersion = null;
//shadow stuff
public static Texture lightBufferDepthTexture;
@ -342,7 +344,7 @@ public class RenderingEngine {
lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/lightDepth/lightDepth.vs", "/Shaders/lightDepth/lightDepth.fs"); lightDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/lightDepth/lightDepth.vs", "/Shaders/lightDepth/lightDepth.fs");
Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.getShaderId(); Globals.depthMapShaderProgramLoc = lightDepthShaderProgram.getShaderId();
lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState); lightDepthBuffer = FramebufferUtils.generateDepthBuffer(openGLState);
Globals.shadowMapTextureLoc = lightDepthBuffer.getTexturePointer(); lightBufferDepthTexture = lightDepthBuffer.getDepthTexture();
// glEnable(GL_CULL_FACE); // enabled for shadow mapping // glEnable(GL_CULL_FACE); // enabled for shadow mapping
// //

View File

@ -27,12 +27,14 @@ public class Framebuffer {
//the pointer to the framebuffer //the pointer to the framebuffer
int framebufferPointer; int framebufferPointer;
//gets the texture pointer to the framebuffer's content
int texturePointer;
//the mipmap level //the mipmap level
int mipMap = -1; int mipMap = -1;
//the map of attachment point to texture object //the map of attachment point to texture object
Map<Integer,Texture> attachTextureMap = new HashMap<Integer,Texture>(); Map<Integer,Texture> attachTextureMap = new HashMap<Integer,Texture>();
//attached texture
Texture texture;
//the depth texture for the framebuffer
Texture depthTexture;
/** /**
* Creates a framebuffer * Creates a framebuffer
@ -54,27 +56,28 @@ public class Framebuffer {
* @param texture The texture attached to the framebuffer * @param texture The texture attached to the framebuffer
*/ */
public void setTexture(Texture texture){ public void setTexture(Texture texture){
setTexture(texture.getTexturePointer()); this.texture = texture;
} }
/** /**
* Sets the texture attached to the framebuffer * Gets the texture attached to this framebuffer
* @param texturePointer The texture attached to the framebuffer * @return The texture
*/ */
public void setTexture(int texturePointer){ public Texture getTexture(){
this.texturePointer = texturePointer; return texture;
} }
/** /**
* Gets the texture associated with the framebuffer * Gets the depth texture attached to this framebuffer
* @return The texture's pointer * @return The depth texture
*/ */
public int getTexturePointer(){ public Texture getDepthTexture(){
return texturePointer; return depthTexture;
} }
/** /**
* Binds the framebuffer * Binds the framebuffer
* @param openGLState The opengl state
*/ */
public void bind(OpenGLState openGLState){ public void bind(OpenGLState openGLState){
openGLState.glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer); openGLState.glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer);
@ -176,31 +179,10 @@ public class Framebuffer {
this.mipMap = mipMap; this.mipMap = mipMap;
} }
/**
* Sets the color attachment
* @param texturePointer The color attachment's pointer
*/
public void attachTexture(OpenGLState openGLState, int texturePointer){
attachTexture(openGLState,texturePointer,0);
}
/**
* Sets the color attachment
* @param texturePointer The color attachment's pointer
* @param attachmentNum The number of the color attachment
*/
public void attachTexture(OpenGLState openGLState, int texturePointer, int attachmentNum){
if(this.mipMap < 0){
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Trying to attach a texture to a framebuffer where mipmap hasn't been set."));
}
this.texturePointer = texturePointer;
openGLState.glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachmentNum, GL_TEXTURE_2D, this.texturePointer, this.mipMap);
}
/** /**
* Attaches a color texture to the default texture unit * Attaches a color texture to the default texture unit
* @param texture * @param openGLState The opengl state
* @param texture The texture
*/ */
public void attachTexture(OpenGLState openGLState, Texture texture){ public void attachTexture(OpenGLState openGLState, Texture texture){
attachTexture(openGLState, texture, 0); attachTexture(openGLState, texture, 0);
@ -208,21 +190,29 @@ public class Framebuffer {
/** /**
* Attaches a texture to the framebuffer * Attaches a texture to the framebuffer
* @param openGLState The opengl state
* @param texture The texture * @param texture The texture
* @param attachmentNum The texture unit to attach to * @param attachmentNum The texture unit to attach to
*/ */
public void attachTexture(OpenGLState openGLState, Texture texture, int attachmentNum){ public void attachTexture(OpenGLState openGLState, Texture texture, int attachmentNum){
this.attachTextureMap.put(attachmentNum,texture); this.attachTextureMap.put(attachmentNum,texture);
attachTexture(openGLState, texture.getTexturePointer(), attachmentNum); if(this.mipMap < 0){
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Trying to attach a texture to a framebuffer where mipmap hasn't been set."));
}
this.texture = texture;
openGLState.glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachmentNum, GL_TEXTURE_2D, texture.getTexturePointer(), this.mipMap);
} }
/** /**
* Sets the depth attachment for the framebuffer * Sets the depth attachment for the framebuffer
* @param openGLState The opengl state
* @param texturePointer The depth attachment's pointer * @param texturePointer The depth attachment's pointer
*/ */
public void setDepthAttachment(OpenGLState openGLState, int texturePointer){ public void setDepthAttachment(OpenGLState openGLState, Texture depthTexture){
openGLState.glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer); openGLState.glBindFramebuffer(GL_FRAMEBUFFER, framebufferPointer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texturePointer, this.mipMap); this.depthTexture = depthTexture;
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture.getTexturePointer(), this.mipMap);
openGLState.glBindFramebuffer(GL_FRAMEBUFFER, 0); openGLState.glBindFramebuffer(GL_FRAMEBUFFER, 0);
checkStatus(); checkStatus();
} }

View File

@ -91,7 +91,7 @@ public class FramebufferUtils {
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.attachTexture(openGLState,colorTexture); buffer.attachTexture(openGLState,colorTexture);
buffer.setDepthAttachment(openGLState,depthTexture.getTexturePointer()); buffer.setDepthAttachment(openGLState,depthTexture);
//check make sure compiled //check make sure compiled
buffer.checkStatus(); buffer.checkStatus();
return buffer; return buffer;
@ -110,7 +110,7 @@ public class FramebufferUtils {
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.attachTexture(openGLState,colorTexture.getTexturePointer()); buffer.attachTexture(openGLState,colorTexture);
//check make sure compiled //check make sure compiled
buffer.checkStatus(); buffer.checkStatus();
return buffer; return buffer;
@ -201,7 +201,7 @@ public class FramebufferUtils {
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.setDepthAttachment(openGLState,texture.getTexturePointer()); buffer.setDepthAttachment(openGLState,texture);
glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL_NONE); glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL_NONE);
glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL_NONE); glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL_NONE);
@ -232,7 +232,7 @@ public class FramebufferUtils {
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.setDepthAttachment(openGLState,texture.getTexturePointer()); buffer.setDepthAttachment(openGLState,texture);
glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL_NONE); glNamedFramebufferDrawBuffer(buffer.getFramebufferPointer(), GL_NONE);
glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL_NONE); glNamedFramebufferReadBuffer(buffer.getFramebufferPointer(), GL_NONE);
@ -268,9 +268,9 @@ public class FramebufferUtils {
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
buffer.attachTexture(openGLState,accumulatorTex.getTexturePointer(),0); buffer.attachTexture(openGLState,accumulatorTex,0);
buffer.attachTexture(openGLState,revealageTex.getTexturePointer(),1); buffer.attachTexture(openGLState,revealageTex,1);
buffer.setDepthAttachment(openGLState,depthTexture.getTexturePointer()); buffer.setDepthAttachment(openGLState,depthTexture);
// const GLenum transparentDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; // const GLenum transparentDrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
// glDrawBuffers(2, transparentDrawBuffers); // glDrawBuffers(2, transparentDrawBuffers);

View File

@ -4,6 +4,7 @@ import electrosphere.engine.Globals;
import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.renderer.OpenGLState; import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderPipelineState;
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.buffer.HomogenousInstancedArray; import electrosphere.renderer.buffer.HomogenousInstancedArray;
@ -420,7 +421,7 @@ public class Mesh {
if(renderPipelineState.getUseShadowMap()){ if(renderPipelineState.getUseShadowMap()){
openGLState.glActiveTexture(GL_TEXTURE3); openGLState.glActiveTexture(GL_TEXTURE3);
openGLState.glBindTexture(GL_TEXTURE_2D, Globals.shadowMapTextureLoc); openGLState.glBindTexture(GL_TEXTURE_2D, RenderingEngine.lightBufferDepthTexture.getTexturePointer());
glUniform1i(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), "shadowMap"), 3); glUniform1i(glGetUniformLocation(openGLState.getActiveShader().getShaderId(), "shadowMap"), 3);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }

View File

@ -206,6 +206,12 @@ public class MainContentPipeline implements RenderPipeline {
renderPipelineState.setSelectedShader(SelectedShaderEnum.PRIMARY); renderPipelineState.setSelectedShader(SelectedShaderEnum.PRIMARY);
//
// Reset State
//
RenderingEngine.defaultFramebuffer.bind(openGLState);
// glBindVertexArray(0); // glBindVertexArray(0);

View File

@ -44,10 +44,10 @@ public class RenderScreenPipeline implements RenderPipeline {
//aaa //aaa
switch(RenderingEngine.outputFramebuffer){ switch(RenderingEngine.outputFramebuffer){
case 0: case 0:
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.screenFramebuffer.getTexturePointer()); openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.screenFramebuffer.getTexture().getTexturePointer());
break; break;
case 1: case 1:
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.lightDepthBuffer.getTexturePointer()); openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.lightDepthBuffer.getTexture().getTexturePointer());
break; break;
case 2: case 2:
openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.volumeDepthBackfaceTexture.getTexturePointer()); openGLState.glBindTexture(GL40.GL_TEXTURE_2D, RenderingEngine.volumeDepthBackfaceTexture.getTexturePointer());

View File

@ -59,7 +59,7 @@ public class ActorPanel extends StandardElement implements DrawableElement, Drag
public ActorPanel(OpenGLState openGLState, int x, int y, int width, int height, Actor actor){ public ActorPanel(OpenGLState openGLState, int x, int y, int width, int height, Actor actor){
super(); super();
elementBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height); elementBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
customMat.setTexturePointer(elementBuffer.getTexturePointer()); customMat.setTexturePointer(elementBuffer.getTexture().getTexturePointer());
this.actor = actor; this.actor = actor;
this.internalPositionX = x; this.internalPositionX = x;
this.internalPositionY = y; this.internalPositionY = y;

View File

@ -39,7 +39,7 @@ public class ScrollableContainer extends StandardContainerElement implements Dra
super(); super();
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height); widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
// widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer(); // widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
customMat.setTexturePointer(widgetBuffer.getTexturePointer()); customMat.setTexturePointer(widgetBuffer.getTexture().getTexturePointer());
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer()); // customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
float ndcX = (float)positionX/Globals.WINDOW_WIDTH; float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT; float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
@ -186,7 +186,7 @@ public class ScrollableContainer extends StandardContainerElement implements Dra
planeModel.pushUniformToMesh("plane", "tPosition", texPosition); planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
planeModel.pushUniformToMesh("plane", "tDimension", texScale); planeModel.pushUniformToMesh("plane", "tDimension", texScale);
planeModel.pushUniformToMesh(planeModel.getMeshes().get(0).getMeshName(), "color", color); planeModel.pushUniformToMesh(planeModel.getMeshes().get(0).getMeshName(), "color", color);
customMat.setTexturePointer(widgetBuffer.getTexturePointer()); customMat.setTexturePointer(widgetBuffer.getTexture().getTexturePointer());
planeModel.getMeshes().get(0).setMaterial(customMat); planeModel.getMeshes().get(0).setMaterial(customMat);
planeModel.drawUI(); planeModel.drawUI();
} else { } else {

View File

@ -71,7 +71,7 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme
*/ */
public Window(OpenGLState openGLState, int positionX, int positionY, int width, int height, boolean showDecorations){ public Window(OpenGLState openGLState, int positionX, int positionY, int width, int height, boolean showDecorations){
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height); widgetBuffer = FramebufferUtils.generateTextureFramebuffer(openGLState, width, height);
customMat.setTexturePointer(widgetBuffer.getTexturePointer()); customMat.setTexturePointer(widgetBuffer.getTexture().getTexturePointer());
float ndcWidth = (float)width/Globals.WINDOW_WIDTH; float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT; float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
float ndcX = (float)positionX/Globals.WINDOW_WIDTH; float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
@ -155,7 +155,7 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme
planeModel.pushUniformToMesh("plane", "tPosition", texPosition); planeModel.pushUniformToMesh("plane", "tPosition", texPosition);
planeModel.pushUniformToMesh("plane", "tDimension", texScale); planeModel.pushUniformToMesh("plane", "tDimension", texScale);
planeModel.pushUniformToMesh(planeModel.getMeshes().get(0).getMeshName(), "color", color); planeModel.pushUniformToMesh(planeModel.getMeshes().get(0).getMeshName(), "color", color);
customMat.setTexturePointer(widgetBuffer.getTexturePointer()); customMat.setTexturePointer(widgetBuffer.getTexture().getTexturePointer());
planeModel.getMeshes().get(0).setMaterial(customMat); planeModel.getMeshes().get(0).setMaterial(customMat);
planeModel.drawUI(); planeModel.drawUI();
} }