Everything works as intended

This commit is contained in:
JozsefA 2021-04-15 15:39:34 -07:00
parent 45b1412837
commit fafd7c84be
4 changed files with 20 additions and 54 deletions

View file

@ -97,9 +97,7 @@ public class EffectsHandler {
program.bindDepthTexture(mainBuffer.getDepthAttachment()); program.bindDepthTexture(mainBuffer.getDepthAttachment());
GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer;
//Matrix4f projection = gameRenderer.getBasicProjectionMatrix(gameRenderer.getActiveRenderInfo(), AnimationTickHolder.getPartialTicks(), true); Matrix4f projection = gameRenderer.getBasicProjectionMatrix(gameRenderer.getActiveRenderInfo(), AnimationTickHolder.getPartialTicks(), true);
Matrix4f projection = Backend.projectionMatrix.copy();
//projection.a23 = projection.a32 = 0;
projection.a33 = 1; projection.a33 = 1;
projection.invert(); projection.invert();
program.bindInverseProjection(projection); program.bindInverseProjection(projection);
@ -111,7 +109,6 @@ public class EffectsHandler {
Vector3d pos1 = new Vector3d(330, 0, 110); Vector3d pos1 = new Vector3d(330, 0, 110);
Vector3d cameraPos = gameRenderer.getActiveRenderInfo().getProjectedView(); Vector3d cameraPos = gameRenderer.getActiveRenderInfo().getProjectedView();
program.setTestParam((float) (Math.E - 0.99));
program.setCameraPos(cameraPos.inverse()); program.setCameraPos(cameraPos.inverse());
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {

View file

@ -17,15 +17,17 @@ import net.minecraft.util.math.vector.Vector3d;
public class SphereFilterProgram extends GlProgram { public class SphereFilterProgram extends GlProgram {
protected static final int BLOCK_BINDING = 4; protected static final int UBO_BINDING = 4;
protected static final int SPHERE_FILTER_SIZE = 4 * 16 + 16 + 4 * 16 * 16; protected static final int SPHERE_FILTER_SIZE = 24 * 4; // <vec4, float + padding, mat4>
protected static final int MAX_FILTERS = 16; // arbitrary
protected static final int MAX_FILTERS = 16; protected static final int EXTRA_INFO = 16; // array length: int + padding
protected static final int ALL_FILTERS_SIZE = MAX_FILTERS * SPHERE_FILTER_SIZE;
protected static final int BUFFER_SIZE = 4 + MAX_FILTERS * SPHERE_FILTER_SIZE; protected static final int BUFFER_SIZE = EXTRA_INFO + ALL_FILTERS_SIZE;
GlBuffer effectsUBO; public final GlBuffer effectsUBO;
protected final ArrayList<FilterSphere> filters = new ArrayList<>(16); protected final ArrayList<FilterSphere> filters = new ArrayList<>(16);
@ -41,11 +43,6 @@ public class SphereFilterProgram extends GlProgram {
protected final int uFarPlane; protected final int uFarPlane;
protected final int uCameraPos; protected final int uCameraPos;
protected final int testParam;
// protected final int uSphereCenter;
// protected final int uSphereRadius;
// protected final int uSphereFeather;
// protected final int uColorFilter;
public SphereFilterProgram(ResourceLocation name, int handle) { public SphereFilterProgram(ResourceLocation name, int handle) {
super(name, handle); super(name, handle);
@ -54,11 +51,11 @@ public class SphereFilterProgram extends GlProgram {
uniformBlock = GL31.glGetUniformBlockIndex(handle, "Filters"); uniformBlock = GL31.glGetUniformBlockIndex(handle, "Filters");
GL31.glUniformBlockBinding(handle, uniformBlock, BLOCK_BINDING); GL31.glUniformBlockBinding(handle, uniformBlock, UBO_BINDING);
effectsUBO.bind(); effectsUBO.bind();
effectsUBO.alloc(BUFFER_SIZE, GL20.GL_STATIC_DRAW); effectsUBO.alloc(BUFFER_SIZE, GL20.GL_STATIC_DRAW);
GL31.glBindBufferBase(effectsUBO.getBufferType(), BLOCK_BINDING, effectsUBO.handle()); GL31.glBindBufferBase(effectsUBO.getBufferType(), UBO_BINDING, effectsUBO.handle());
effectsUBO.unbind(); effectsUBO.unbind();
uInverseProjection = getUniformLocation("uInverseProjection"); uInverseProjection = getUniformLocation("uInverseProjection");
@ -66,12 +63,6 @@ public class SphereFilterProgram extends GlProgram {
uNearPlane = getUniformLocation("uNearPlane"); uNearPlane = getUniformLocation("uNearPlane");
uFarPlane = getUniformLocation("uFarPlane"); uFarPlane = getUniformLocation("uFarPlane");
uCameraPos = getUniformLocation("uCameraPos"); uCameraPos = getUniformLocation("uCameraPos");
testParam = getUniformLocation("testParam");
//
// uSphereCenter = getUniformLocation("uSphereCenter");
// uSphereRadius = getUniformLocation("uSphereRadius");
// uSphereFeather = getUniformLocation("uSphereFeather");
// uColorFilter = getUniformLocation("uColorFilter");
bind(); bind();
uDepth = setSamplerBinding("uDepth", 8); uDepth = setSamplerBinding("uDepth", 8);
@ -87,10 +78,6 @@ public class SphereFilterProgram extends GlProgram {
GL20.glUniform1f(uFarPlane, farPlane); GL20.glUniform1f(uFarPlane, farPlane);
} }
public void setTestParam(float farPlane) {
GL20.glUniform1f(testParam, farPlane);
}
public void setCameraPos(Vector3d pos) { public void setCameraPos(Vector3d pos) {
GL20.glUniform3f(uCameraPos, (float) pos.x, (float) pos.y, (float) pos.z); GL20.glUniform3f(uCameraPos, (float) pos.x, (float) pos.y, (float) pos.z);
} }
@ -109,15 +96,6 @@ public class SphereFilterProgram extends GlProgram {
effectsUBO.unbind(GL20.GL_ARRAY_BUFFER); effectsUBO.unbind(GL20.GL_ARRAY_BUFFER);
} }
// public void setSphere(FilterSphere sphere) {
// GL20.glUniform3f(uSphereCenter, (float) sphere.center.x, (float) sphere.center.y, (float) sphere.center.z);
//
// GL20.glUniform1f(uSphereRadius, sphere.radius);
// GL20.glUniform1f(uSphereFeather, sphere.feather);
//
// uploadMatrixUniform(uColorFilter, sphere.filter);
// }
public void bindInverseProjection(Matrix4f mat) { public void bindInverseProjection(Matrix4f mat) {
uploadMatrixUniform(uInverseProjection, mat); uploadMatrixUniform(uInverseProjection, mat);
} }
@ -141,7 +119,6 @@ public class SphereFilterProgram extends GlProgram {
buf.position(16); buf.position(16);
FloatBuffer floatBuffer = buf.asFloatBuffer(); FloatBuffer floatBuffer = buf.asFloatBuffer();
//floatBuffer.position(4);
filters.forEach(it -> it.write(floatBuffer)); filters.forEach(it -> it.write(floatBuffer));
} }
@ -179,7 +156,7 @@ public class SphereFilterProgram extends GlProgram {
(float) center.z, (float) center.z,
radius, radius,
feather, feather,
0, 0, // padding, we could add more parameters here
0, 0,
0 0
}); });

View file

@ -1,7 +1,5 @@
#version 140 #version 140
#define LC 1.7282818// e - 0.99
#flwinclude <"create:core/color.glsl"> #flwinclude <"create:core/color.glsl">
in vec2 ScreenCoord; in vec2 ScreenCoord;
@ -16,11 +14,6 @@ uniform float uNearPlane = 0.15;
uniform float uFarPlane = 1.; uniform float uFarPlane = 1.;
uniform vec3 uCameraPos; uniform vec3 uCameraPos;
uniform float testParam = 2.0;
uniform mat4 uInverseProjection;
uniform mat4 uInverseView;
struct SphereFilter { struct SphereFilter {
vec4 sphere;// <vec3 position, float radius> vec4 sphere;// <vec3 position, float radius>
float feather; float feather;
@ -35,8 +28,7 @@ layout (std140) uniform Filters {
float linearizeDepth(float d, float zNear, float zFar) { float linearizeDepth(float d, float zNear, float zFar) {
float clipZ = 2.0 * d - 1.0; float clipZ = 2.0 * d - 1.0;
float linearized = zNear * zFar / (zFar + zNear - clipZ * (zFar - zNear)); return zNear * zFar / (zFar + zNear - clipZ * (zFar - zNear));
return LC * linearized;
} }
vec4 filterColor(mat4 colorOp, vec4 frag) { vec4 filterColor(mat4 colorOp, vec4 frag) {
@ -49,11 +41,7 @@ vec4 filterColor(mat4 colorOp, vec4 frag) {
float getDepth() { float getDepth() {
float depth = texture2D(uDepth, ScreenCoord).r; float depth = texture2D(uDepth, ScreenCoord).r;
depth = linearizeDepth(depth, uNearPlane, uFarPlane); return linearizeDepth(depth, uNearPlane, uFarPlane);
//depth = (depth - uNearPlane) / (uFarPlane - uNearPlane);
//depth = depth / uFarPlane;
return depth;
} }
vec4 applyFilters(vec3 worldPos, vec4 diffuse) { vec4 applyFilters(vec3 worldPos, vec4 diffuse) {
@ -85,6 +73,6 @@ void main() {
vec4 diffuse = texture2D(uColor, ScreenCoord); vec4 diffuse = texture2D(uColor, ScreenCoord);
//Color = applyFilters(worldPos, diffuse); Color = applyFilters(worldPos, diffuse);
Color = debugGrid(worldPos, diffuse); //Color = debugGrid(worldPos, diffuse);
} }

View file

@ -1,5 +1,9 @@
#version 140 #version 140
// scaling constants
#define SXY 1.7282818// e - 0.99, this works too well
#define SZ 1.905// who knows, but it works
in vec4 aVertex;// <vec2 position, vec2 texCoords> in vec4 aVertex;// <vec2 position, vec2 texCoords>
out vec2 ScreenCoord; out vec2 ScreenCoord;
@ -17,6 +21,6 @@ void main() {
clip *= uInverseProjection; clip *= uInverseProjection;
vec3 cameraDir = clip.xyz / clip.w; vec3 cameraDir = clip.xyz / clip.w;
cameraDir = cameraDir * vec3(SXY, SXY, SZ);
WorldDir = (uInverseView * vec4(cameraDir, 1.)).xyz; WorldDir = (uInverseView * vec4(cameraDir, 1.)).xyz;
//worldDirection = (uInverseProjection * vec4(aVertex.xy, 0, 1.)).xyz;
} }