diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java index 305c7fe34..32c2a1c5a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java @@ -46,9 +46,9 @@ public class SSAOShader extends AbstractShaderRenderer MC_RENDER.getTargetFrameBufferViewportWidth() / (float) MC_RENDER.getTargetFrameBufferViewportHeight(), RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks), (float) ((RenderUtil.getFarClipPlaneDistanceInBlocks() + LodUtil.REGION_WIDTH) * Math.sqrt(2))); - - + this.shader.setUniform(this.shader.getUniformLocation("gProj"), perspective); + this.shader.setUniform(this.shader.getUniformLocation("gProjInv"), perspective.invert()); this.shader.setUniform(this.shader.getUniformLocation("gSampleRad"), 3.0f); this.shader.setUniform(this.shader.getUniformLocation("gFactor"), 0.8f); this.shader.setUniform(this.shader.getUniformLocation("gPower"), 1.0f); diff --git a/core/src/main/resources/shaders/ssao/ao.frag b/core/src/main/resources/shaders/ssao/ao.frag index c791b458b..f681cb0e8 100644 --- a/core/src/main/resources/shaders/ssao/ao.frag +++ b/core/src/main/resources/shaders/ssao/ao.frag @@ -9,6 +9,7 @@ uniform float gSampleRad; uniform float gFactor; uniform float gPower; uniform mat4 gProj; +uniform mat4 gProjInv; const int MAX_KERNEL_SIZE = 32; const float INV_MAX_KERNEL_SIZE_F = 1.0 / float(MAX_KERNEL_SIZE); @@ -20,8 +21,7 @@ vec3 calcViewPosition(vec2 coords) { vec4 ndc = vec4(coords.xy, fragmentDepth, 1.0); ndc.xyz = ndc.xyz * 2.0 - 1.0; - // TODO: This inverse() call should be moved CPU side - vec4 vs_pos = inverse(gProj) * ndc; + vec4 vs_pos = gProjInv * ndc; return vs_pos.xyz / vs_pos.w; }