Skip to content

Commit

Permalink
Add events fired during framegraph setup to allow adding custom passe…
Browse files Browse the repository at this point in the history
…s and enabling entity outline post-processing
  • Loading branch information
XFactHD committed Oct 16, 2024
1 parent b8a868a commit 4b13bc4
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 2 deletions.
13 changes: 11 additions & 2 deletions patches/net/minecraft/client/renderer/LevelRenderer.java.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
--- a/net/minecraft/client/renderer/LevelRenderer.java
+++ b/net/minecraft/client/renderer/LevelRenderer.java
@@ -485,7 +_,7 @@
@@ -484,8 +_,10 @@
RenderSystem.clearColor(vector4f.x, vector4f.y, vector4f.z, 0.0F);
RenderSystem.clear(16640);
});
+ var preEvent = net.neoforged.neoforge.client.ClientHooks.fireFrameGraphSetupPre(framegraphbuilder, this.targets, frustum, p_109604_, p_254120_, p_323920_, p_348530_, profilerfiller);
+ flag2 |= preEvent.isOutlineProcessingEnabled();
if (!flag1) {
- this.addSkyPass(framegraphbuilder, p_109604_, f, fogparameters1);
+ this.addSkyPass(framegraphbuilder, p_109604_, f, fogparameters1, p_254120_, p_323920_);
Expand All @@ -18,7 +21,7 @@
CloudStatus cloudstatus = this.minecraft.options.getCloudsType();
if (cloudstatus != CloudStatus.OFF) {
float f2 = this.level.effects().getCloudHeight();
@@ -505,7 +_,7 @@
@@ -505,12 +_,13 @@
}
}

Expand All @@ -27,6 +30,12 @@
if (postchain != null) {
postchain.addToFrame(framegraphbuilder, i, j, this.targets);
}

this.addLateDebugPass(framegraphbuilder, vec3, fogparameters);
+ var postEvent = net.neoforged.neoforge.client.ClientHooks.fireFrameGraphSetupPost(framegraphbuilder, this.targets, frustum, p_109604_, p_254120_, p_323920_, p_348530_, profilerfiller);
profilerfiller.popPush("framegraph");
framegraphbuilder.execute(p_361796_, new FrameGraphBuilder.Inspector() {
@Override
@@ -576,7 +_,9 @@
double d2 = vec3.z();
p_362234_.push("terrain");
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
Expand Down Expand Up @@ -67,6 +68,7 @@
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LevelTargetBundle;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.ShaderDefines;
Expand Down Expand Up @@ -108,6 +110,7 @@
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -147,6 +150,7 @@
import net.neoforged.neoforge.client.event.ComputeFovModifierEvent;
import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.FrameGraphSetupEvent;
import net.neoforged.neoforge.client.event.GatherEffectScreenTooltipsEvent;
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.client.event.ModelEvent;
Expand Down Expand Up @@ -1088,4 +1092,14 @@ public static RecipeBookType[] getFilteredRecipeBookTypeValues() {
}
return RECIPE_BOOK_TYPES;
}

@ApiStatus.Internal
public static FrameGraphSetupEvent.Pre fireFrameGraphSetupPre(FrameGraphBuilder builder, LevelTargetBundle targets, Frustum frustum, Camera camera, Matrix4f modelViewMatrix, Matrix4f projectionMatrix, DeltaTracker deltaTracker, ProfilerFiller profiler) {
return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent.Pre(builder, targets, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler));
}

@ApiStatus.Internal
public static FrameGraphSetupEvent.Post fireFrameGraphSetupPost(FrameGraphBuilder builder, LevelTargetBundle targets, Frustum frustum, Camera camera, Matrix4f modelViewMatrix, Matrix4f projectionMatrix, DeltaTracker deltaTracker, ProfilerFiller profiler) {
return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent.Post(builder, targets, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.client.event;

import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.renderer.LevelTargetBundle;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.util.profiling.ProfilerFiller;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.ICancellableEvent;
import net.neoforged.fml.LogicalSide;
import net.neoforged.neoforge.common.NeoForge;
import org.jetbrains.annotations.ApiStatus;
import org.joml.Matrix4f;

/**
* Fired when the {@linkplain FrameGraphBuilder frame graph} is set up at the start of level rendering.
* <p>
* These events are not {@linkplain ICancellableEvent cancellable}.
* <p>
* These events are fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.
*/
public abstract sealed class FrameGraphSetupEvent extends Event {
protected final FrameGraphBuilder builder;
private final LevelTargetBundle targets;
private final Frustum frustum;
private final Camera camera;
private final Matrix4f modelViewMatrix;
private final Matrix4f projectionMatrix;
private final DeltaTracker deltaTracker;
private final ProfilerFiller profiler;

protected FrameGraphSetupEvent(
FrameGraphBuilder builder,
LevelTargetBundle targets,
Frustum frustum,
Camera camera,
Matrix4f modelViewMatrix,
Matrix4f projectionMatrix,
DeltaTracker deltaTracker,
ProfilerFiller profiler) {
this.builder = builder;
this.targets = targets;
this.frustum = frustum;
this.camera = camera;
this.modelViewMatrix = modelViewMatrix;
this.projectionMatrix = projectionMatrix;
this.deltaTracker = deltaTracker;
this.profiler = profiler;
}

/**
* {@return the {@link FrameGraphBuilder} used to set up the frame graph}
*/
public FrameGraphBuilder getFrameGrapBuilder() {
return builder;
}

/**
* {@return the render targets used during level rendering}
*/
public LevelTargetBundle getTargetBundle() {
return targets;
}

/**
* {@return the culling frustum}
*/
public Frustum getFrustum() {
return frustum;
}

/**
* {@return the active {@link Camera}}
*/
public Camera getCamera() {
return camera;
}

/**
* {@return the model view matrix}
*/
public Matrix4f getModelViewMatrix() {
return modelViewMatrix;
}

/**
* {@return the projection matrix}
*/
public Matrix4f getProjectionMatrix() {
return projectionMatrix;
}

/**
* {@return the {@link DeltaTracker}}
*/
public DeltaTracker getDeltaTracker() {
return deltaTracker;
}

/**
* {@return the active {@linkplain ProfilerFiller profiler}}
*/
public ProfilerFiller getProfiler() {
return profiler;
}

/**
* Fired at the start of frame graph setup, right after the "clear" pass is added
*/
public static final class Pre extends FrameGraphSetupEvent {
private boolean enableOutline;

@ApiStatus.Internal
public Pre(
FrameGraphBuilder builder,
LevelTargetBundle targets,
Frustum frustum,
Camera camera,
Matrix4f modelViewMatrix,
Matrix4f projectionMatrix,
DeltaTracker deltaTracker,
ProfilerFiller profiler) {
super(builder, targets, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler);
}

/**
* Enables the entity outline post-processing shader regardless of any entities having active outlines
*/
public void enableOutlineProcessing() {
this.enableOutline = true;
}

/**
* {@return whether the entity outline post-processing shader will be enabled regardless of entities using it}
*/
public boolean isOutlineProcessingEnabled() {
return enableOutline;
}
}

/**
* Fired at the end of frame graph setup, right before the frame graph is executed
*/
public static final class Post extends FrameGraphSetupEvent {
@ApiStatus.Internal
public Post(
FrameGraphBuilder builder,
LevelTargetBundle targets,
Frustum frustum,
Camera camera,
Matrix4f modelViewMatrix,
Matrix4f projectionMatrix,
DeltaTracker deltaTracker,
ProfilerFiller profiler) {
super(builder, targets, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler);
}
}
}

0 comments on commit 4b13bc4

Please sign in to comment.