Improve SSAO class readability

This commit is contained in:
James Seibel
2023-10-12 19:42:21 -05:00
parent f4e7eb6a38
commit d3a575542d
4 changed files with 34 additions and 11 deletions
@@ -386,8 +386,7 @@ public class LodRenderer
if (Config.Client.Advanced.Graphics.Ssao.enabled.get())
{
profiler.popPush("LOD SSAO");
SSAOShader.INSTANCE.setProjectionMatrix(projectionMatrix);
SSAORenderer.INSTANCE.render(minecraftGlState, partialTicks);
SSAORenderer.INSTANCE.render(minecraftGlState, projectionMatrix, partialTicks);
}
profiler.popPush("LOD Fog");
@@ -24,10 +24,17 @@ import com.seibel.distanthorizons.core.render.glObject.GLState;
import com.seibel.distanthorizons.core.render.renderer.shaders.SSAOApplyShader;
import com.seibel.distanthorizons.core.render.renderer.shaders.SSAOShader;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import org.lwjgl.opengl.GL32;
import java.nio.ByteBuffer;
/**
* Handles adding SSAO via {@link SSAOShader} and {@link SSAOApplyShader}. <br><br>
*
* {@link SSAOShader} - draws the SSAO to a texture. <br>
* {@link SSAOApplyShader} - draws the SSAO texture to DH's FrameBuffer. <br>
*/
public class SSAORenderer
{
public static SSAORenderer INSTANCE = new SSAORenderer();
@@ -90,7 +97,7 @@ public class SSAORenderer
// render //
//========//
public void render(GLState primaryState, float partialTicks)
public void render(GLState primaryState, Mat4f projectionMatrix, float partialTicks)
{
GLState state = new GLState();
@@ -107,6 +114,7 @@ public class SSAORenderer
}
SSAOShader.INSTANCE.FrameBuffer = this.ssaoFramebuffer;
SSAOShader.INSTANCE.setProjectionMatrix(projectionMatrix);
SSAOShader.INSTANCE.render(partialTicks);
primaryState.restore();
@@ -22,11 +22,19 @@ package com.seibel.distanthorizons.core.render.renderer.shaders;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.render.renderer.SSAORenderer;
import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderUtil;
import org.lwjgl.opengl.GL32;
/**
* Draws the SSAO texture onto DH's FrameBuffer. <br><br>
*
* See Also: <br>
* {@link SSAORenderer} - Parent to this shader. <br>
* {@link SSAOShader} - draws the SSAO texture. <br>
*/
public class SSAOApplyShader extends AbstractShaderRenderer
{
public static SSAOApplyShader INSTANCE = new SSAOApplyShader();
@@ -22,18 +22,26 @@ package com.seibel.distanthorizons.core.render.renderer.shaders;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.render.renderer.SSAORenderer;
import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import org.lwjgl.opengl.GL32;
/**
* Draws the SSAO to a texture. <br><br>
*
* See Also: <br>
* {@link SSAORenderer} - Parent to this shader. <br>
* {@link SSAOApplyShader} - draws the SSAO texture to DH's FrameBuffer. <br>
*/
public class SSAOShader extends AbstractShaderRenderer
{
public static SSAOShader INSTANCE = new SSAOShader();
public int FrameBuffer;
private Mat4f perspective;
private Mat4f invertedPerspective;
private Mat4f projection;
private Mat4f invertedProjection;
// uniforms
public int gProjUniform;
@@ -63,20 +71,20 @@ public class SSAOShader extends AbstractShaderRenderer
this.gDepthMapUniform = this.shader.getUniformLocation("gDepthMap");
}
public void setProjectionMatrix(Mat4f perspective)
public void setProjectionMatrix(Mat4f projectionMatrix)
{
this.perspective = perspective;
this.projection = projectionMatrix;
this.invertedPerspective = new Mat4f(perspective);
this.invertedPerspective.invert();
this.invertedProjection = new Mat4f(projectionMatrix);
this.invertedProjection.invert();
}
@Override
protected void onApplyUniforms(float partialTicks)
{
this.shader.setUniform(this.gProjUniform, this.perspective);
this.shader.setUniform(this.gProjUniform, this.projection);
this.shader.setUniform(this.gInvProjUniform, this.invertedPerspective);
this.shader.setUniform(this.gInvProjUniform, this.invertedProjection);
this.shader.setUniform(this.gSampleCountUniform,
Config.Client.Advanced.Graphics.Ssao.sampleCount.get());