Move Fog matrix inversion to the CPU

This commit is contained in:
James Seibel
2023-08-31 21:15:49 -05:00
parent 08f78c22f0
commit b894cc8836
2 changed files with 10 additions and 7 deletions
@@ -21,7 +21,7 @@ public class FogShader extends AbstractShaderRenderer
private static final IVersionConstants VERSION_CONSTANTS = SingletonInjector.INSTANCE.get(IVersionConstants.class);
public final int gModelViewProjectionUniform;
public final int gInvertedModelViewProjectionUniform;
public final int gDepthMapUniform;
// Fog Uniforms
@@ -48,7 +48,7 @@ public class FogShader extends AbstractShaderRenderer
// because disabling fog can cause the GLSL to optimize out most (if not all) uniforms
this.gModelViewProjectionUniform = this.shader.tryGetUniformLocation("gMvmProj");
this.gInvertedModelViewProjectionUniform = this.shader.tryGetUniformLocation("gInvMvmProj");
this.gDepthMapUniform = this.shader.tryGetUniformLocation("gDepthMap");
// Fog uniforms
@@ -119,7 +119,11 @@ public class FogShader extends AbstractShaderRenderer
public void setModelViewProjectionMatrix(Mat4f combinedModelViewProjectionMatrix)
{
this.shader.bind();
this.shader.setUniform(this.gModelViewProjectionUniform, combinedModelViewProjectionMatrix);
Mat4f inverseMvmProjMatrix = new Mat4f(combinedModelViewProjectionMatrix);
inverseMvmProjMatrix.invert();
this.shader.setUniform(this.gInvertedModelViewProjectionUniform, inverseMvmProjMatrix);
this.shader.unbind();
}
+3 -4
View File
@@ -4,8 +4,8 @@ in vec2 TexCoord;
out vec4 fragColor;
uniform sampler2D gDepthMap;
// model view matrix and projection matrix
uniform mat4 gMvmProj;
// inverted model view matrix and projection matrix
uniform mat4 gInvMvmProj;
uniform float fogScale;
uniform float fogVerticalScale;
@@ -62,8 +62,7 @@ vec3 calcViewPosition(float fragmentDepth)
vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0);
ndc.xyz = ndc.xyz * 2.0 - 1.0;
// TODO: This inverse() should be moved CPU side
vec4 eyeCoord = inverse(gMvmProj) * ndc;
vec4 eyeCoord = gInvMvmProj * ndc;
return eyeCoord.xyz / eyeCoord.w;
}