mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Fix visual artifacts with contraptions while using opfine.
I think the buffers from the shadow pass were bleeding into the color pass.
This commit is contained in:
parent
e0342c4b78
commit
5c4ff9ca2a
9 changed files with 138 additions and 53 deletions
|
@ -1,10 +1,6 @@
|
|||
package com.jozufozu.flywheel.backend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -55,7 +51,7 @@ public class Backend {
|
|||
* (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use.
|
||||
*/
|
||||
public String getBackendDescriptor() {
|
||||
return engine.getProperName();
|
||||
return engine == null ? "" : engine.getProperName();
|
||||
}
|
||||
|
||||
public FlwEngine getEngine() {
|
||||
|
|
|
@ -4,7 +4,11 @@ import java.io.BufferedReader;
|
|||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import com.jozufozu.flywheel.util.Lazy;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
|
@ -15,6 +19,23 @@ public class OptifineHandler {
|
|||
private static Package optifine;
|
||||
private static OptifineHandler handler;
|
||||
|
||||
private static final Lazy<BooleanSupplier> isShadowPass = Lazy.of(() -> {
|
||||
try {
|
||||
Class<?> ofShaders = Class.forName("net.optifine.shaders.Shaders");
|
||||
Field field = ofShaders.getDeclaredField("isShadowPass");
|
||||
field.setAccessible(true);
|
||||
return () -> {
|
||||
try {
|
||||
return field.getBoolean(null);
|
||||
} catch (IllegalAccessException ignored) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} catch (Exception ignored) {
|
||||
return () -> false;
|
||||
}
|
||||
});
|
||||
|
||||
public final boolean usingShaders;
|
||||
|
||||
public OptifineHandler(boolean usingShaders) {
|
||||
|
@ -40,6 +61,10 @@ public class OptifineHandler {
|
|||
.orElse(false);
|
||||
}
|
||||
|
||||
public static boolean isShadowPass() {
|
||||
return isShadowPass.get().getAsBoolean();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
optifine = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
|
||||
|
||||
|
|
|
@ -90,12 +90,12 @@ public class InstanceWorld {
|
|||
* </p>
|
||||
*/
|
||||
public void beginFrame(BeginFrameEvent event) {
|
||||
engine.beginFrame(event.getInfo());
|
||||
engine.beginFrame(event.getCamera());
|
||||
|
||||
taskEngine.syncPoint();
|
||||
|
||||
blockEntityInstanceManager.beginFrame(taskEngine, event.getInfo());
|
||||
entityInstanceManager.beginFrame(taskEngine, event.getInfo());
|
||||
blockEntityInstanceManager.beginFrame(taskEngine, event.getCamera());
|
||||
entityInstanceManager.beginFrame(taskEngine, event.getCamera());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.jozufozu.flywheel.core;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
|
||||
public class LastActiveCamera {
|
||||
|
||||
private static Camera camera;
|
||||
|
||||
public static void _setActiveCamera(Camera camera) {
|
||||
LastActiveCamera.camera = camera;
|
||||
}
|
||||
|
||||
public static Camera getActiveCamera() {
|
||||
return camera;
|
||||
}
|
||||
}
|
|
@ -8,28 +8,28 @@ import net.minecraftforge.eventbus.api.Event;
|
|||
|
||||
public class BeginFrameEvent extends Event {
|
||||
private final ClientLevel world;
|
||||
private final Camera info;
|
||||
private final Frustum clippingHelper;
|
||||
private final Camera camera;
|
||||
private final Frustum frustum;
|
||||
|
||||
public BeginFrameEvent(ClientLevel world, Camera info, Frustum clippingHelper) {
|
||||
public BeginFrameEvent(ClientLevel world, Camera camera, Frustum frustum) {
|
||||
this.world = world;
|
||||
this.info = info;
|
||||
this.clippingHelper = clippingHelper;
|
||||
this.camera = camera;
|
||||
this.frustum = frustum;
|
||||
}
|
||||
|
||||
public ClientLevel getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public Camera getInfo() {
|
||||
return info;
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
public Frustum getClippingHelper() {
|
||||
return clippingHelper;
|
||||
public Frustum getFrustum() {
|
||||
return frustum;
|
||||
}
|
||||
|
||||
public Vec3 getCameraPos() {
|
||||
return info.getPosition();
|
||||
return camera.getPosition();
|
||||
}
|
||||
}
|
||||
|
|
21
src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java
Normal file
21
src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.jozufozu.flywheel.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.core.LastActiveCamera;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
|
||||
@Mixin(Camera.class)
|
||||
public class CameraMixin {
|
||||
|
||||
@Inject(method = "setup", at = @At("TAIL"))
|
||||
private void setup(BlockGetter level, Entity entity, boolean is3rdPerson, boolean isMirrored, float pt, CallbackInfo ci) {
|
||||
LastActiveCamera._setActiveCamera((Camera)(Object) this);
|
||||
}
|
||||
}
|
25
src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java
Normal file
25
src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package com.jozufozu.flywheel.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.backend.OptifineHandler;
|
||||
import com.jozufozu.flywheel.core.LastActiveCamera;
|
||||
import com.jozufozu.flywheel.event.BeginFrameEvent;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
@Mixin(Frustum.class)
|
||||
public class FrustumMixin {
|
||||
|
||||
@Inject(method = "prepare", at = @At("TAIL"))
|
||||
private void onPrepare(double x, double y, double z, CallbackInfo ci) {
|
||||
if (OptifineHandler.isShadowPass()) {
|
||||
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(Minecraft.getInstance().level, LastActiveCamera.getActiveCamera(), (Frustum) (Object) this));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Mixin(LevelRenderer.class)
|
||||
public class RenderHooksMixin {
|
||||
public class LevelRendererMixin {
|
||||
|
||||
@Shadow
|
||||
private ClientLevel level;
|
||||
|
@ -52,7 +52,7 @@ public class RenderHooksMixin {
|
|||
* layer-correct custom rendering. RenderWorldLast is not refined enough for rendering world objects.
|
||||
* This should probably be a forge event.
|
||||
*/
|
||||
@Inject(at = @At("TAIL"), method = "renderChunkLayer")
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ShaderInstance;clear()V"), method = "renderChunkLayer")
|
||||
private void renderLayer(RenderType type, PoseStack stack, double camX, double camY, double camZ, Matrix4f p_172999_, CallbackInfo ci) {
|
||||
|
||||
RenderBuffers renderBuffers = this.renderBuffers;
|
|
@ -1,34 +1,36 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.jozufozu.flywheel.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"refmap": "flywheel.refmap.json",
|
||||
"client": [
|
||||
"BlockEntityTypeMixin",
|
||||
"BufferBuilderMixin",
|
||||
"BufferUploaderAccessor",
|
||||
"CancelEntityRenderMixin",
|
||||
"ChunkRebuildHooksMixin",
|
||||
"EntityTypeMixin",
|
||||
"FixFabulousDepthMixin",
|
||||
"InstanceAddMixin",
|
||||
"InstanceRemoveMixin",
|
||||
"LevelRendererAccessor",
|
||||
"PausedPartialTickAccessor",
|
||||
"RenderHooksMixin",
|
||||
"RenderTexturesMixin",
|
||||
"ShaderCloseMixin",
|
||||
"ShaderInstanceAccessor",
|
||||
"atlas.AtlasDataMixin",
|
||||
"atlas.SheetDataAccessor",
|
||||
"light.LightUpdateMixin",
|
||||
"light.NetworkLightUpdateMixin",
|
||||
"matrix.Matrix3fMixin",
|
||||
"matrix.Matrix4fMixin",
|
||||
"matrix.PoseStackMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.jozufozu.flywheel.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"refmap": "flywheel.refmap.json",
|
||||
"client": [
|
||||
"BlockEntityTypeMixin",
|
||||
"BufferBuilderMixin",
|
||||
"BufferUploaderAccessor",
|
||||
"CameraMixin",
|
||||
"CancelEntityRenderMixin",
|
||||
"ChunkRebuildHooksMixin",
|
||||
"EntityTypeMixin",
|
||||
"FixFabulousDepthMixin",
|
||||
"FrustumMixin",
|
||||
"InstanceAddMixin",
|
||||
"InstanceRemoveMixin",
|
||||
"LevelRendererAccessor",
|
||||
"LevelRendererMixin",
|
||||
"PausedPartialTickAccessor",
|
||||
"RenderTexturesMixin",
|
||||
"ShaderCloseMixin",
|
||||
"ShaderInstanceAccessor",
|
||||
"atlas.AtlasDataMixin",
|
||||
"atlas.SheetDataAccessor",
|
||||
"light.LightUpdateMixin",
|
||||
"light.NetworkLightUpdateMixin",
|
||||
"matrix.Matrix3fMixin",
|
||||
"matrix.Matrix4fMixin",
|
||||
"matrix.PoseStackMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue