Skip to content

Commit

Permalink
Flatten into single event and add full-screen target descriptor as ad…
Browse files Browse the repository at this point in the history
…ditional context
  • Loading branch information
XFactHD committed Nov 20, 2024
1 parent 805b50d commit 8a902da
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 68 deletions.
23 changes: 12 additions & 11 deletions patches/net/minecraft/client/renderer/LevelRenderer.java.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
--- a/net/minecraft/client/renderer/LevelRenderer.java
+++ b/net/minecraft/client/renderer/LevelRenderer.java
@@ -484,8 +_,10 @@
RenderSystem.clearColor(vector4f.x, vector4f.y, vector4f.z, 0.0F);
@@ -478,6 +_,9 @@
this.targets.entityOutline = framegraphbuilder.importExternal("entity_outline", this.entityOutlineTarget);
}

+ var setupEvent = net.neoforged.neoforge.client.ClientHooks.fireFrameGraphSetup(framegraphbuilder, this.targets, rendertargetdescriptor, frustum, p_109604_, p_254120_, p_323920_, p_348530_, profilerfiller);
+ flag2 |= setupEvent.isOutlineProcessingEnabled();
+
FramePass framepass = framegraphbuilder.addPass("clear");
this.targets.main = framepass.readsAndWrites(this.targets.main);
framepass.executes(() -> {
@@ -485,7 +_,7 @@
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 @@ -21,7 +28,7 @@
CloudStatus cloudstatus = this.minecraft.options.getCloudsType();
if (cloudstatus != CloudStatus.OFF) {
float f2 = this.level.effects().getCloudHeight();
@@ -505,12 +_,13 @@
@@ -505,7 +_,7 @@
}
}

Expand All @@ -30,12 +37,6 @@
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
10 changes: 3 additions & 7 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.resource.RenderTargetDescriptor;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
Expand Down Expand Up @@ -1111,12 +1112,7 @@ public static Map<ResourceLocation, ResourceLocation> gatherMaterialAtlases(Map<
}

@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));
public static FrameGraphSetupEvent fireFrameGraphSetup(FrameGraphBuilder builder, LevelTargetBundle targets, RenderTargetDescriptor renderTargetDescriptor, Frustum frustum, Camera camera, Matrix4f modelViewMatrix, Matrix4f projectionMatrix, DeltaTracker deltaTracker, ProfilerFiller profiler) {
return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent(builder, targets, renderTargetDescriptor, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.neoforged.neoforge.client.event;

import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
import com.mojang.blaze3d.resource.RenderTargetDescriptor;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.renderer.LevelTargetBundle;
Expand All @@ -19,26 +20,31 @@
import org.joml.Matrix4f;

/**
* Fired when the {@linkplain FrameGraphBuilder frame graph} is set up at the start of level rendering.
* Fired when the {@linkplain FrameGraphBuilder frame graph} is set up at the start of level rendering, right before
* the vanilla frame passes are set up.
* <p>
* These events are not {@linkplain ICancellableEvent cancellable}.
* This event is not {@linkplain ICancellableEvent cancellable}.
* <p>
* These events are fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus},
* This event is 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;
public final class FrameGraphSetupEvent extends Event {
private final FrameGraphBuilder builder;
private final LevelTargetBundle targets;
private final RenderTargetDescriptor renderTargetDescriptor;
private final Frustum frustum;
private final Camera camera;
private final Matrix4f modelViewMatrix;
private final Matrix4f projectionMatrix;
private final DeltaTracker deltaTracker;
private final ProfilerFiller profiler;
private boolean enableOutline;

protected FrameGraphSetupEvent(
@ApiStatus.Internal
public FrameGraphSetupEvent(
FrameGraphBuilder builder,
LevelTargetBundle targets,
RenderTargetDescriptor renderTargetDescriptor,
Frustum frustum,
Camera camera,
Matrix4f modelViewMatrix,
Expand All @@ -47,6 +53,7 @@ protected FrameGraphSetupEvent(
ProfilerFiller profiler) {
this.builder = builder;
this.targets = targets;
this.renderTargetDescriptor = renderTargetDescriptor;
this.frustum = frustum;
this.camera = camera;
this.modelViewMatrix = modelViewMatrix;
Expand All @@ -69,6 +76,13 @@ public LevelTargetBundle getTargetBundle() {
return targets;
}

/**
* {@return the render target descriptor to use for creating full-screen render targets}
*/
public RenderTargetDescriptor getRenderTargetDescriptor() {
return renderTargetDescriptor;
}

/**
* {@return the culling frustum}
*/
Expand Down Expand Up @@ -112,54 +126,16 @@ public ProfilerFiller getProfiler() {
}

/**
* Fired at the start of frame graph setup, right after the "clear" pass is added
* Enables the entity outline post-processing shader regardless of any entities having active outlines
*/
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;
}
public void enableOutlineProcessing() {
this.enableOutline = true;
}

/**
* Fired at the end of frame graph setup, right before the frame graph is executed
* {@return whether the entity outline post-processing shader will be enabled regardless of entities using it}
*/
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);
}
public boolean isOutlineProcessingEnabled() {
return enableOutline;
}
}

0 comments on commit 8a902da

Please sign in to comment.