ChunkCullingDebugRenderer .java

net.minecraft.client.renderer.debug.ChunkCullingDebugRenderer (class, 128 lines): members: DIRECTIONS, frustum, emitGizmos, minecraft. imports: Vector4f.

net.minecraft.client.renderer.debugclass128 linesclient5.7 KB

Implements

API Surface (1)

void emitGizmos(final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks)

Fields & Constants (4)

DIRECTIONS
minecraft
frustum
g

Full Source

ChunkCullingDebugRenderer.java128 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.debug;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.Minecraft;
6
import net.minecraft.client.gui.components.debug.DebugScreenEntries;
7
import net.minecraft.client.renderer.LevelRenderer;
8
import net.minecraft.client.renderer.SectionOcclusionGraph;
9
import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
10
import net.minecraft.client.renderer.culling.Frustum;
11
import net.minecraft.core.BlockPos;
12
import net.minecraft.core.Direction;
13
import net.minecraft.gizmos.GizmoStyle;
14
import net.minecraft.gizmos.Gizmos;
15
import net.minecraft.util.ARGB;
16
import net.minecraft.util.Mth;
17
import net.minecraft.util.debug.DebugValueAccess;
18
import net.minecraft.world.phys.Vec3;
19
import org.joml.Vector4f;
20
21
@Environment(EnvType.CLIENT)
22
public class ChunkCullingDebugRenderer implements DebugRenderer.SimpleDebugRenderer {
23
	public static final Direction[] DIRECTIONS = Direction.values();
24
	private final Minecraft minecraft;
25
26
	public ChunkCullingDebugRenderer(final Minecraft minecraft) {
27
		this.minecraft = minecraft;
28
	}
29
30
	@Override
31
	public void emitGizmos(
32
		final double camX, final double camY, final double camZ, final DebugValueAccess debugValues, final Frustum frustum, final float partialTicks
33
	) {
34
		LevelRenderer levelRenderer = this.minecraft.levelRenderer;
35
		boolean sectionPath = this.minecraft.debugEntries.isCurrentlyEnabled(DebugScreenEntries.CHUNK_SECTION_PATHS);
36
		boolean sectionVisibility = this.minecraft.debugEntries.isCurrentlyEnabled(DebugScreenEntries.CHUNK_SECTION_VISIBILITY);
37
		if (sectionPath || sectionVisibility) {
38
			SectionOcclusionGraph sectionOcclusionGraph = levelRenderer.sectionOcclusionGraph();
39
40
			for (SectionRenderDispatcher.RenderSection section : levelRenderer.visibleSections()) {
41
				SectionOcclusionGraph.Node node = sectionOcclusionGraph.getNode(section);
42
				if (node != null) {
43
					BlockPos renderOffset = section.getRenderOrigin();
44
					if (sectionPath) {
45
						int color = node.step == 0 ? 0 : Mth.hsvToRgb(node.step / 50.0F, 0.9F, 0.9F);
46
47
						for (int i = 0; i < DIRECTIONS.length; i++) {
48
							if (node.hasSourceDirection(i)) {
49
								Direction direction = DIRECTIONS[i];
50
								Gizmos.line(
51
									Vec3.atLowerCornerWithOffset(renderOffset, 8.0, 8.0, 8.0),
52
									Vec3.atLowerCornerWithOffset(renderOffset, 8 - 16 * direction.getStepX(), 8 - 16 * direction.getStepY(), 8 - 16 * direction.getStepZ()),
53
									ARGB.opaque(color)
54
								);
55
							}
56
						}
57
					}
58
59
					if (sectionVisibility && section.getSectionMesh().hasRenderableLayers()) {
60
						int c = 0;
61
62
						for (Direction direction1 : DIRECTIONS) {
63
							for (Direction direction2 : DIRECTIONS) {
64
								boolean b = section.getSectionMesh().facesCanSeeEachother(direction1, direction2);
65
								if (!b) {
66
									c++;
67
									Gizmos.line(
68
										Vec3.atLowerCornerWithOffset(renderOffset, 8 + 8 * direction1.getStepX(), 8 + 8 * direction1.getStepY(), 8 + 8 * direction1.getStepZ()),
69
										Vec3.atLowerCornerWithOffset(renderOffset, 8 + 8 * direction2.getStepX(), 8 + 8 * direction2.getStepY(), 8 + 8 * direction2.getStepZ()),
70
										ARGB.color(255, 255, 0, 0)
71
									);
72
								}
73
							}
74
						}
75
76
						if (c > 0) {
77
							float delta = 0.5F;
78
							float a = 0.2F;
79
							Gizmos.cuboid(section.getBoundingBox().deflate(0.5), GizmoStyle.fill(ARGB.colorFromFloat(0.2F, 0.9F, 0.9F, 0.0F)));
80
						}
81
					}
82
				}
83
			}
84
		}
85
86
		Frustum capturedFrustum = this.minecraft.gameRenderer.mainCamera().getCapturedFrustum();
87
		if (capturedFrustum != null) {
88
			Vec3 offset = new Vec3(capturedFrustum.getCamX(), capturedFrustum.getCamY(), capturedFrustum.getCamZ());
89
			Vector4f[] frustumPoints = capturedFrustum.getFrustumPoints();
90
			this.addFrustumQuad(offset, frustumPoints, 0, 1, 2, 3, 0, 1, 1);
91
			this.addFrustumQuad(offset, frustumPoints, 4, 5, 6, 7, 1, 0, 0);
92
			this.addFrustumQuad(offset, frustumPoints, 0, 1, 5, 4, 1, 1, 0);
93
			this.addFrustumQuad(offset, frustumPoints, 2, 3, 7, 6, 0, 0, 1);
94
			this.addFrustumQuad(offset, frustumPoints, 0, 4, 7, 3, 0, 1, 0);
95
			this.addFrustumQuad(offset, frustumPoints, 1, 5, 6, 2, 1, 0, 1);
96
			this.addFrustumLine(offset, frustumPoints[0], frustumPoints[1]);
97
			this.addFrustumLine(offset, frustumPoints[1], frustumPoints[2]);
98
			this.addFrustumLine(offset, frustumPoints[2], frustumPoints[3]);
99
			this.addFrustumLine(offset, frustumPoints[3], frustumPoints[0]);
100
			this.addFrustumLine(offset, frustumPoints[4], frustumPoints[5]);
101
			this.addFrustumLine(offset, frustumPoints[5], frustumPoints[6]);
102
			this.addFrustumLine(offset, frustumPoints[6], frustumPoints[7]);
103
			this.addFrustumLine(offset, frustumPoints[7], frustumPoints[4]);
104
			this.addFrustumLine(offset, frustumPoints[0], frustumPoints[4]);
105
			this.addFrustumLine(offset, frustumPoints[1], frustumPoints[5]);
106
			this.addFrustumLine(offset, frustumPoints[2], frustumPoints[6]);
107
			this.addFrustumLine(offset, frustumPoints[3], frustumPoints[7]);
108
		}
109
	}
110
111
	private void addFrustumLine(final Vec3 offset, final Vector4f a, final Vector4f b) {
112
		Gizmos.line(new Vec3(offset.x + a.x, offset.y + a.y, offset.z + a.z), new Vec3(offset.x + b.x, offset.y + b.y, offset.z + b.z), -16777216);
113
	}
114
115
	private void addFrustumQuad(
116
		final Vec3 offset, final Vector4f[] frustumPoints, final int i0, final int i1, final int i2, final int i3, final int r, final int g, final int b
117
	) {
118
		float a = 0.25F;
119
		Gizmos.rect(
120
			new Vec3(frustumPoints[i0].x(), frustumPoints[i0].y(), frustumPoints[i0].z()).add(offset),
121
			new Vec3(frustumPoints[i1].x(), frustumPoints[i1].y(), frustumPoints[i1].z()).add(offset),
122
			new Vec3(frustumPoints[i2].x(), frustumPoints[i2].y(), frustumPoints[i2].z()).add(offset),
123
			new Vec3(frustumPoints[i3].x(), frustumPoints[i3].y(), frustumPoints[i3].z()).add(offset),
124
			GizmoStyle.fill(ARGB.colorFromFloat(0.25F, r, g, b))
125
		);
126
	}
127
}
128

Decompiled Minecraft 26.3 source of ChunkCullingDebugRenderer (net/minecraft/client/renderer/debug/ChunkCullingDebugRenderer.java) with Mojang official mappings, stored verbatim on the site.