Move SSAO gInvProj to the CPU instead of GPU
Also make Mat4f.invert() return void instead of boolean to prevent confusion about trying to pass the result into shader uniforms.
This commit is contained in:
+7
@@ -53,6 +53,7 @@ public class SSAORenderer
|
||||
private static class SsaoShaderUniforms
|
||||
{
|
||||
public int gProjUniform;
|
||||
public int gInvProjUniform;
|
||||
public int gSampleRadUniform;
|
||||
public int gFactorUniform;
|
||||
public int gPowerUniform;
|
||||
@@ -100,6 +101,7 @@ public class SSAORenderer
|
||||
|
||||
// SSAO uniform setup
|
||||
this.ssaoShaderUniforms.gProjUniform = this.ssaoShader.getUniformLocation("gProj");
|
||||
this.ssaoShaderUniforms.gInvProjUniform = this.ssaoShader.getUniformLocation("gInvProj");
|
||||
this.ssaoShaderUniforms.gSampleRadUniform = this.ssaoShader.getUniformLocation("gSampleRad");
|
||||
this.ssaoShaderUniforms.gFactorUniform = this.ssaoShader.getUniformLocation("gFactor");
|
||||
this.ssaoShaderUniforms.gPowerUniform = this.ssaoShader.getUniformLocation("gPower");
|
||||
@@ -216,8 +218,13 @@ public class SSAORenderer
|
||||
RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks),
|
||||
(float) ((RenderUtil.getFarClipPlaneDistanceInBlocks() + LodUtil.REGION_WIDTH) * Math.sqrt(2)));
|
||||
|
||||
Mat4f invertedPerspective = new Mat4f(perspective);
|
||||
invertedPerspective.invert();
|
||||
|
||||
|
||||
this.ssaoShader.bind();
|
||||
this.ssaoShader.setUniform(this.ssaoShaderUniforms.gProjUniform, perspective);
|
||||
this.ssaoShader.setUniform(this.ssaoShaderUniforms.gInvProjUniform, invertedPerspective);
|
||||
this.ssaoShader.setUniform(this.ssaoShaderUniforms.gSampleRadUniform, 3.0f);
|
||||
this.ssaoShader.setUniform(this.ssaoShaderUniforms.gFactorUniform, 0.8f);
|
||||
this.ssaoShader.setUniform(this.ssaoShaderUniforms.gPowerUniform, 1.0f);
|
||||
|
||||
@@ -9,6 +9,7 @@ uniform float gSampleRad;
|
||||
uniform float gFactor;
|
||||
uniform float gPower;
|
||||
uniform mat4 gProj;
|
||||
uniform mat4 gInvProj;
|
||||
|
||||
const int MAX_KERNEL_SIZE = 128;
|
||||
const float INV_MAX_KERNEL_SIZE_F = 1.0 / float(MAX_KERNEL_SIZE);
|
||||
@@ -25,7 +26,7 @@ vec3 calcViewPosition(vec2 coords) {
|
||||
1.0
|
||||
);
|
||||
|
||||
vec4 vs_pos = inverse(gProj) * ndc;
|
||||
vec4 vs_pos = gInvProj * ndc;
|
||||
vs_pos.xyz = vs_pos.xyz / vs_pos.w;
|
||||
return vs_pos.xyz;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user