From 8a902daa9bd0ff24807698f34604579c7fa3c63e Mon Sep 17 00:00:00 2001 From: XFactHD Date: Wed, 20 Nov 2024 01:29:49 +0100 Subject: [PATCH] Flatten into single event and add full-screen target descriptor as additional context --- .../client/renderer/LevelRenderer.java.patch | 23 +++--- .../neoforge/client/ClientHooks.java | 10 +-- .../client/event/FrameGraphSetupEvent.java | 76 +++++++------------ 3 files changed, 41 insertions(+), 68 deletions(-) diff --git a/patches/net/minecraft/client/renderer/LevelRenderer.java.patch b/patches/net/minecraft/client/renderer/LevelRenderer.java.patch index b6491fddd1a..e791577c8e2 100644 --- a/patches/net/minecraft/client/renderer/LevelRenderer.java.patch +++ b/patches/net/minecraft/client/renderer/LevelRenderer.java.patch @@ -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_); @@ -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 @@ } } @@ -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"); diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java index 03b0538c44f..c1f2b8d79e0 100644 --- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java +++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java @@ -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; @@ -1111,12 +1112,7 @@ public static Map 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)); } } diff --git a/src/main/java/net/neoforged/neoforge/client/event/FrameGraphSetupEvent.java b/src/main/java/net/neoforged/neoforge/client/event/FrameGraphSetupEvent.java index f02020f96b5..2a410c7bd7d 100644 --- a/src/main/java/net/neoforged/neoforge/client/event/FrameGraphSetupEvent.java +++ b/src/main/java/net/neoforged/neoforge/client/event/FrameGraphSetupEvent.java @@ -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; @@ -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. *

- * These events are not {@linkplain ICancellableEvent cancellable}. + * This event is not {@linkplain ICancellableEvent cancellable}. *

- * 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, @@ -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; @@ -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} */ @@ -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; } }