-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more accurate culling for single quad particles (#885)
- Loading branch information
Showing
10 changed files
with
126 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
patches/net/minecraft/client/particle/SingleQuadParticle.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- a/net/minecraft/client/particle/SingleQuadParticle.java | ||
+++ b/net/minecraft/client/particle/SingleQuadParticle.java | ||
@@ -81,6 +_,12 @@ | ||
.endVertex(); | ||
} | ||
|
||
+ @Override | ||
+ public net.minecraft.world.phys.AABB getRenderBoundingBox(float partialTicks) { | ||
+ float size = getQuadSize(partialTicks); | ||
+ return new net.minecraft.world.phys.AABB(this.x - size, this.y - size, this.z - size, this.x + size, this.y + size, this.z + size); | ||
+ } | ||
+ | ||
public float getQuadSize(float p_107681_) { | ||
return this.quadSize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- a/net/minecraft/world/phys/AABB.java | ||
+++ b/net/minecraft/world/phys/AABB.java | ||
@@ -9,6 +_,7 @@ | ||
|
||
public class AABB { | ||
private static final double EPSILON = 1.0E-7; | ||
+ public static final AABB INFINITE = new AABB(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); | ||
public final double minX; | ||
public final double minY; | ||
public final double minZ; | ||
@@ -511,5 +_,13 @@ | ||
p_165883_.y + p_165885_ / 2.0, | ||
p_165883_.z + p_165886_ / 2.0 | ||
); | ||
+ } | ||
+ | ||
+ /** | ||
+ * {@return true if this AABB is infinite in all directions} | ||
+ */ | ||
+ public boolean isInfinite() { | ||
+ return this == INFINITE || (Double.isInfinite(this.minX) && Double.isInfinite(this.minY) && Double.isInfinite(this.minZ) | ||
+ && Double.isInfinite(this.maxX) && Double.isInfinite(this.maxY) && Double.isInfinite(this.maxZ)); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/net/neoforged/neoforge/client/ParticleBoundsDebugRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.BoolArgumentType; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.LevelRenderer; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.commands.Commands; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent; | ||
import net.neoforged.neoforge.client.event.RenderLevelStageEvent; | ||
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; | ||
|
||
@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.GAME, modid = NeoForgeVersion.MOD_ID) | ||
public final class ParticleBoundsDebugRenderer { | ||
private static boolean enabled = false; | ||
|
||
@SubscribeEvent | ||
public static void onRenderLevelStage(RenderLevelStageEvent event) { | ||
if (!enabled || event.getStage() != RenderLevelStageEvent.Stage.AFTER_PARTICLES) { | ||
return; | ||
} | ||
|
||
var camPos = event.getCamera().getPosition(); | ||
|
||
PoseStack poseStack = event.getPoseStack(); | ||
poseStack.pushPose(); | ||
poseStack.translate(-camPos.x, -camPos.y, -camPos.z); | ||
|
||
VertexConsumer consumer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(RenderType.lines()); | ||
|
||
Minecraft.getInstance().particleEngine.iterateParticles(particle -> { | ||
var bb = particle.getRenderBoundingBox(event.getPartialTick()); | ||
if (!bb.isInfinite() && event.getFrustum().isVisible(bb)) { | ||
LevelRenderer.renderLineBox(poseStack, consumer, bb, 1F, 0F, 0F, 1F); | ||
} | ||
}); | ||
|
||
poseStack.popPose(); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onRegisterClientCommands(RegisterClientCommandsEvent event) { | ||
event.getDispatcher().register( | ||
Commands.literal("neoforge") | ||
.then(Commands.literal("debug_particle_renderbounds") | ||
.requires(src -> src.hasPermission(Commands.LEVEL_ADMINS)) | ||
.then(Commands.argument("enable", BoolArgumentType.bool()) | ||
.executes(ctx -> { | ||
enabled = BoolArgumentType.getBool(ctx, "enable"); | ||
return Command.SINGLE_SUCCESS; | ||
})))); | ||
} | ||
|
||
private ParticleBoundsDebugRenderer() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters