Skip to content

Commit

Permalink
[1.21.4] Add event fired at the start of the framegraph setup (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Dec 21, 2024
1 parent cbbb26f commit b71b520
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
10 changes: 10 additions & 0 deletions patches/net/minecraft/client/renderer/LevelRenderer.java.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
--- a/net/minecraft/client/renderer/LevelRenderer.java
+++ b/net/minecraft/client/renderer/LevelRenderer.java
@@ -473,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(() -> {
@@ -480,7 +_,7 @@
RenderSystem.clear(16640);
});
Expand Down
10 changes: 10 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,8 +8,10 @@
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.resource.RenderTargetDescriptor;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
Expand Down Expand Up @@ -64,6 +66,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 @@ -105,6 +108,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 @@ -142,6 +146,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 @@ -1089,4 +1094,9 @@ public static Map<ResourceLocation, ResourceLocation> gatherMaterialAtlases(Map<
ModLoader.postEvent(new RegisterMaterialAtlasesEvent(vanillaAtlases));
return Map.copyOf(vanillaAtlases);
}

@ApiStatus.Internal
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
@@ -0,0 +1,141 @@
/*
* 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 com.mojang.blaze3d.resource.RenderTargetDescriptor;
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, right before
* the vanilla frame passes are set up.
* <p>
* This event is not {@linkplain ICancellableEvent cancellable}.
* <p>
* This event is fired on the {@linkplain NeoForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.
*/
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;

@ApiStatus.Internal
public FrameGraphSetupEvent(
FrameGraphBuilder builder,
LevelTargetBundle targets,
RenderTargetDescriptor renderTargetDescriptor,
Frustum frustum,
Camera camera,
Matrix4f modelViewMatrix,
Matrix4f projectionMatrix,
DeltaTracker deltaTracker,
ProfilerFiller profiler) {
this.builder = builder;
this.targets = targets;
this.renderTargetDescriptor = renderTargetDescriptor;
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 render target descriptor to use for creating full-screen render targets}
*/
public RenderTargetDescriptor getRenderTargetDescriptor() {
return renderTargetDescriptor;
}

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

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

0 comments on commit b71b520

Please sign in to comment.