Update to Celeritas 2.5.12 with translucency sorting v3 (#2151)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2026-09-27 09:37:40 -07:00
1 parent a8c29fa3f9
commit c9d46e70e0
50 files changed
+870 -556

No files matched your search

@@ -66,12 +66,6 @@ public class IrisCeleritasShaderProvider implements IrisShaderProvider {
return BlockRenderingSettings.INSTANCE.getBlockTypeIds();
}
@Override
public void preSubmitShadowGraph(int frame) {
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
if (pipeline != null) pipeline.preSubmitShadowGraph(frame);
}
public void deleteShaders() {
overrides.deleteShaders();
}
@@ -1958,11 +1958,6 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
isRenderingFullScreenPass = false;
}
@Override
public void preSubmitShadowGraph(int frame) {
if (shadowRenderer != null) shadowRenderer.preSubmitGraphUpdate(frame);
}
@Override
public void renderShadows(EntityRenderer levelRenderer, Camera playerCamera) {
if (shouldRenderPrepareBeforeShadow) {
@@ -81,6 +81,7 @@ public class ShadowRenderer {
private static final Tracy.ZoneId Z_SHADOW_FRUSTUM = Tracy.zoneId("shadowFrustum", Tracy.COLOR_IRIS);
private static final Tracy.ZoneId Z_SHADOW_VIEWPORT = Tracy.zoneId("shadowViewport", Tracy.COLOR_IRIS);
private static final Tracy.ZoneId Z_SHADOW_MODEL_PARTS = Tracy.zoneId("shadowModelParts", Tracy.COLOR_IRIS);
private static final Tracy.ZoneId Z_SHADOW_GRAPH_JOIN = Tracy.zoneId("shadowGraphJoin", Tracy.COLOR_IRIS);
public static final Matrix4f MODELVIEW = new Matrix4f();
public static final FloatBuffer MODELVIEW_BUFFER = BufferUtils.createFloatBuffer(16);
@@ -114,6 +115,7 @@ public class ShadowRenderer {
private final boolean shouldRenderEntities;
private final boolean shouldRenderPlayer;
private final boolean shouldRenderBlockEntities;
private final boolean shouldRenderLightBlockEntities;
private final float sunPathRotation;
private final List<MipmapPass> mipmapPasses = new ArrayList<>();
private final String debugStringOverall;
@@ -171,10 +173,9 @@ public class ShadowRenderer {
private final FrustumCaches entityFrustumCaches = new FrustumCaches();
private float lastGraphShadowAngle = Float.NaN;
private float relayShadowAngle = Float.NaN;
private FrustumHolder preSubmitFrustumHolder = new FrustumHolder("preSubmit");
private final FrustumCaches preSubmitFrustumCaches = new FrustumCaches();
private boolean preSubmitActive;
private float preSubmittedShadowAngle = Float.NaN;
/** A shadow search was submitted by the last shadow pass; with async occlusion its lists are published by this pass's join. */
private boolean shadowSearchPending;
private float searchedShadowAngle = Float.NaN;
private float shadowAngleDelta() {
final Vector4f light = celestialUniforms.getShadowLightPositionInWorldSpace();
@@ -185,25 +186,6 @@ public class ShadowRenderer {
AngelicaConfig.shadowGraphHorizonScale);
}
public void preSubmitGraphUpdate(int frame) {
final AngelicaRenderSectionManager rsm = CeleritasWorldRenderer.getInstance().getRenderSectionManager();
final float currentShadowAngle = getShadowAngle();
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle, shadowAngleDelta())) {
rsm.markShadowGraphDirty();
lastGraphShadowAngle = currentShadowAngle;
}
if (!rsm.canSubmitShadowGraphSearch()) return;
preSubmitFrustumHolder = createShadowFrustum(renderDistanceMultiplier, preSubmitFrustumHolder, preSubmitFrustumCaches);
if (!(preSubmitFrustumHolder.getFrustum() instanceof ViewportProvider provider)) return;
final Vector3d entityPos = Camera.INSTANCE.getEntityPos();
preSubmitFrustumHolder.getFrustum().setPosition(entityPos.x, entityPos.y, entityPos.z);
if (rsm.submitShadowGraphSearch(provider.sodium$createViewport(), frame)) {
preSubmittedShadowAngle = lastGraphShadowAngle;
preSubmitActive = true;
}
}
private long lastRelayNanos;
private final Vector3f shadowLightVectorCache = new Vector3f();
private final MemoizedBoxCuller tileEntityCuller = new MemoizedBoxCuller();
@@ -232,6 +214,7 @@ public class ShadowRenderer {
this.shouldRenderEntities = shadowDirectives.shouldRenderEntities();
this.shouldRenderPlayer = shadowDirectives.shouldRenderPlayer();
this.shouldRenderBlockEntities = shadowDirectives.shouldRenderBlockEntities();
this.shouldRenderLightBlockEntities = shadowDirectives.shouldRenderLightBlockEntities();
this.shouldRenderDH = shadowDirectives.isDhShadowEnabled().orElse(false);
this.packUsesShadowtex1 = packUsesShadowtex1;
@@ -797,7 +780,11 @@ public class ShadowRenderer {
);
}
private void renderTileEntities(Object bufferSource, MatrixStack modelView, double cameraX, double cameraY, double cameraZ, float partialTicks, boolean hasEntityFrustum) {
private static boolean emitsLight(TileEntity tile) {
return tile.getBlockType().getLightValue(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord) > 0;
}
private void renderTileEntities(Object bufferSource, MatrixStack modelView, double cameraX, double cameraY, double cameraZ, float partialTicks, boolean hasEntityFrustum, boolean lightsOnly) {
profiler.startSection("iris_shadow_build_blockentities");
int shadowTileEntities = 0;
@@ -826,6 +813,9 @@ public class ShadowRenderer {
if (hasEntityFrustum && (culler.isCulled(tileEntity.xCoord - 1, tileEntity.yCoord - 1, tileEntity.zCoord - 1, tileEntity.xCoord + 1, tileEntity.yCoord + 1, tileEntity.zCoord + 1))) {
continue;
}
if (lightsOnly && !emitsLight(tileEntity)) {
continue;
}
renderTileEntity(tileEntity, cameraX, cameraY, cameraZ, partialTicks);
shadowTileEntities++;
@@ -838,6 +828,9 @@ public class ShadowRenderer {
if (hasEntityFrustum && (culler.isCulled(tileEntity.xCoord - 1, tileEntity.yCoord - 1, tileEntity.zCoord - 1, tileEntity.xCoord + 1, tileEntity.yCoord + 1, tileEntity.zCoord + 1))) {
continue;
}
if (lightsOnly && !emitsLight(tileEntity)) {
continue;
}
renderTileEntity(tileEntity, cameraX, cameraY, cameraZ, partialTicks);
shadowTileEntities++;
@@ -864,8 +857,20 @@ public class ShadowRenderer {
this.profiler = Minecraft.getMinecraft().mcProfiler;
profiler.endStartSection("iris_shadows");
final AngelicaRenderSectionManager rsm = CeleritasWorldRenderer.getInstance().getRenderSectionManager();
// The in-flight shadow search reads terrainFrustumHolder's frustum, which createShadowFrustum re-inits below.
if (Tracy.ENABLED) Tracy.beginZone(Z_SHADOW_GRAPH_JOIN);
try {
rsm.finishAllGraphUpdates();
} finally {
if (Tracy.ENABLED) Tracy.endZone();
}
ACTIVE = true;
CURRENT_TARGETS = this.targets;
// ACTIVE routes clipRenderersByFrustum into the shadow path; a leak would send every main pass there.
try {
// NB: We store the previous player buffers in order to be able to allow mods rendering entities in the shadow pass (Flywheel) to use the shadow buffers instead.
// TODO: Render
@@ -875,25 +880,27 @@ public class ShadowRenderer {
visibleTileEntities.clear();
globalTileEntities.clear();
final boolean newShadowLists = shadowSearchPending;
shadowSearchPending = false;
final float currentShadowAngle = getShadowAngle();
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle, shadowAngleDelta())) {
CeleritasWorldRenderer.getInstance().getRenderSectionManager().markShadowGraphDirty();
rsm.markShadowGraphDirty();
lastGraphShadowAngle = currentShadowAngle;
}
final boolean deferActive = shouldRenderTerrain;
final long frameNanos = System.nanoTime();
final boolean consumePreSubmit = preSubmitActive;
preSubmitActive = false;
final boolean shadowGraphDirty = rsm.isShadowGraphDirty();
final boolean relayTerrain = shadowTerrainAlwaysRelays()
|| !targets.isTerrainSnapshotValid()
|| consumePreSubmit
|| CeleritasWorldRenderer.getInstance().getRenderSectionManager().isShadowGraphDirty()
|| newShadowLists
|| shadowGraphDirty
|| frameNanos - lastRelayNanos >= SHADOW_RELAY_MAX_AGE_NANOS;
if (relayTerrain) {
relayShadowAngle = consumePreSubmit && !CeleritasWorldRenderer.getInstance().getRenderSectionManager().isShadowGraphDirty() ? preSubmittedShadowAngle : currentShadowAngle;
// New lists draw at the angle they were searched at, unless the gate already wants a newer search.
relayShadowAngle = newShadowLists && !shadowGraphDirty ? searchedShadowAngle : currentShadowAngle;
}
activeShadowAngle = relayShadowAngle;
SHADOW_TERRAIN_RELAID = relayTerrain;
@@ -934,11 +941,9 @@ public class ShadowRenderer {
profiler.endSection();
// Save the main camera viewport before shadow pass overwrites it.
// clipRenderersByFrustum -> setupTerrain sets currentViewport to the shadow frustum.
// If the shadow pass throws or the main setupTerrain doesn't run after us, the shadow
// viewport would persist and corrupt entity culling in the main pass.
final Viewport savedViewport = CeleritasWorldRenderer.getInstance().getCurrentViewport();
// clipRenderersByFrustum -> setupShadowTerrain sets currentViewport to the shadow frustum; restore the last
// terrain viewport so entity culling never sees the shadow one if the main setupTerrain doesn't run.
final Viewport savedViewport = CeleritasWorldRenderer.getInstance().getLastViewport();
// Pair setupGlState / restoreGlState with try-finally so any throw between them
// (translucent terrain, entity rendering, mipmaps, etc.) still unwinds the
@@ -947,7 +952,13 @@ public class ShadowRenderer {
boolean setupGlStateRan = false;
try {
// Execute the vanilla terrain setup / culling routines using our shadow frustum.
final int shadowSearchesBefore = rsm.getShadowSearchSubmissions();
mc.renderGlobal.clipRenderersByFrustum(terrainFrustumHolder.getFrustum(), playerCamera.getPartialTicks());
if (rsm.getShadowSearchSubmissions() != shadowSearchesBefore) {
shadowSearchPending = true;
// createShadowFrustum built the search's light vector from the current light
searchedShadowAngle = currentShadowAngle;
}
// Don't forget to increment the frame counter! This variable is arbitrary and only used in terrain setup,
// and if it's not incremented, the vanilla culling code will get confused and think that it's already seen
@@ -983,9 +994,9 @@ public class ShadowRenderer {
renderShadowEntitiesAndPlayer(levelRenderer, entityShadowFrustum, modelView, entityX, entityY, entityZ, tickDelta);
}
if (shouldRenderBlockEntities) {
if (shouldRenderBlockEntities || shouldRenderLightBlockEntities) {
try (GLDebug.Scope s = GLDebug.scope("shadow:block_entities")) {
renderTileEntities(null, modelView, entityX, entityY, entityZ, tickDelta, entityFrustumConstrained);
renderTileEntities(null, modelView, entityX, entityY, entityZ, tickDelta, entityFrustumConstrained, !shouldRenderBlockEntities);
}
}
@@ -1036,9 +1047,10 @@ public class ShadowRenderer {
profiler.endStartSection("iris_shadowcomp");
if (compositeRenderer != null) compositeRenderer.renderAll();
ACTIVE = false;
CURRENT_TARGETS = null;
} finally {
ACTIVE = false;
CURRENT_TARGETS = null;
}
profiler.endSection();
profiler.endStartSection("culling");
}
@@ -1062,7 +1074,7 @@ public class ShadowRenderer {
}
private String getTileEntitiesDebugString() {
return shouldRenderBlockEntities ? (renderedShadowTileEntities + "/" + Minecraft.getMinecraft().theWorld.loadedTileEntityList.size()) : "disabled by pack";
return (shouldRenderBlockEntities || shouldRenderLightBlockEntities) ? (renderedShadowTileEntities + "/" + Minecraft.getMinecraft().theWorld.loadedTileEntityList.size()) : "disabled by pack";
}
private static class MipmapPass {
@@ -22,7 +22,6 @@ import java.util.OptionalInt;
public interface WorldRenderingPipeline {
void beginLevelRendering();
void renderShadows(EntityRenderer levelRenderer, Camera camera);
default void preSubmitShadowGraph(int frame) {}
void addDebugText(List<String> messages);
OptionalInt getForcedShadowRenderDistanceChunksForDisplay();
@@ -611,16 +611,6 @@ public final class RwImageStoreExtractor {
final Set<String> present = new HashSet<>();
for (AttributeSlot slot : attrs) present.add(slot.name());
out.append("#ifdef USE_VERTEX_COMPRESSION\n");
if (present.contains("a_PosId")) {
out.append(" _vert_position = vec3(a_PosId.xyz) * VERT_POS_SCALE + VERT_POS_OFFSET;\n");
out.append(" _draw_id = (a_PosId.w >> 8u) & 0xFFu;\n");
out.append(" _material_params = (a_PosId.w >> 0u) & 0xFFu;\n");
}
if (present.contains("a_TexCoord")) out.append(" _vert_tex_diffuse_coord = a_TexCoord * VERT_TEX_SCALE;\n");
if (present.contains("a_LightCoord")) out.append(" _vert_tex_light_coord = a_LightCoord;\n");
if (present.contains("a_Color")) out.append(" _vert_color = a_Color;\n");
out.append("#else\n");
if (present.contains("a_PosId")) out.append(" _vert_position = a_PosId;\n");
if (present.contains("a_TexCoord")) out.append(" _vert_tex_diffuse_coord = a_TexCoord;\n");
if (present.contains("a_Color")) out.append(" _vert_color = a_Color;\n");
@@ -630,7 +620,6 @@ public final class RwImageStoreExtractor {
out.append(" _draw_id = (_vg_draw_params >> 8) & 0xFFu;\n");
out.append(" _vert_tex_light_coord = ivec2((uvec2((a_LightCoord >> 16) & 0xFFFFu) >> uvec2(0, 8)) & uvec2(0xFFu));\n");
}
out.append("#endif\n");
}
private static void emitDispatchMain(StringBuilder out, RwExtractMode mode, List<AttributeSlot> attrs) {
@@ -788,11 +777,6 @@ public final class RwImageStoreExtractor {
addAttr(m, new AttributeSlot("a_LightCoord", "uint", 24,
"_vg_vbuf.data[base + 6u]"));
addAttr(m, new AttributeSlot("a_PosId", "uvec4", 0,
"uvec4(0u, 0u, 0u, 0u)", false));
addAttr(m, new AttributeSlot("a_LightCoord", "ivec2", 24,
"ivec2(0, 0)", false));
final LinkedHashMap<String, Map<String, AttributeSlot>> immutable = new LinkedHashMap<>();
for (var e : m.entrySet()) immutable.put(e.getKey(), Map.copyOf(e.getValue()));
return Map.copyOf(immutable);
@@ -29,6 +29,7 @@ public class PackShadowDirectives {
private final boolean shouldRenderEntities;
private final boolean shouldRenderPlayer;
private final boolean shouldRenderBlockEntities;
private final boolean shouldRenderLightBlockEntities;
@Getter private final ShadowCullState cullingState;
private final OptionalBoolean dhShadowEnabled;
private float nearPlane, farPlane;
@@ -83,6 +84,7 @@ public class PackShadowDirectives {
this.shouldRenderEntities = properties.getShadowEntities().orElse(true);
this.shouldRenderPlayer = properties.getShadowPlayer().orElse(false);
this.shouldRenderBlockEntities = properties.getShadowBlockEntities().orElse(true);
this.shouldRenderLightBlockEntities = properties.getShadowLightBlockEntities().orElse(false);
this.cullingState = properties.getShadowCulling();
this.shadowEnabled = properties.getShadowEnabled();
this.dhShadowEnabled = properties.getDhShadowEnabled();
@@ -114,6 +116,7 @@ public class PackShadowDirectives {
this.shouldRenderEntities = shadowDirectives.shouldRenderEntities;
this.shouldRenderPlayer = shadowDirectives.shouldRenderPlayer;
this.shouldRenderBlockEntities = shadowDirectives.shouldRenderBlockEntities;
this.shouldRenderLightBlockEntities = shadowDirectives.shouldRenderLightBlockEntities;
this.cullingState = shadowDirectives.cullingState;
this.depthSamplingSettings = shadowDirectives.depthSamplingSettings;
this.colorSamplingSettings = shadowDirectives.colorSamplingSettings;
@@ -185,6 +188,10 @@ public class PackShadowDirectives {
return shouldRenderBlockEntities;
}
public boolean shouldRenderLightBlockEntities() {
return shouldRenderLightBlockEntities;
}
public OptionalBoolean isShadowEnabled() {
return shadowEnabled;
}