Move Fog matrix inversion to the CPU
This commit is contained in:
+7
-3
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user