Skip to content

Commit

Permalink
Fix depth test mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jul 25, 2020
1 parent 332ff4c commit 62fb381
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.gl.ShaderEffect;
import net.minecraft.client.options.GraphicsMode;
import net.minecraft.client.render.Camera;

/**
Expand All @@ -28,6 +30,9 @@
public interface PostWorldRenderCallback {
/**
* Fired after Minecraft has rendered everything in the world, before it renders hands, HUDs and GUIs.
*
* <p>{@link ShaderEffect}s <strong>must not</strong> be rendered in this callback, as they will prevent
* {@link GraphicsMode#FABULOUS fabulous graphics} and other effects from working properly.
*/
Event<PostWorldRenderCallback> EVENT = EventFactory.createArrayBacked(PostWorldRenderCallback.class,
(listeners) -> (camera, tickDelta, nanoTime) -> {
Expand Down
3 changes: 3 additions & 0 deletions test_mods/core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DebugItem extends Item {
private int debugMode;
private List<DebugCallback> callbacks = new ArrayList<>();
private final List<DebugCallback> callbacks = new ArrayList<>();

public DebugItem(Settings settings) {
super(settings);
Expand Down
1 change: 1 addition & 0 deletions test_mods/depth/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies {
compile project(":core").sourceSets.main.output
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ladysnake.satindepthtest;

import ladysnake.satin.api.event.PostWorldRenderCallback;
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
import ladysnake.satin.api.experimental.ReadableDepthFramebuffer;
import ladysnake.satin.api.managed.ManagedShaderEffect;
import ladysnake.satin.api.managed.ShaderEffectManager;
import ladysnake.satin.api.managed.uniform.Uniform1f;
import ladysnake.satin.api.managed.uniform.Uniform3f;
import ladysnake.satin.api.managed.uniform.UniformMat4;
import ladysnake.satin.api.util.GlMatrices;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
Expand All @@ -21,7 +22,7 @@

import javax.annotation.Nullable;

public class DepthFx implements PostWorldRenderCallback, ClientTickCallback {
public class DepthFx implements PostWorldRenderCallback, ShaderEffectRenderCallback, ClientTickEvents.EndTick {
public static final Identifier FANCY_NIGHT_SHADER_ID = new Identifier(SatinDepthTest.MOD_ID, "shaders/post/rainbow_ping.json");
public static final DepthFx INSTANCE = new DepthFx();

Expand All @@ -43,14 +44,14 @@ public class DepthFx implements PostWorldRenderCallback, ClientTickCallback {
private boolean isWorldNight(@Nullable PlayerEntity player) {
if (player != null) {
World world = player.world;
float celestialAngle = world.getSkyAngle(1.0f);
float celestialAngle = world.method_30274(1.0f);
return 0.23f < celestialAngle && celestialAngle < 0.76f;
}
return false;
}

@Override
public void tick(MinecraftClient minecraftClient) {
public void onEndTick(MinecraftClient minecraftClient) {
if (!minecraftClient.isPaused()) {
ticks++;
}
Expand All @@ -66,10 +67,14 @@ public void onWorldRendered(Camera camera, float tickDelta, long nanoTime) {
uniformCameraPosition.set((float)cameraPos.x, (float)cameraPos.y, (float)cameraPos.z);
Entity e = camera.getFocusedEntity();
uniformCenter.set(lerpf(e.getX(), e.prevX, tickDelta), lerpf(e.getY(), e.prevY, tickDelta), lerpf(e.getZ(), e.prevZ, tickDelta));
testShader.render(tickDelta);
}
}

@Override
public void renderShaderEffects(float tickDelta) {
testShader.render(tickDelta);
}

private static float lerpf(double n, double prevN, float tickDelta) {
return (float) MathHelper.lerp(tickDelta, prevN, n);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package ladysnake.satindepthtest;

import ladysnake.satin.api.event.PostWorldRenderCallback;
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
import ladysnake.satintestcore.item.SatinTestItems;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;

public class SatinDepthTest implements ClientModInitializer {
public static final String MOD_ID = "satindepthtest";
@Override
public void onInitializeClient() {
ClientTickCallback.EVENT.register(DepthFx.INSTANCE);
ClientTickEvents.END_CLIENT_TICK.register(DepthFx.INSTANCE);
ShaderEffectRenderCallback.EVENT.register(DepthFx.INSTANCE);
PostWorldRenderCallback.EVENT.register(DepthFx.INSTANCE);
SatinTestItems.DEBUG_ITEM.registerDebugCallback((world, player, hand) -> {
if (world.isClient) {
DepthFx.INSTANCE.testShader.release();
}
});
}

}
1 change: 1 addition & 0 deletions test_mods/render-layer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies {
compile project(":core").sourceSets.main.output
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
}

0 comments on commit 62fb381

Please sign in to comment.