Reduce SSAO artifacting

This commit is contained in:
James Seibel
2023-08-26 10:15:17 -05:00
parent 2216eed449
commit 8871b893c1
2 changed files with 16 additions and 15 deletions
@@ -1,6 +1,7 @@
package com.seibel.distanthorizons.core.render.renderer.shaders;
import com.seibel.distanthorizons.api.enums.config.EGpuUploadMethod;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.render.glObject.GLState;
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
@@ -16,15 +17,10 @@ import org.lwjgl.opengl.GL32;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
// For some reason this version looks slightly different to that, even tough there isnt much visible change in the code
public class SSAORenderer
{
public static SSAORenderer INSTANCE = new SSAORenderer();
public SSAORenderer()
{
}
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
private static final float[] box_vertices = {
@@ -36,15 +32,26 @@ public class SSAORenderer
-1, 1,
};
ShaderProgram ssaoShader;
ShaderProgram applyShader;
GLVertexBuffer boxBuffer;
VertexAttribute va;
boolean init = false;
private static final int MAX_KERNEL_SIZE = 32;
private static final int MAX_KERNEL_SIZE = 128;
private float[] kernel = new float[MAX_KERNEL_SIZE * 3];
private int width = -1;
private int height = -1;
private int ssaoFramebuffer = -1;
private int ssaoTexture = -1;
private SSAORenderer() { }
public void init()
{
if (init) return;
@@ -68,12 +75,6 @@ public class SSAORenderer
createBuffer();
}
private int width = -1;
private int height = -1;
private int ssaoFramebuffer = -1;
private int ssaoTexture = -1;
private void createFramebuffer(int width, int height)
{
if (ssaoFramebuffer != -1)
@@ -143,7 +144,6 @@ public class SSAORenderer
{
GLState state = new GLState();
init();
//GL32.glDepthMask(false);
int width = MC_RENDER.getTargetFrameBufferViewportWidth();
int height = MC_RENDER.getTargetFrameBufferViewportHeight();
@@ -172,6 +172,7 @@ public class SSAORenderer
ssaoShader.setUniform(ssaoShader.getUniformLocation("gSampleRad"), 3.0f);
ssaoShader.setUniform(ssaoShader.getUniformLocation("gFactor"), 0.8f);
ssaoShader.setUniform(ssaoShader.getUniformLocation("gPower"), 1.0f);
va.bind();
va.bindBufferToAllBindingPoint(boxBuffer.getId());
+2 -2
View File
@@ -10,7 +10,7 @@ uniform float gFactor;
uniform float gPower;
uniform mat4 gProj;
const int MAX_KERNEL_SIZE = 32;
const int MAX_KERNEL_SIZE = 128;
const float INV_MAX_KERNEL_SIZE_F = 1.0 / float(MAX_KERNEL_SIZE);
const vec2 HALF_2 = vec2(0.5);
uniform vec3 gKernel[MAX_KERNEL_SIZE];
@@ -55,7 +55,7 @@ void main()
float rangeCheck = smoothstep(0.0, 1.0, gSampleRad / abs(viewPos.z - geometryDepth));
// the number added to the samplePos.z can be used to reduce noise in the SSAO application at the cost of reducing the overall affect
occlusion_factor += float(geometryDepth >= samplePos.z + 1.0) * rangeCheck;
occlusion_factor += float(geometryDepth >= samplePos.z + 0.1) * rangeCheck;
}