Many bug fixes (#2017)

Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
Eclipse-SolandMartin Robertz authored and GitHub committed 2026-08-19 08:55:43 -07:00
1 parent b2f597a73a
commit 22c9479946
89 files changed
+2820 -735

No files matched your search

@@ -26,6 +26,7 @@ import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
import net.coderbot.iris.gbuffer_overrides.matching.ProgramTable;
import net.coderbot.iris.gbuffer_overrides.matching.RenderCondition;
import net.coderbot.iris.gbuffer_overrides.matching.TranslucentBlendMatcher;
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
import net.coderbot.iris.gbuffer_overrides.state.RenderTargetStateListener;
import net.coderbot.iris.gl.blending.AlphaTestOverride;
@@ -127,9 +128,6 @@ import java.util.function.Supplier;
* Encapsulates the compiled shader program objects for the currently loaded shaderpack.
*/
public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, RenderTargetStateListener {
private final static int SRC_ALPHA = 770;
private final static int ONE_MINUS_SRC_ALPHA = 771;
private final static int ONE = 1;
private final RenderTargets renderTargets;
@Nullable
@@ -260,14 +258,31 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
final Map<Pair<String, InputAvailability>, CompletableFuture<Map<PatchShaderType, String>>> instancedTransformFutures = submitAttributeTransforms(resolver, INSTANCED_PROGRAM_IDS, true);
final Optional<ProgramSource> terrainSource = first(programs.getGbuffersTerrain(), programs.getGbuffersTexturedLit(), programs.getGbuffersTextured(), programs.getGbuffersBasic());
final Optional<ProgramSource> terrainSolidOverride = programs.getGbuffersTerrainSolid();
final Optional<ProgramSource> terrainCutoutOverride = programs.getGbuffersTerrainCutout();
final Optional<ProgramSource> terrainSolidSource = first(terrainSolidOverride, terrainSource);
final Optional<ProgramSource> terrainCutoutSource = first(terrainCutoutOverride, terrainSource);
final Optional<ProgramSource> translucentSource = first(programs.getGbuffersWater(), terrainSource);
final Optional<ProgramSource> shadowSource = programs.getShadow();
final Optional<ProgramSource> shadowSolidOverride = programs.getShadowSolid();
final Optional<ProgramSource> shadowCutoutOverride = programs.getShadowCutout();
final Optional<ProgramSource> shadowSolidSource = first(shadowSolidOverride, shadowSource);
final Optional<ProgramSource> shadowCutoutSource = first(shadowCutoutOverride, shadowSource);
final Optional<ProgramSource> shadowTranslucentSource = first(programs.getShadowWater(), shadowSource);
// Celeritas terrain transform futures
final CompletableFuture<Map<PatchShaderType, String>> celeritasTerrainFuture = terrainSource.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(null);
final CompletableFuture<Map<PatchShaderType, String>> celeritasTerrainSolidFuture = terrainSolidOverride
.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(celeritasTerrainFuture);
final CompletableFuture<Map<PatchShaderType, String>> celeritasTerrainCutoutFuture = terrainCutoutOverride
.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(celeritasTerrainFuture);
final CompletableFuture<Map<PatchShaderType, String>> celeritasTranslucentFuture = translucentSource.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(null);
final CompletableFuture<Map<PatchShaderType, String>> celeritasShadowFuture = shadowSource.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(null);
final CompletableFuture<Map<PatchShaderType, String>> celeritasShadowSolidFuture = shadowSolidOverride
.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(celeritasShadowFuture);
final CompletableFuture<Map<PatchShaderType, String>> celeritasShadowCutoutFuture = shadowCutoutOverride
.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(celeritasShadowFuture);
final CompletableFuture<Map<PatchShaderType, String>> celeritasShadowTranslucentFuture = shadowTranslucentSource.map(DeferredWorldRenderingPipeline::submitCeleritasTerrainTransform).orElse(null);
final Int2ObjectArrayMap<CompletableFuture<String>> setupComputeFutures = submitSetupComputeTransforms(programs.getSetup(), programs.getPackDirectives().getTextureMap());
@@ -461,6 +476,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
ProgramId.BeaconBeam, ProgramId.BeaconBeam, ProgramId.BeaconBeam,
ProgramId.Entities, ProgramId.Entities, ProgramId.Entities,
ProgramId.EntitiesTrans, ProgramId.EntitiesTrans, ProgramId.EntitiesTrans,
ProgramId.Particles, ProgramId.Particles, ProgramId.Particles,
ProgramId.ParticlesTrans, ProgramId.ParticlesTrans, ProgramId.ParticlesTrans,
null, ProgramId.ArmorGlint, ProgramId.ArmorGlint,
null, ProgramId.SpiderEyes, ProgramId.SpiderEyes,
ProgramId.Hand, ProgramId.Hand, ProgramId.Hand,
@@ -697,11 +714,14 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
this.celeritasTerrainPipeline = new CeleritasTerrainPipeline(createTerrainSamplers,
shadowRenderer == null ? null : createShadowTerrainSamplers, createTerrainImages,
shadowRenderer == null ? null : createShadowTerrainImages, this.customUniforms,
terrainSource,
terrainSolidSource,
terrainCutoutSource,
translucentSource,
shadowSource,
shadowSolidSource,
shadowCutoutSource,
shadowTranslucentSource,
celeritasTerrainFuture, celeritasTranslucentFuture, celeritasShadowFuture, celeritasShadowTranslucentFuture,
celeritasTerrainSolidFuture, celeritasTerrainCutoutFuture, celeritasTranslucentFuture,
celeritasShadowSolidFuture, celeritasShadowCutoutFuture, celeritasShadowTranslucentFuture,
renderTargets, flippedAfterPrepare, flippedAfterTranslucent,
celeritasShadowFb);
@@ -843,28 +863,18 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
}
switch (phase) {
case NONE, OUTLINE, DEBUG, PARTICLES:
case NONE, OUTLINE, DEBUG:
return RenderCondition.DEFAULT;
case PARTICLES:
return isTranslucentDraw() ? RenderCondition.PARTICLES_TRANSLUCENT : RenderCondition.PARTICLES;
case SKY, SUNSET, CUSTOM_SKY, SUN, MOON, STARS, VOID:
return RenderCondition.SKY;
case TERRAIN_SOLID, TERRAIN_CUTOUT, TERRAIN_CUTOUT_MIPPED:
return RenderCondition.TERRAIN_OPAQUE;
case ENTITIES:
if (GLStateManager.getBlendState().getSrcRgb() == SRC_ALPHA &&
GLStateManager.getBlendState().getSrcAlpha() == ONE_MINUS_SRC_ALPHA &&
GLStateManager.getBlendState().getDstRgb() == ONE &&
GLStateManager.getBlendState().getDstAlpha() == ONE_MINUS_SRC_ALPHA)
{
return RenderCondition.ENTITIES_TRANSLUCENT;
} else {
return RenderCondition.ENTITIES;
}
return isTranslucentDraw() ? RenderCondition.ENTITIES_TRANSLUCENT : RenderCondition.ENTITIES;
case BLOCK_ENTITIES:
if (GLStateManager.getBlendState().getSrcRgb() == SRC_ALPHA &&
GLStateManager.getBlendState().getDstRgb() == ONE_MINUS_SRC_ALPHA) {
return RenderCondition.BLOCK_ENTITIES_TRANSLUCENT;
}
return RenderCondition.BLOCK_ENTITIES;
return isTranslucentDraw() ? RenderCondition.BLOCK_ENTITIES_TRANSLUCENT : RenderCondition.BLOCK_ENTITIES;
case DESTROY:
return RenderCondition.DESTROY;
case HAND_SOLID:
@@ -884,6 +894,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
}
}
private boolean isTranslucentDraw() {
return declaredTranslucent != null ? declaredTranslucent : TranslucentBlendMatcher.matchesCurrentState();
}
public boolean shouldOverrideShaders() {
return isRenderingLevelGeometry() && isMainBound;
}
@@ -906,10 +920,60 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
* Called when a mod overrides the GL program away from the active Iris pass
*/
public void onModProgramOverride() {
if (current != null) {
modProgramOverrode = true;
programBeforeModOverride = getActivePassProgramId();
}
current = null;
currentCondition = null;
}
public void restorePassAfterModProgram(int newProgram) {
if (refreshingPass || drivingProgram || !modProgramOverrode) {
return;
}
if (newProgram != 0 && newProgram != programBeforeModOverride) {
return;
}
refreshingPass = true;
try {
current = null;
matchPass();
} finally {
modProgramOverrode = false;
programBeforeModOverride = -1;
refreshingPass = false;
}
}
private boolean refreshingPass;
private boolean modProgramOverrode;
private int programBeforeModOverride = -1;
public void onVanillaBlendChanged() {
if (matchingBlend || drivingProgram || refreshingPass) {
return;
}
if (declaredTranslucent != null) {
return;
}
final WorldRenderingPhase phase = getPhase();
if (phase != WorldRenderingPhase.ENTITIES && phase != WorldRenderingPhase.BLOCK_ENTITIES) {
return;
}
matchingBlend = true;
try {
matchPass();
} finally {
matchingBlend = false;
}
}
private boolean matchingBlend;
private void matchPass() {
if (!shouldOverrideShaders()) {
return;
@@ -946,13 +1010,20 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
current = pass;
if (pass != null) {
pass.use();
} else {
Program.unbind();
drivingProgram = true;
try {
if (pass != null) {
pass.use();
} else {
Program.unbind();
}
} finally {
drivingProgram = false;
}
}
private boolean drivingProgram;
@Override
public void rebindCurrentPass() {
final Pass pass = this.current;
@@ -1631,6 +1702,9 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
@Nullable
public ComputeProgram getShadowVoxelizationCompute() { return shadowVoxelizationCompute; }
@Nullable
public ShadowRenderer getShadowRenderer() { return shadowRenderer; }
private GlUniformMatrix4f voxelizationModelView;
private GlUniformMatrix3f voxelizationNormalMatrix;
private final Matrix3f voxelizationNormalScratch = new Matrix3f();
@@ -1772,6 +1846,14 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
@Override
public void beginHand() {
isRenderingFullScreenPass = true;
beginPass(null);
currentCondition = null;
profiler.startSection("iris_center_depth");
centerDepthSampler.sampleCenterDepth();
profiler.endSection();
isRenderingFullScreenPass = false;
if (!usesSampler(IrisSamplers.USAGE_DEPTHTEX2)) {
return;
}
@@ -2005,10 +2087,6 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
isRenderingFullScreenPass = true;
profiler.startSection("iris_center_depth");
centerDepthSampler.sampleCenterDepth();
profiler.endSection();
profiler.startSection("iris_composites");
GLDebug.pushGroup("composite");
try {
@@ -2110,6 +2188,15 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
matchPass();
}
@Override
public void setDeclaredTranslucency(@Nullable Boolean translucent) {
this.declaredTranslucent = translucent;
matchPass();
}
@Nullable
private Boolean declaredTranslucent;
@Override
public RenderTargetStateListener getRenderTargetStateListener() {
return this;