diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/effects/EffectsHandler.java b/src/main/java/com/simibubi/create/foundation/render/backend/effects/EffectsHandler.java index 57ad125bb..79d71205f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/effects/EffectsHandler.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/effects/EffectsHandler.java @@ -97,9 +97,7 @@ public class EffectsHandler { program.bindDepthTexture(mainBuffer.getDepthAttachment()); GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer; - //Matrix4f projection = gameRenderer.getBasicProjectionMatrix(gameRenderer.getActiveRenderInfo(), AnimationTickHolder.getPartialTicks(), true); - Matrix4f projection = Backend.projectionMatrix.copy(); - //projection.a23 = projection.a32 = 0; + Matrix4f projection = gameRenderer.getBasicProjectionMatrix(gameRenderer.getActiveRenderInfo(), AnimationTickHolder.getPartialTicks(), true); projection.a33 = 1; projection.invert(); program.bindInverseProjection(projection); @@ -111,7 +109,6 @@ public class EffectsHandler { Vector3d pos1 = new Vector3d(330, 0, 110); Vector3d cameraPos = gameRenderer.getActiveRenderInfo().getProjectedView(); - program.setTestParam((float) (Math.E - 0.99)); program.setCameraPos(cameraPos.inverse()); for (int i = 0; i < 16; i++) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java b/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java index afa618d0f..dfa0c397d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/effects/SphereFilterProgram.java @@ -17,15 +17,17 @@ import net.minecraft.util.math.vector.Vector3d; 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; // + 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 filters = new ArrayList<>(16); @@ -41,11 +43,6 @@ public class SphereFilterProgram extends GlProgram { protected final int uFarPlane; 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) { super(name, handle); @@ -54,11 +51,11 @@ public class SphereFilterProgram extends GlProgram { uniformBlock = GL31.glGetUniformBlockIndex(handle, "Filters"); - GL31.glUniformBlockBinding(handle, uniformBlock, BLOCK_BINDING); + GL31.glUniformBlockBinding(handle, uniformBlock, UBO_BINDING); effectsUBO.bind(); 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(); uInverseProjection = getUniformLocation("uInverseProjection"); @@ -66,12 +63,6 @@ public class SphereFilterProgram extends GlProgram { uNearPlane = getUniformLocation("uNearPlane"); uFarPlane = getUniformLocation("uFarPlane"); uCameraPos = getUniformLocation("uCameraPos"); - testParam = getUniformLocation("testParam"); -// -// uSphereCenter = getUniformLocation("uSphereCenter"); -// uSphereRadius = getUniformLocation("uSphereRadius"); -// uSphereFeather = getUniformLocation("uSphereFeather"); -// uColorFilter = getUniformLocation("uColorFilter"); bind(); uDepth = setSamplerBinding("uDepth", 8); @@ -87,10 +78,6 @@ public class SphereFilterProgram extends GlProgram { GL20.glUniform1f(uFarPlane, farPlane); } - public void setTestParam(float farPlane) { - GL20.glUniform1f(testParam, farPlane); - } - public void setCameraPos(Vector3d pos) { 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); } -// 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) { uploadMatrixUniform(uInverseProjection, mat); } @@ -141,7 +119,6 @@ public class SphereFilterProgram extends GlProgram { buf.position(16); FloatBuffer floatBuffer = buf.asFloatBuffer(); - //floatBuffer.position(4); filters.forEach(it -> it.write(floatBuffer)); } @@ -179,7 +156,7 @@ public class SphereFilterProgram extends GlProgram { (float) center.z, radius, feather, - 0, + 0, // padding, we could add more parameters here 0, 0 }); diff --git a/src/main/resources/assets/create/flywheel/shaders/area_effect.frag b/src/main/resources/assets/create/flywheel/shaders/area_effect.frag index 7f0d6f5e2..1e06411d8 100644 --- a/src/main/resources/assets/create/flywheel/shaders/area_effect.frag +++ b/src/main/resources/assets/create/flywheel/shaders/area_effect.frag @@ -1,7 +1,5 @@ #version 140 -#define LC 1.7282818// e - 0.99 - #flwinclude <"create:core/color.glsl"> in vec2 ScreenCoord; @@ -16,11 +14,6 @@ uniform float uNearPlane = 0.15; uniform float uFarPlane = 1.; uniform vec3 uCameraPos; -uniform float testParam = 2.0; - -uniform mat4 uInverseProjection; -uniform mat4 uInverseView; - struct SphereFilter { vec4 sphere;// float feather; @@ -35,8 +28,7 @@ layout (std140) uniform Filters { float linearizeDepth(float d, float zNear, float zFar) { float clipZ = 2.0 * d - 1.0; - float linearized = zNear * zFar / (zFar + zNear - clipZ * (zFar - zNear)); - return LC * linearized; + return zNear * zFar / (zFar + zNear - clipZ * (zFar - zNear)); } vec4 filterColor(mat4 colorOp, vec4 frag) { @@ -49,11 +41,7 @@ vec4 filterColor(mat4 colorOp, vec4 frag) { float getDepth() { float depth = texture2D(uDepth, ScreenCoord).r; - depth = linearizeDepth(depth, uNearPlane, uFarPlane); - //depth = (depth - uNearPlane) / (uFarPlane - uNearPlane); - //depth = depth / uFarPlane; - - return depth; + return linearizeDepth(depth, uNearPlane, uFarPlane); } vec4 applyFilters(vec3 worldPos, vec4 diffuse) { @@ -85,6 +73,6 @@ void main() { vec4 diffuse = texture2D(uColor, ScreenCoord); - //Color = applyFilters(worldPos, diffuse); - Color = debugGrid(worldPos, diffuse); + Color = applyFilters(worldPos, diffuse); + //Color = debugGrid(worldPos, diffuse); } diff --git a/src/main/resources/assets/create/flywheel/shaders/area_effect.vert b/src/main/resources/assets/create/flywheel/shaders/area_effect.vert index 525191aa1..6c1d35d5f 100644 --- a/src/main/resources/assets/create/flywheel/shaders/area_effect.vert +++ b/src/main/resources/assets/create/flywheel/shaders/area_effect.vert @@ -1,5 +1,9 @@ #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;// out vec2 ScreenCoord; @@ -17,6 +21,6 @@ void main() { clip *= uInverseProjection; vec3 cameraDir = clip.xyz / clip.w; + cameraDir = cameraDir * vec3(SXY, SXY, SZ); WorldDir = (uInverseView * vec4(cameraDir, 1.)).xyz; - //worldDirection = (uInverseProjection * vec4(aVertex.xy, 0, 1.)).xyz; }