Skip to content

Commit b71b520

Browse files
authored
[1.21.4] Add event fired at the start of the framegraph setup (#1598)
1 parent cbbb26f commit b71b520

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

patches/net/minecraft/client/renderer/LevelRenderer.java.patch

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
--- a/net/minecraft/client/renderer/LevelRenderer.java
22
+++ b/net/minecraft/client/renderer/LevelRenderer.java
3+
@@ -473,6 +_,9 @@
4+
this.targets.entityOutline = framegraphbuilder.importExternal("entity_outline", this.entityOutlineTarget);
5+
}
6+
7+
+ var setupEvent = net.neoforged.neoforge.client.ClientHooks.fireFrameGraphSetup(framegraphbuilder, this.targets, rendertargetdescriptor, frustum, p_109604_, p_254120_, p_323920_, p_348530_, profilerfiller);
8+
+ flag2 |= setupEvent.isOutlineProcessingEnabled();
9+
+
10+
FramePass framepass = framegraphbuilder.addPass("clear");
11+
this.targets.main = framepass.readsAndWrites(this.targets.main);
12+
framepass.executes(() -> {
313
@@ -480,7 +_,7 @@
414
RenderSystem.clear(16640);
515
});

src/main/java/net/neoforged/neoforge/client/ClientHooks.java

+10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import com.google.common.collect.BiMap;
99
import com.google.common.collect.HashBiMap;
1010
import com.google.common.collect.ImmutableMap;
11+
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
1112
import com.mojang.blaze3d.platform.NativeImage;
1213
import com.mojang.blaze3d.platform.Window;
14+
import com.mojang.blaze3d.resource.RenderTargetDescriptor;
1315
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
1416
import com.mojang.blaze3d.vertex.PoseStack;
1517
import com.mojang.blaze3d.vertex.VertexConsumer;
@@ -64,6 +66,7 @@
6466
import net.minecraft.client.renderer.FogRenderer;
6567
import net.minecraft.client.renderer.GameRenderer;
6668
import net.minecraft.client.renderer.LevelRenderer;
69+
import net.minecraft.client.renderer.LevelTargetBundle;
6770
import net.minecraft.client.renderer.MultiBufferSource;
6871
import net.minecraft.client.renderer.RenderType;
6972
import net.minecraft.client.renderer.ShaderDefines;
@@ -105,6 +108,7 @@
105108
import net.minecraft.util.Mth;
106109
import net.minecraft.util.RandomSource;
107110
import net.minecraft.util.profiling.Profiler;
111+
import net.minecraft.util.profiling.ProfilerFiller;
108112
import net.minecraft.world.InteractionHand;
109113
import net.minecraft.world.effect.MobEffectInstance;
110114
import net.minecraft.world.entity.Entity;
@@ -142,6 +146,7 @@
142146
import net.neoforged.neoforge.client.event.ComputeFovModifierEvent;
143147
import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent;
144148
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
149+
import net.neoforged.neoforge.client.event.FrameGraphSetupEvent;
145150
import net.neoforged.neoforge.client.event.GatherEffectScreenTooltipsEvent;
146151
import net.neoforged.neoforge.client.event.InputEvent;
147152
import net.neoforged.neoforge.client.event.ModelEvent;
@@ -1089,4 +1094,9 @@ public static Map<ResourceLocation, ResourceLocation> gatherMaterialAtlases(Map<
10891094
ModLoader.postEvent(new RegisterMaterialAtlasesEvent(vanillaAtlases));
10901095
return Map.copyOf(vanillaAtlases);
10911096
}
1097+
1098+
@ApiStatus.Internal
1099+
public static FrameGraphSetupEvent fireFrameGraphSetup(FrameGraphBuilder builder, LevelTargetBundle targets, RenderTargetDescriptor renderTargetDescriptor, Frustum frustum, Camera camera, Matrix4f modelViewMatrix, Matrix4f projectionMatrix, DeltaTracker deltaTracker, ProfilerFiller profiler) {
1100+
return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent(builder, targets, renderTargetDescriptor, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler));
1101+
}
10921102
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (c) NeoForged and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
package net.neoforged.neoforge.client.event;
7+
8+
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
9+
import com.mojang.blaze3d.resource.RenderTargetDescriptor;
10+
import net.minecraft.client.Camera;
11+
import net.minecraft.client.DeltaTracker;
12+
import net.minecraft.client.renderer.LevelTargetBundle;
13+
import net.minecraft.client.renderer.culling.Frustum;
14+
import net.minecraft.util.profiling.ProfilerFiller;
15+
import net.neoforged.bus.api.Event;
16+
import net.neoforged.bus.api.ICancellableEvent;
17+
import net.neoforged.fml.LogicalSide;
18+
import net.neoforged.neoforge.common.NeoForge;
19+
import org.jetbrains.annotations.ApiStatus;
20+
import org.joml.Matrix4f;
21+
22+
/**
23+
* Fired when the {@linkplain FrameGraphBuilder frame graph} is set up at the start of level rendering, right before
24+
* the vanilla frame passes are set up.
25+
* <p>
26+
* This event is not {@linkplain ICancellableEvent cancellable}.
27+
* <p>
28+
* This event is fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus},
29+
* only on the {@linkplain LogicalSide#CLIENT logical client}.
30+
*/
31+
public final class FrameGraphSetupEvent extends Event {
32+
private final FrameGraphBuilder builder;
33+
private final LevelTargetBundle targets;
34+
private final RenderTargetDescriptor renderTargetDescriptor;
35+
private final Frustum frustum;
36+
private final Camera camera;
37+
private final Matrix4f modelViewMatrix;
38+
private final Matrix4f projectionMatrix;
39+
private final DeltaTracker deltaTracker;
40+
private final ProfilerFiller profiler;
41+
private boolean enableOutline;
42+
43+
@ApiStatus.Internal
44+
public FrameGraphSetupEvent(
45+
FrameGraphBuilder builder,
46+
LevelTargetBundle targets,
47+
RenderTargetDescriptor renderTargetDescriptor,
48+
Frustum frustum,
49+
Camera camera,
50+
Matrix4f modelViewMatrix,
51+
Matrix4f projectionMatrix,
52+
DeltaTracker deltaTracker,
53+
ProfilerFiller profiler) {
54+
this.builder = builder;
55+
this.targets = targets;
56+
this.renderTargetDescriptor = renderTargetDescriptor;
57+
this.frustum = frustum;
58+
this.camera = camera;
59+
this.modelViewMatrix = modelViewMatrix;
60+
this.projectionMatrix = projectionMatrix;
61+
this.deltaTracker = deltaTracker;
62+
this.profiler = profiler;
63+
}
64+
65+
/**
66+
* {@return the {@link FrameGraphBuilder} used to set up the frame graph}
67+
*/
68+
public FrameGraphBuilder getFrameGrapBuilder() {
69+
return builder;
70+
}
71+
72+
/**
73+
* {@return the render targets used during level rendering}
74+
*/
75+
public LevelTargetBundle getTargetBundle() {
76+
return targets;
77+
}
78+
79+
/**
80+
* {@return the render target descriptor to use for creating full-screen render targets}
81+
*/
82+
public RenderTargetDescriptor getRenderTargetDescriptor() {
83+
return renderTargetDescriptor;
84+
}
85+
86+
/**
87+
* {@return the culling frustum}
88+
*/
89+
public Frustum getFrustum() {
90+
return frustum;
91+
}
92+
93+
/**
94+
* {@return the active {@link Camera}}
95+
*/
96+
public Camera getCamera() {
97+
return camera;
98+
}
99+
100+
/**
101+
* {@return the model view matrix}
102+
*/
103+
public Matrix4f getModelViewMatrix() {
104+
return modelViewMatrix;
105+
}
106+
107+
/**
108+
* {@return the projection matrix}
109+
*/
110+
public Matrix4f getProjectionMatrix() {
111+
return projectionMatrix;
112+
}
113+
114+
/**
115+
* {@return the {@link DeltaTracker}}
116+
*/
117+
public DeltaTracker getDeltaTracker() {
118+
return deltaTracker;
119+
}
120+
121+
/**
122+
* {@return the active {@linkplain ProfilerFiller profiler}}
123+
*/
124+
public ProfilerFiller getProfiler() {
125+
return profiler;
126+
}
127+
128+
/**
129+
* Enables the entity outline post-processing shader regardless of any entities having active outlines
130+
*/
131+
public void enableOutlineProcessing() {
132+
this.enableOutline = true;
133+
}
134+
135+
/**
136+
* {@return whether the entity outline post-processing shader will be enabled regardless of entities using it}
137+
*/
138+
public boolean isOutlineProcessingEnabled() {
139+
return enableOutline;
140+
}
141+
}

0 commit comments

Comments
 (0)