mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-23 21:59:44 +00:00
Many bug fixes (#2017)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
b2f597a73a
commit
22c9479946
89 files changed
+2820
-735
No files matched your search
@@ -6,6 +6,8 @@ import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.coderbot.batchedentityrendering.impl.ordering.SimpleRenderOrderManager;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPhase;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -159,15 +161,17 @@ public class AngelicaBufferSource implements Groupable {
|
||||
|
||||
private void clearCurrentId() {
|
||||
if (!anyIdSet) return;
|
||||
if (idKind == GroupIdKind.ENTITY) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(-1);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityColor(0f, 0f, 0f, 0f);
|
||||
} else {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
}
|
||||
// A pass can set either kind: nested entities inside a TESR write the entity id during a block entity pass
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityAndItem(-1, 0);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityColor(0f, 0f, 0f, 0f);
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
anyIdSet = false;
|
||||
}
|
||||
|
||||
private GroupIdKind effectiveIdKind() {
|
||||
return GbufferPrograms.getCurrentPhase() == WorldRenderingPhase.ENTITIES ? GroupIdKind.ENTITY : idKind;
|
||||
}
|
||||
|
||||
private void drawLayer(RenderLayer layer, LayerDrawHook hook) {
|
||||
final List<BufferSegment> segments = typeToSegment.get(layer);
|
||||
final boolean hasDynamic = segments != null && !segments.isEmpty();
|
||||
@@ -184,7 +188,7 @@ public class AngelicaBufferSource implements Groupable {
|
||||
GLStateManager.glPushMatrix();
|
||||
GLStateManager.glLoadIdentity();
|
||||
SegmentedBufferBuilder.LayerBuffer bound = null;
|
||||
final boolean entityKind = idKind == GroupIdKind.ENTITY;
|
||||
final boolean entityKind = effectiveIdKind() == GroupIdKind.ENTITY;
|
||||
int currentId = Integer.MIN_VALUE;
|
||||
int currentColor = 0;
|
||||
boolean colorSet = false;
|
||||
@@ -271,8 +275,8 @@ public class AngelicaBufferSource implements Groupable {
|
||||
|
||||
public void applyIdAndRebind(int id) {
|
||||
anyIdSet = true;
|
||||
if (idKind == GroupIdKind.ENTITY) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(id);
|
||||
if (effectiveIdKind() == GroupIdKind.ENTITY) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityAndItem(id, 0);
|
||||
rebindPass();
|
||||
} else {
|
||||
setBlockEntityAndRebind(id);
|
||||
@@ -281,8 +285,8 @@ public class AngelicaBufferSource implements Groupable {
|
||||
|
||||
public void applyIdNoRebind(int id) {
|
||||
anyIdSet = true;
|
||||
if (idKind == GroupIdKind.ENTITY) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(id);
|
||||
if (effectiveIdKind() == GroupIdKind.ENTITY) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntityAndItem(id, 0);
|
||||
} else {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(id);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -919,6 +920,11 @@ public class Iris {
|
||||
return pipelineManager;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PipelineManager getPipelineManagerNullable() {
|
||||
return pipelineManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Optional<ShaderPack> getCurrentPack() {
|
||||
return Optional.ofNullable(currentPack);
|
||||
|
||||
@@ -69,13 +69,17 @@ public class CeleritasTerrainPipeline {
|
||||
IntFunction<ProgramImages> createTerrainImages,
|
||||
IntFunction<ProgramImages> createShadowImages,
|
||||
CustomUniforms customUniforms,
|
||||
Optional<ProgramSource> terrainSource,
|
||||
Optional<ProgramSource> terrainSolidSource,
|
||||
Optional<ProgramSource> terrainCutoutSource,
|
||||
Optional<ProgramSource> translucentSource,
|
||||
Optional<ProgramSource> shadowSource,
|
||||
Optional<ProgramSource> shadowSolidSource,
|
||||
Optional<ProgramSource> shadowCutoutSource,
|
||||
Optional<ProgramSource> shadowTranslucentSource,
|
||||
CompletableFuture<Map<PatchShaderType, String>> terrainFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> terrainSolidFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> terrainCutoutFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> translucentFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> shadowFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> shadowSolidFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> shadowCutoutFuture,
|
||||
CompletableFuture<Map<PatchShaderType, String>> shadowTranslucentFuture,
|
||||
RenderTargets renderTargets,
|
||||
ImmutableSet<Integer> flippedAfterPrepare,
|
||||
@@ -90,11 +94,12 @@ public class CeleritasTerrainPipeline {
|
||||
|
||||
// Build program source map (local - only needed during construction)
|
||||
final EnumMap<IrisTerrainPass, Optional<ProgramSource>> gbufferProgramSource = new EnumMap<>(IrisTerrainPass.class);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_SOLID, terrainSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_CUTOUT, terrainSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_TRANSLUCENT, translucentSource.isPresent() ? translucentSource : terrainSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.SHADOW, shadowSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.SHADOW_TRANSLUCENT, shadowTranslucentSource.isPresent() ? shadowTranslucentSource : shadowSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_SOLID, terrainSolidSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_CUTOUT, terrainCutoutSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.GBUFFER_TRANSLUCENT, translucentSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.SHADOW, shadowSolidSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.SHADOW_CUTOUT, shadowCutoutSource);
|
||||
gbufferProgramSource.put(IrisTerrainPass.SHADOW_TRANSLUCENT, shadowTranslucentSource);
|
||||
|
||||
// Initialize PassInfo, framebuffers, blend modes, and alpha in single pass
|
||||
for (IrisTerrainPass pass : IrisTerrainPass.VALUES) {
|
||||
@@ -103,10 +108,12 @@ public class CeleritasTerrainPipeline {
|
||||
|
||||
// Set up framebuffer, blend mode, and buffer blend overrides
|
||||
final ProgramId programId = switch (pass) {
|
||||
case GBUFFER_SOLID -> ProgramId.TerrainSolid;
|
||||
case GBUFFER_CUTOUT -> ProgramId.TerrainCutout;
|
||||
case GBUFFER_TRANSLUCENT -> ProgramId.Water;
|
||||
case SHADOW_TRANSLUCENT -> ProgramId.ShadowWater;
|
||||
case SHADOW, SHADOW_CUTOUT -> ProgramId.Shadow;
|
||||
default -> ProgramId.Terrain;
|
||||
case SHADOW -> ProgramId.ShadowSolid;
|
||||
case SHADOW_CUTOUT -> ProgramId.ShadowCutout;
|
||||
};
|
||||
|
||||
if (pass.isShadow()) {
|
||||
@@ -146,10 +153,12 @@ public class CeleritasTerrainPipeline {
|
||||
}
|
||||
|
||||
// Process and apply shader sources
|
||||
processShaderFuture(terrainFuture, terrainSource, passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID), passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT));
|
||||
processShaderFuture(terrainSolidFuture, terrainSolidSource, passInfoMap.get(IrisTerrainPass.GBUFFER_SOLID));
|
||||
processShaderFuture(terrainCutoutFuture, terrainCutoutSource, passInfoMap.get(IrisTerrainPass.GBUFFER_CUTOUT));
|
||||
processShaderFuture(translucentFuture, translucentSource, passInfoMap.get(IrisTerrainPass.GBUFFER_TRANSLUCENT));
|
||||
processShaderFuture(shadowFuture, shadowSource, passInfoMap.get(IrisTerrainPass.SHADOW), passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT));
|
||||
processShaderFuture(shadowTranslucentFuture, shadowTranslucentSource.isPresent() ? shadowTranslucentSource : shadowSource, passInfoMap.get(IrisTerrainPass.SHADOW_TRANSLUCENT));
|
||||
processShaderFuture(shadowSolidFuture, shadowSolidSource, passInfoMap.get(IrisTerrainPass.SHADOW));
|
||||
processShaderFuture(shadowCutoutFuture, shadowCutoutSource, passInfoMap.get(IrisTerrainPass.SHADOW_CUTOUT));
|
||||
processShaderFuture(shadowTranslucentFuture, shadowTranslucentSource, passInfoMap.get(IrisTerrainPass.SHADOW_TRANSLUCENT));
|
||||
}
|
||||
|
||||
private void processShaderFuture(@Nullable CompletableFuture<Map<PatchShaderType, String>> future, Optional<ProgramSource> source, PassInfo... targets) {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package net.coderbot.iris.fantastic;
|
||||
|
||||
// TODO: RenderType
|
||||
//public class IrisParticleRenderTypes {
|
||||
// public static final ParticleRenderType OPAQUE_TERRAIN = new ParticleRenderType() {
|
||||
// public void begin(BufferBuilder bufferBuilder, TextureManager textureManager) {
|
||||
// GL11.glDisable(GL11.GL_BLEND);
|
||||
// GL11.glDepthMask(true);
|
||||
// GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
|
||||
// textureManager.bind(TextureAtlas.LOCATION_BLOCKS);
|
||||
// bufferBuilder.begin(7, DefaultVertexFormat.PARTICLE);
|
||||
// }
|
||||
//
|
||||
// public void end(Tesselator tesselator) {
|
||||
// tesselator.end();
|
||||
// }
|
||||
//
|
||||
// public String toString() {
|
||||
// return "OPAQUE_TERRAIN_SHEET";
|
||||
// }
|
||||
// };
|
||||
//}
|
||||
@@ -12,6 +12,8 @@ public enum RenderCondition {
|
||||
BEACON_BEAM,
|
||||
ENTITIES,
|
||||
ENTITIES_TRANSLUCENT,
|
||||
PARTICLES,
|
||||
PARTICLES_TRANSLUCENT,
|
||||
GLINT,
|
||||
ENTITY_EYES,
|
||||
HAND_OPAQUE,
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package net.coderbot.iris.gbuffer_overrides.matching;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.states.BlendState;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* Decides whether a draw is blending.
|
||||
*/
|
||||
public final class TranslucentBlendMatcher {
|
||||
|
||||
/** Render thread only. */
|
||||
private static final BlendState scratch = new BlendState();
|
||||
|
||||
private TranslucentBlendMatcher() {}
|
||||
|
||||
public static boolean matchesCurrentState() {
|
||||
if (!GLStateManager.isEffectiveBlendEnabled()) {
|
||||
return false;
|
||||
}
|
||||
GLStateManager.getEffectiveBlendState(scratch);
|
||||
return scratch.getSrcRgb() == GL11.GL_SRC_ALPHA && scratch.getDstRgb() == GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||
}
|
||||
}
|
||||
@@ -3,57 +3,114 @@ package net.coderbot.iris.gl.blending;
|
||||
import com.gtnewhorizons.angelica.glsm.states.AlphaTestFunction;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.VanillaBooleanLayer;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.VanillaStateLayer;
|
||||
import com.gtnewhorizons.angelica.glsm.states.AlphaState;
|
||||
import lombok.Getter;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class AlphaTestStorage {
|
||||
private static boolean originalAlphaTestEnable;
|
||||
private static AlphaTest originalAlphaTest;
|
||||
@Getter
|
||||
private static boolean vanillaEnabled;
|
||||
private static int vanillaFunction = GL11.GL_ALWAYS;
|
||||
private static float vanillaReference;
|
||||
|
||||
@Getter
|
||||
private static boolean alphaTestLocked;
|
||||
|
||||
private static boolean overrideHeld;
|
||||
|
||||
public static void overrideAlphaTest(AlphaTest override) {
|
||||
if (!alphaTestLocked) {
|
||||
if (!overrideHeld) {
|
||||
final AlphaState alphaState = GLStateManager.getAlphaState();
|
||||
|
||||
// Only save the previous state if the alpha test wasn't already locked
|
||||
originalAlphaTestEnable = GLStateManager.getAlphaTest().isEnabled();
|
||||
originalAlphaTest = new AlphaTest(AlphaTestFunction.fromGlId(alphaState.getFunction()).orElse(AlphaTestFunction.ALWAYS), alphaState.getReference());
|
||||
}
|
||||
// Only save the previous state if the alpha test wasn't already overridden
|
||||
vanillaEnabled = GLStateManager.getAlphaTest().isEnabled();
|
||||
vanillaFunction = alphaState.getFunction();
|
||||
vanillaReference = alphaState.getReference();
|
||||
}
|
||||
|
||||
alphaTestLocked = false;
|
||||
overrideHeld = true;
|
||||
|
||||
if (override == null) {
|
||||
GLStateManager.disableAlphaTest();
|
||||
} else {
|
||||
if (override == null) {
|
||||
apply(false, GL11.GL_ALWAYS, 0.0f);
|
||||
} else {
|
||||
apply(true, override.getFunction().getGlId(), override.getReference());
|
||||
}
|
||||
}
|
||||
|
||||
private static void apply(boolean enabled, int function, float reference) {
|
||||
alphaTestLocked = false;
|
||||
try {
|
||||
if (enabled) {
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.glAlphaFunc(function, reference);
|
||||
} else {
|
||||
GLStateManager.disableAlphaTest();
|
||||
}
|
||||
} finally {
|
||||
alphaTestLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void deferAlphaTestToggle(boolean enabled) {
|
||||
vanillaEnabled = enabled;
|
||||
}
|
||||
|
||||
public static void deferAlphaFunc(int function, float reference) {
|
||||
vanillaFunction = function;
|
||||
vanillaReference = reference;
|
||||
}
|
||||
|
||||
public static void restoreAlphaTest() {
|
||||
if (!overrideHeld) {
|
||||
return;
|
||||
}
|
||||
|
||||
alphaTestLocked = false;
|
||||
|
||||
if (vanillaEnabled) {
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.glAlphaFunc(override.getFunction().getGlId(), override.getReference());
|
||||
}
|
||||
|
||||
alphaTestLocked = true;
|
||||
}
|
||||
|
||||
public static void deferAlphaTestToggle(boolean enabled) {
|
||||
originalAlphaTestEnable = enabled;
|
||||
}
|
||||
|
||||
public static void deferAlphaFunc(int function, float reference) {
|
||||
originalAlphaTest = new AlphaTest(AlphaTestFunction.fromGlId(function).get(), reference);
|
||||
}
|
||||
|
||||
public static void restoreAlphaTest() {
|
||||
if (!alphaTestLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
alphaTestLocked = false;
|
||||
|
||||
if (originalAlphaTestEnable) {
|
||||
GLStateManager.enableAlphaTest();
|
||||
} else {
|
||||
} else {
|
||||
GLStateManager.disableAlphaTest();
|
||||
}
|
||||
}
|
||||
|
||||
GLStateManager.glAlphaFunc(originalAlphaTest.getFunction().getGlId(), originalAlphaTest.getReference());
|
||||
}
|
||||
GLStateManager.glAlphaFunc(vanillaFunction, vanillaReference);
|
||||
overrideHeld = false;
|
||||
}
|
||||
|
||||
public static final VanillaBooleanLayer ENABLE_LAYER = new VanillaBooleanLayer() {
|
||||
@Override
|
||||
public boolean isOverrideHeld() {
|
||||
return overrideHeld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVanilla() {
|
||||
return vanillaEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVanilla(boolean enabled) {
|
||||
vanillaEnabled = enabled;
|
||||
}
|
||||
};
|
||||
|
||||
public static final VanillaStateLayer<AlphaState> FUNC_LAYER = new VanillaStateLayer<>() {
|
||||
@Override
|
||||
public boolean isOverrideHeld() {
|
||||
return overrideHeld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readVanilla(AlphaState into) {
|
||||
into.setFunction(vanillaFunction);
|
||||
into.setReference(vanillaReference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeVanilla(AlphaState from) {
|
||||
vanillaFunction = from.getFunction();
|
||||
vanillaReference = from.getReference();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2,126 +2,187 @@ package net.coderbot.iris.gl.blending;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.VanillaBooleanLayer;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.VanillaStateLayer;
|
||||
import com.gtnewhorizons.angelica.glsm.states.BlendState;
|
||||
import lombok.Getter;
|
||||
|
||||
public class BlendModeStorage {
|
||||
private static final int MAX_DRAW_BUFFERS = 8;
|
||||
private static final int MAX_DRAW_BUFFERS = 8;
|
||||
|
||||
private static boolean originalBlendEnable;
|
||||
private static final BlendState originalBlend = new BlendState();
|
||||
@Getter private static boolean blendLocked;
|
||||
@Getter private static boolean hasDeferredChanges;
|
||||
private static final int[] bufferOverrideIndices = new int[MAX_DRAW_BUFFERS];
|
||||
private static final boolean[] bufferOverrideIsDisable = new boolean[MAX_DRAW_BUFFERS];
|
||||
private static final BlendState[] bufferOverrideStates = new BlendState[MAX_DRAW_BUFFERS];
|
||||
private static int bufferOverrideCount;
|
||||
private static boolean vanillaBlendEnable;
|
||||
private static final BlendState vanillaBlend = new BlendState();
|
||||
|
||||
static {
|
||||
for (int i = 0; i < MAX_DRAW_BUFFERS; i++) {
|
||||
bufferOverrideStates[i] = new BlendState();
|
||||
}
|
||||
}
|
||||
@Getter
|
||||
private static boolean blendLocked;
|
||||
@Getter
|
||||
private static boolean overrideHeld;
|
||||
|
||||
private static boolean hasGlobalOverride;
|
||||
|
||||
private static boolean hasDeferredChanges;
|
||||
private static final int[] bufferOverrideIndices = new int[MAX_DRAW_BUFFERS];
|
||||
private static final boolean[] bufferOverrideIsDisable = new boolean[MAX_DRAW_BUFFERS];
|
||||
private static final BlendState[] bufferOverrideStates = new BlendState[MAX_DRAW_BUFFERS];
|
||||
private static int bufferOverrideCount;
|
||||
private static boolean bufferOverridesDirty;
|
||||
|
||||
static {
|
||||
for (int i = 0; i < MAX_DRAW_BUFFERS; i++) {
|
||||
bufferOverrideStates[i] = new BlendState();
|
||||
}
|
||||
}
|
||||
|
||||
public static void overrideBlend(BlendState override) {
|
||||
if (!blendLocked) {
|
||||
// Only save the previous state if the blend mode wasn't already locked
|
||||
originalBlendEnable = GLStateManager.getBlendMode().isEnabled();
|
||||
originalBlend.set(GLStateManager.getBlendState());
|
||||
}
|
||||
captureVanilla();
|
||||
|
||||
bufferOverrideCount = 0;
|
||||
hasDeferredChanges = false;
|
||||
blendLocked = false;
|
||||
bufferOverrideCount = 0;
|
||||
bufferOverridesDirty = false;
|
||||
hasDeferredChanges = false;
|
||||
overrideHeld = true;
|
||||
hasGlobalOverride = true;
|
||||
|
||||
if (override == null) {
|
||||
GLStateManager.disableBlend();
|
||||
} else {
|
||||
GLStateManager.enableBlend();
|
||||
GLStateManager.tryBlendFuncSeparate(override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha());
|
||||
}
|
||||
blendLocked = false;
|
||||
try {
|
||||
if (override == null) {
|
||||
GLStateManager.disableBlend();
|
||||
} else {
|
||||
GLStateManager.enableBlend();
|
||||
GLStateManager.tryBlendFuncSeparate(override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha());
|
||||
}
|
||||
} finally {
|
||||
blendLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
blendLocked = true;
|
||||
}
|
||||
public static void overrideBufferBlend(int index, BlendState override) {
|
||||
captureVanilla();
|
||||
|
||||
public static void overrideBufferBlend(int index, BlendState override) {
|
||||
if (!blendLocked) {
|
||||
// Only save the previous state if the blend mode wasn't already locked
|
||||
originalBlendEnable = GLStateManager.getBlendMode().isEnabled();
|
||||
originalBlend.set(GLStateManager.getBlendState());
|
||||
}
|
||||
if (override == null) {
|
||||
RenderSystem.disableBufferBlend(index);
|
||||
} else {
|
||||
RenderSystem.enableBufferBlend(index);
|
||||
RenderSystem.blendFuncSeparatei(index, override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha());
|
||||
}
|
||||
|
||||
if (override == null) {
|
||||
RenderSystem.disableBufferBlend(index);
|
||||
} else {
|
||||
RenderSystem.enableBufferBlend(index);
|
||||
RenderSystem.blendFuncSeparatei(index, override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha());
|
||||
}
|
||||
if (bufferOverrideCount < MAX_DRAW_BUFFERS) {
|
||||
final int slot = bufferOverrideCount++;
|
||||
bufferOverrideIndices[slot] = index;
|
||||
bufferOverrideIsDisable[slot] = (override == null);
|
||||
if (override != null) {
|
||||
bufferOverrideStates[slot].setAll(override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha());
|
||||
}
|
||||
}
|
||||
overrideHeld = true;
|
||||
blendLocked = true;
|
||||
}
|
||||
|
||||
if (bufferOverrideCount < MAX_DRAW_BUFFERS) {
|
||||
final int slot = bufferOverrideCount++;
|
||||
bufferOverrideIndices[slot] = index;
|
||||
bufferOverrideIsDisable[slot] = (override == null);
|
||||
if (override != null) {
|
||||
bufferOverrideStates[slot].setAll(override.getSrcRgb(), override.getDstRgb(), override.getSrcAlpha(), override.getDstAlpha());
|
||||
}
|
||||
}
|
||||
blendLocked = true;
|
||||
}
|
||||
private static void captureVanilla() {
|
||||
if (!overrideHeld) {
|
||||
vanillaBlendEnable = GLStateManager.getBlendMode().isEnabled();
|
||||
vanillaBlend.set(GLStateManager.getBlendState());
|
||||
}
|
||||
}
|
||||
|
||||
public static void deferBlendModeToggle(boolean enabled) {
|
||||
originalBlendEnable = enabled;
|
||||
hasDeferredChanges = true;
|
||||
}
|
||||
public static void deferBlendModeToggle(boolean enabled) {
|
||||
vanillaBlendEnable = enabled;
|
||||
hasDeferredChanges = true;
|
||||
}
|
||||
|
||||
public static void deferBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) {
|
||||
originalBlend.setAll(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
hasDeferredChanges = true;
|
||||
}
|
||||
public static void deferBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) {
|
||||
vanillaBlend.setAll(srcRgb, dstRgb, srcAlpha, dstAlpha);
|
||||
hasDeferredChanges = true;
|
||||
}
|
||||
|
||||
public static void flushDeferredBlend() {
|
||||
if (!blendLocked || !hasDeferredChanges) return;
|
||||
hasDeferredChanges = false;
|
||||
blendLocked = false;
|
||||
public static void flushDeferredBlend() {
|
||||
if (!overrideHeld) return;
|
||||
|
||||
if (originalBlendEnable) {
|
||||
GLStateManager.enableBlend();
|
||||
} else {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
GLStateManager.tryBlendFuncSeparate(
|
||||
originalBlend.getSrcRgb(), originalBlend.getDstRgb(),
|
||||
originalBlend.getSrcAlpha(), originalBlend.getDstAlpha());
|
||||
if (hasDeferredChanges && !hasGlobalOverride) {
|
||||
hasDeferredChanges = false;
|
||||
applyVanilla();
|
||||
bufferOverridesDirty = true;
|
||||
}
|
||||
|
||||
blendLocked = true;
|
||||
if (bufferOverridesDirty) {
|
||||
bufferOverridesDirty = false;
|
||||
reassertBufferOverrides();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < bufferOverrideCount; i++) {
|
||||
final int idx = bufferOverrideIndices[i];
|
||||
if (bufferOverrideIsDisable[i]) {
|
||||
RenderSystem.disableBufferBlend(idx);
|
||||
} else {
|
||||
final BlendState s = bufferOverrideStates[i];
|
||||
RenderSystem.enableBufferBlend(idx);
|
||||
RenderSystem.blendFuncSeparatei(idx, s.getSrcRgb(), s.getDstRgb(), s.getSrcAlpha(), s.getDstAlpha());
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void reassertBufferOverrides() {
|
||||
for (int i = 0; i < bufferOverrideCount; i++) {
|
||||
final int idx = bufferOverrideIndices[i];
|
||||
if (bufferOverrideIsDisable[i]) {
|
||||
RenderSystem.disableBufferBlend(idx);
|
||||
} else {
|
||||
final BlendState s = bufferOverrideStates[i];
|
||||
RenderSystem.enableBufferBlend(idx);
|
||||
RenderSystem.blendFuncSeparatei(idx, s.getSrcRgb(), s.getDstRgb(), s.getSrcAlpha(), s.getDstAlpha());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreBlend() {
|
||||
if (!blendLocked) {
|
||||
return;
|
||||
}
|
||||
public static void restoreBlend() {
|
||||
if (!overrideHeld) {
|
||||
return;
|
||||
}
|
||||
|
||||
blendLocked = false;
|
||||
hasDeferredChanges = false;
|
||||
bufferOverrideCount = 0;
|
||||
hasGlobalOverride = false;
|
||||
hasDeferredChanges = false;
|
||||
bufferOverrideCount = 0;
|
||||
bufferOverridesDirty = false;
|
||||
blendLocked = false;
|
||||
|
||||
if (originalBlendEnable) {
|
||||
GLStateManager.enableBlend();
|
||||
} else {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
applyVanilla();
|
||||
overrideHeld = false;
|
||||
}
|
||||
|
||||
GLStateManager.tryBlendFuncSeparate(originalBlend.getSrcRgb(), originalBlend.getDstRgb(), originalBlend.getSrcAlpha(), originalBlend.getDstAlpha());
|
||||
}
|
||||
private static void applyVanilla() {
|
||||
final boolean wasLocked = blendLocked;
|
||||
blendLocked = false;
|
||||
try {
|
||||
if (vanillaBlendEnable) {
|
||||
GLStateManager.enableBlend();
|
||||
} else {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
GLStateManager.tryBlendFuncSeparate(vanillaBlend.getSrcRgb(), vanillaBlend.getDstRgb(), vanillaBlend.getSrcAlpha(), vanillaBlend.getDstAlpha());
|
||||
} finally {
|
||||
blendLocked = wasLocked;
|
||||
}
|
||||
}
|
||||
|
||||
public static final VanillaBooleanLayer ENABLE_LAYER = new VanillaBooleanLayer() {
|
||||
@Override
|
||||
public boolean isOverrideHeld() {
|
||||
return overrideHeld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVanilla() {
|
||||
return vanillaBlendEnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVanilla(boolean enabled) {
|
||||
deferBlendModeToggle(enabled);
|
||||
}
|
||||
};
|
||||
|
||||
public static final VanillaStateLayer<BlendState> FUNC_LAYER = new VanillaStateLayer<>() {
|
||||
@Override
|
||||
public boolean isOverrideHeld() {
|
||||
return overrideHeld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readVanilla(BlendState into) {
|
||||
into.setAll(vanillaBlend.getSrcRgb(), vanillaBlend.getDstRgb(), vanillaBlend.getSrcAlpha(), vanillaBlend.getDstAlpha());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeVanilla(BlendState from) {
|
||||
deferBlendFunc(from.getSrcRgb(), from.getDstRgb(), from.getSrcAlpha(), from.getDstAlpha());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -3,64 +3,105 @@ package net.coderbot.iris.gl.blending;
|
||||
import com.gtnewhorizons.angelica.glsm.states.DepthState;
|
||||
import com.gtnewhorizons.angelica.glsm.states.ColorMask;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.hooks.VanillaStateLayer;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import lombok.Getter;
|
||||
|
||||
public class DepthColorStorage {
|
||||
private static boolean originalDepthEnable;
|
||||
private static net.coderbot.iris.gl.blending.ColorMask originalColor;
|
||||
@Getter
|
||||
private static boolean vanillaDepthEnable;
|
||||
private static final ColorMask vanillaColor = new ColorMask();
|
||||
|
||||
@Getter
|
||||
private static boolean depthColorLocked;
|
||||
|
||||
private static final IntOpenHashSet ownedPrograms = new IntOpenHashSet();
|
||||
@Getter
|
||||
private static boolean overrideHeld;
|
||||
|
||||
public static void registerOwnedProgram(int programId) {
|
||||
ownedPrograms.add(programId);
|
||||
}
|
||||
private static final IntOpenHashSet ownedPrograms = new IntOpenHashSet();
|
||||
|
||||
public static void unregisterOwnedProgram(int programId) {
|
||||
ownedPrograms.remove(programId);
|
||||
}
|
||||
public static void registerOwnedProgram(int programId) {
|
||||
ownedPrograms.add(programId);
|
||||
}
|
||||
|
||||
public static boolean isOwnedProgram(int programId) {
|
||||
return ownedPrograms.contains(programId);
|
||||
}
|
||||
public static void unregisterOwnedProgram(int programId) {
|
||||
ownedPrograms.remove(programId);
|
||||
}
|
||||
|
||||
public static boolean isOwnedProgram(int programId) {
|
||||
return ownedPrograms.contains(programId);
|
||||
}
|
||||
|
||||
public static void disableDepthColor() {
|
||||
if (!depthColorLocked) {
|
||||
// Only save the previous state if the depth and color mask wasn't already locked
|
||||
final ColorMask colorMask = GLStateManager.getColorMask();
|
||||
final DepthState depthState = GLStateManager.getDepthState();
|
||||
if (!overrideHeld) {
|
||||
final ColorMask colorMask = GLStateManager.getColorMask();
|
||||
final DepthState depthState = GLStateManager.getDepthState();
|
||||
|
||||
originalDepthEnable = depthState.isEnabled();
|
||||
originalColor = new net.coderbot.iris.gl.blending.ColorMask(colorMask.red, colorMask.green, colorMask.blue, colorMask.alpha);
|
||||
}
|
||||
vanillaDepthEnable = depthState.isEnabled();
|
||||
vanillaColor.set(colorMask);
|
||||
}
|
||||
|
||||
depthColorLocked = false;
|
||||
overrideHeld = true;
|
||||
|
||||
GLStateManager.glDepthMask(false);
|
||||
GLStateManager.glColorMask(false, false, false, false);
|
||||
depthColorLocked = false;
|
||||
try {
|
||||
GLStateManager.glDepthMask(false);
|
||||
GLStateManager.glColorMask(false, false, false, false);
|
||||
} finally {
|
||||
depthColorLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
depthColorLocked = true;
|
||||
}
|
||||
public static void deferDepthEnable(boolean enabled) {
|
||||
vanillaDepthEnable = enabled;
|
||||
}
|
||||
|
||||
public static void deferDepthEnable(boolean enabled) {
|
||||
originalDepthEnable = enabled;
|
||||
}
|
||||
public static void deferColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
|
||||
vanillaColor.setAll(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public static void deferColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
|
||||
originalColor = new net.coderbot.iris.gl.blending.ColorMask(red, green, blue, alpha);
|
||||
}
|
||||
public static void unlockDepthColor() {
|
||||
if (!overrideHeld) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static void unlockDepthColor() {
|
||||
if (!depthColorLocked) {
|
||||
return;
|
||||
}
|
||||
depthColorLocked = false;
|
||||
|
||||
depthColorLocked = false;
|
||||
GLStateManager.glDepthMask(vanillaDepthEnable);
|
||||
GLStateManager.glColorMask(vanillaColor.red, vanillaColor.green, vanillaColor.blue, vanillaColor.alpha);
|
||||
overrideHeld = false;
|
||||
}
|
||||
|
||||
GLStateManager.glDepthMask(originalDepthEnable);
|
||||
public static final VanillaStateLayer<DepthState> DEPTH_LAYER = new VanillaStateLayer<>() {
|
||||
@Override
|
||||
public boolean isOverrideHeld() {
|
||||
return overrideHeld;
|
||||
}
|
||||
|
||||
GLStateManager.glColorMask(originalColor.isRedMasked(), originalColor.isGreenMasked(), originalColor.isBlueMasked(), originalColor.isAlphaMasked());
|
||||
}
|
||||
@Override
|
||||
public void readVanilla(DepthState into) {
|
||||
into.setEnabled(vanillaDepthEnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeVanilla(DepthState from) {
|
||||
vanillaDepthEnable = from.isEnabled();
|
||||
}
|
||||
};
|
||||
|
||||
public static final VanillaStateLayer<ColorMask> COLOR_LAYER = new VanillaStateLayer<>() {
|
||||
@Override
|
||||
public boolean isOverrideHeld() {
|
||||
return overrideHeld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readVanilla(ColorMask into) {
|
||||
into.set(vanillaColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeVanilla(ColorMask from) {
|
||||
vanillaColor.set(from);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -36,7 +36,6 @@ public class ShaderPackSelectionList extends IrisGuiSlot {
|
||||
@Getter
|
||||
private ShaderPackEntry applied = null;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private ShaderPackEntry selected = null;
|
||||
|
||||
@@ -203,6 +202,11 @@ public class ShaderPackSelectionList extends IrisGuiSlot {
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelected(ShaderPackEntry selected) {
|
||||
this.selected = selected;
|
||||
this.screen.refreshScreenSwitchButton();
|
||||
}
|
||||
|
||||
public void select(String name) {
|
||||
for (BaseEntry entry : this.entries) {
|
||||
if (entry instanceof ShaderPackEntry shaderPackEntry && name.equals(shaderPackEntry.getPackName())) {
|
||||
|
||||
@@ -39,8 +39,10 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
@@ -85,6 +87,8 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
private boolean guiHidden = false;
|
||||
private boolean dirty = false;
|
||||
|
||||
private final Map<String, Boolean> packOptionAvailability = new HashMap<>();
|
||||
|
||||
public ShaderPackScreen(GuiScreen parent) {
|
||||
this.title = I18n.format("options.iris.shaderPackSelection.title");
|
||||
|
||||
@@ -250,19 +254,7 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
I18n.format("options.iris.openShaderPackFolder"), button -> this.openShaderPackFolder()));
|
||||
|
||||
this.screenSwitchButton = new IrisButton(topCenter + 78, this.height - 51, 152, 20,
|
||||
I18n.format("options.iris.shaderPackList"), button -> {
|
||||
this.optionMenuOpen = !this.optionMenuOpen;
|
||||
|
||||
// UX: Apply changes before switching screens to avoid unintuitive behavior
|
||||
//
|
||||
// Not doing this leads to unintuitive behavior, since selecting a pack in the
|
||||
// list (but not applying) would open the settings for the previous pack, rather
|
||||
// than opening the settings for the selected (but not applied) pack.
|
||||
this.applyChanges();
|
||||
|
||||
initGui();
|
||||
}
|
||||
);
|
||||
I18n.format("options.iris.shaderPackList"), button -> this.toggleOptionMenu());
|
||||
this.buttonList.add(this.screenSwitchButton);
|
||||
|
||||
refreshScreenSwitchButton();
|
||||
@@ -299,6 +291,17 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (this.notificationDialogTimer > 0) {
|
||||
this.notificationDialogTimer--;
|
||||
} else if (this.notificationDialog != null) {
|
||||
this.notificationDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the mouse is clicked.
|
||||
*/
|
||||
@@ -346,10 +349,52 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches between the pack list and the pack settings, applying the pending pack first.
|
||||
* <p>
|
||||
* UX: Apply changes before switching screens to avoid unintuitive behavior. Not doing this leads to
|
||||
* unintuitive behavior, since selecting a pack in the list (but not applying) would open the settings
|
||||
* for the previous pack, rather than opening the settings for the selected (but not applied) pack.
|
||||
*/
|
||||
private void toggleOptionMenu() {
|
||||
final boolean opening = !this.optionMenuOpen;
|
||||
this.optionMenuOpen = opening;
|
||||
|
||||
this.applyChanges();
|
||||
|
||||
// The pack is only parsed by applyChanges, so this is the first point where an option-less
|
||||
// pack can be recognized. Stay on the list instead of opening an empty settings screen.
|
||||
if (opening && !currentPackHasOptions()) {
|
||||
this.optionMenuOpen = false;
|
||||
displayNotification(I18n.format("options.iris.shaderPackOptions.noOptions", Iris.getCurrentPackName()));
|
||||
}
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
private boolean canOpenOptionMenu() {
|
||||
if (!this.shaderPackList.getTopButtonRow().shadersEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ShaderPackEntry highlighted = this.shaderPackList.getSelected();
|
||||
final String name = highlighted != null ? highlighted.getPackName() : Iris.getCurrentPackName();
|
||||
|
||||
return name == null || this.packOptionAvailability.getOrDefault(name, Boolean.TRUE);
|
||||
}
|
||||
|
||||
private boolean currentPackHasOptions() {
|
||||
return Iris.getCurrentPack().map(p -> p.getMenuContainer().hasMenuElements()).orElse(false);
|
||||
}
|
||||
|
||||
public void refreshForChangedPack() {
|
||||
if (Iris.getCurrentPack().isPresent()) {
|
||||
final ShaderPack currentPack = Iris.getCurrentPack().get();
|
||||
|
||||
if (Iris.getCurrentPackName() != null) {
|
||||
this.packOptionAvailability.put(Iris.getCurrentPackName(), currentPack.getMenuContainer().hasMenuElements());
|
||||
}
|
||||
|
||||
this.navigation = new NavigationController();
|
||||
|
||||
if (this.shaderOptionList != null) {
|
||||
@@ -364,11 +409,10 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
}
|
||||
|
||||
public void refreshScreenSwitchButton() {
|
||||
if (this.screenSwitchButton != null) {
|
||||
if (this.screenSwitchButton != null && this.shaderPackList != null) {
|
||||
this.screenSwitchButton.displayString = optionMenuOpen ? I18n.format("options.iris.shaderPackList") : I18n.format("options.iris.shaderPackSettings");
|
||||
// Disable the settings switch when shaders are off or the selected pack exposes no options
|
||||
this.screenSwitchButton.enabled = optionMenuOpen || (shaderPackList.getTopButtonRow().shadersEnabled
|
||||
&& Iris.getCurrentPack().map(p -> !p.getMenuContainer().mainScreen.elements.isEmpty()).orElse(true));
|
||||
// Disable the settings switch when shaders are off or the highlighted pack exposes no options
|
||||
this.screenSwitchButton.enabled = optionMenuOpen || canOpenOptionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,12 +479,8 @@ public class ShaderPackScreen extends GuiScreen implements HudHideable {
|
||||
return;
|
||||
}
|
||||
if (keyCode == Keyboard.KEY_TAB) {
|
||||
final boolean canOpenOptions = shaderPackList.getTopButtonRow().shadersEnabled
|
||||
&& Iris.getCurrentPack().map(p -> !p.getMenuContainer().mainScreen.elements.isEmpty()).orElse(false);
|
||||
if (this.optionMenuOpen || canOpenOptions) {
|
||||
this.optionMenuOpen = !this.optionMenuOpen;
|
||||
this.applyChanges();
|
||||
this.initGui();
|
||||
if (this.optionMenuOpen || canOpenOptionMenu()) {
|
||||
toggleOptionMenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
package net.coderbot.iris.layer;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.states.AlphaState;
|
||||
import com.gtnewhorizons.angelica.glsm.states.BlendState;
|
||||
import net.coderbot.iris.gl.shader.ProgramCreator;
|
||||
import net.coderbot.iris.gl.state.StateUpdateNotifiers;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPhase;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GbufferPrograms {
|
||||
private static boolean entities;
|
||||
private static boolean blockEntities;
|
||||
private static boolean particles;
|
||||
private static boolean outline;
|
||||
private static boolean entityLoop;
|
||||
private static Runnable phaseChangeListener;
|
||||
|
||||
|
||||
static {
|
||||
StateUpdateNotifiers.phaseChangeNotifier = listener -> phaseChangeListener = listener;
|
||||
}
|
||||
|
||||
|
||||
private static void checkReentrancy() {
|
||||
if (entities || blockEntities || outline) {
|
||||
throw new IllegalStateException("GbufferPrograms in weird state, tried to call begin function when entities = "
|
||||
@@ -61,8 +69,18 @@ public class GbufferPrograms {
|
||||
throw new IllegalStateException("GbufferPrograms in weird state, tried to call endEntities when entities = false");
|
||||
}
|
||||
|
||||
setPhase(WorldRenderingPhase.NONE);
|
||||
entities = false;
|
||||
endPhase();
|
||||
}
|
||||
|
||||
private static void endPhase() {
|
||||
if (particles) {
|
||||
setPhase(WorldRenderingPhase.PARTICLES);
|
||||
} else if (entityLoop) {
|
||||
setPhase(WorldRenderingPhase.ENTITIES);
|
||||
} else {
|
||||
setPhase(WorldRenderingPhase.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void beginOutline() {
|
||||
@@ -76,10 +94,41 @@ public class GbufferPrograms {
|
||||
throw new IllegalStateException("GbufferPrograms in weird state, tried to call endOutline when outline = false");
|
||||
}
|
||||
|
||||
setPhase(WorldRenderingPhase.NONE);
|
||||
outline = false;
|
||||
endPhase();
|
||||
}
|
||||
|
||||
public static int beginParticles() {
|
||||
if (particleDepth == particlePhaseSaves.length) {
|
||||
particlePhaseSaves = Arrays.copyOf(particlePhaseSaves, particleDepth * 2);
|
||||
particleTranslucencySaves = Arrays.copyOf(particleTranslucencySaves, particleDepth * 2);
|
||||
}
|
||||
|
||||
particlePhaseSaves[particleDepth] = getCurrentPhase();
|
||||
particleTranslucencySaves[particleDepth] = beginTranslucencyDeclaration(Boolean.FALSE);
|
||||
|
||||
setPhase(WorldRenderingPhase.PARTICLES);
|
||||
particles = true;
|
||||
|
||||
return particleDepth++;
|
||||
}
|
||||
|
||||
public static void endParticles(int depth) {
|
||||
particleDepth = depth;
|
||||
|
||||
endTranslucencyDeclaration(particleTranslucencySaves[depth]);
|
||||
particleTranslucencySaves[depth] = null;
|
||||
|
||||
setPhase(particlePhaseSaves[depth]);
|
||||
particlePhaseSaves[depth] = null;
|
||||
|
||||
particles = particleDepth > 0;
|
||||
}
|
||||
|
||||
private static WorldRenderingPhase[] particlePhaseSaves = new WorldRenderingPhase[4];
|
||||
private static Boolean[] particleTranslucencySaves = new Boolean[4];
|
||||
private static int particleDepth;
|
||||
|
||||
public static void beginBlockEntities() {
|
||||
checkReentrancy();
|
||||
setPhase(WorldRenderingPhase.BLOCK_ENTITIES);
|
||||
@@ -92,8 +141,101 @@ public class GbufferPrograms {
|
||||
throw new IllegalStateException("GbufferPrograms in weird state, tried to call endBlockEntities when blockEntities = false");
|
||||
}
|
||||
|
||||
setPhase(WorldRenderingPhase.NONE);
|
||||
blockEntities = false;
|
||||
endPhase();
|
||||
}
|
||||
|
||||
public static void setCutoutDefaults() {
|
||||
GLStateManager.enableAlphaTest();
|
||||
GLStateManager.glAlphaFunc(GL11.GL_GREATER, 0.1F);
|
||||
|
||||
final int previousUnit = GLStateManager.getActiveTextureUnitForServerState();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE1);
|
||||
GLStateManager.enableTexture();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + previousUnit);
|
||||
}
|
||||
|
||||
public static long pushCutoutDefaults() {
|
||||
final long saved = packCutoutState();
|
||||
setCutoutDefaults();
|
||||
return saved;
|
||||
}
|
||||
|
||||
public static void popCutoutDefaults(long saved) {
|
||||
if ((saved & ALPHA_ENABLED_BIT) != 0) {
|
||||
GLStateManager.enableAlphaTest();
|
||||
} else {
|
||||
GLStateManager.disableAlphaTest();
|
||||
}
|
||||
GLStateManager.glAlphaFunc((int) ((saved >>> 32) & 0xFFFF), Float.intBitsToFloat((int) saved));
|
||||
|
||||
if ((saved & LIGHTMAP_ENABLED_BIT) == 0) {
|
||||
final int previousUnit = GLStateManager.getActiveTextureUnitForServerState();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE1);
|
||||
GLStateManager.disableTexture();
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0 + previousUnit);
|
||||
}
|
||||
}
|
||||
|
||||
public static int pushBlendState() {
|
||||
if (blendDepth == blendSaves.length) {
|
||||
blendSaves = Arrays.copyOf(blendSaves, blendDepth * 2);
|
||||
blendEnabledSaves = Arrays.copyOf(blendEnabledSaves, blendDepth * 2);
|
||||
}
|
||||
|
||||
BlendState saved = blendSaves[blendDepth];
|
||||
if (saved == null) {
|
||||
saved = new BlendState();
|
||||
blendSaves[blendDepth] = saved;
|
||||
}
|
||||
|
||||
GLStateManager.getEffectiveBlendState(saved);
|
||||
blendEnabledSaves[blendDepth] = GLStateManager.isEffectiveBlendEnabled();
|
||||
|
||||
return blendDepth++;
|
||||
}
|
||||
public static void popBlendState(int depth) {
|
||||
blendDepth = depth;
|
||||
|
||||
final boolean enabled = blendEnabledSaves[depth];
|
||||
if (enabled != GLStateManager.isEffectiveBlendEnabled()) {
|
||||
if (enabled) {
|
||||
GLStateManager.enableBlend();
|
||||
} else {
|
||||
GLStateManager.disableBlend();
|
||||
}
|
||||
}
|
||||
|
||||
final BlendState saved = blendSaves[depth];
|
||||
GLStateManager.getEffectiveBlendState(blendScratch);
|
||||
if (blendScratch.getSrcRgb() != saved.getSrcRgb() || blendScratch.getDstRgb() != saved.getDstRgb()
|
||||
|| blendScratch.getSrcAlpha() != saved.getSrcAlpha() || blendScratch.getDstAlpha() != saved.getDstAlpha()) {
|
||||
GLStateManager.tryBlendFuncSeparate(saved.getSrcRgb(), saved.getDstRgb(), saved.getSrcAlpha(), saved.getDstAlpha());
|
||||
}
|
||||
}
|
||||
|
||||
public static void popBlendStateTop() {
|
||||
if (blendDepth > 0) {
|
||||
popBlendState(blendDepth - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static BlendState[] blendSaves = new BlendState[4];
|
||||
private static boolean[] blendEnabledSaves = new boolean[4];
|
||||
private static int blendDepth;
|
||||
private static final BlendState blendScratch = new BlendState();
|
||||
|
||||
private static final long ALPHA_ENABLED_BIT = 1L << 48;
|
||||
private static final long LIGHTMAP_ENABLED_BIT = 1L << 49;
|
||||
private static final AlphaState alphaScratch = new AlphaState();
|
||||
|
||||
private static long packCutoutState() {
|
||||
GLStateManager.getEffectiveAlphaState(alphaScratch);
|
||||
|
||||
return (Float.floatToRawIntBits(alphaScratch.getReference()) & 0xFFFFFFFFL)
|
||||
| ((long) (alphaScratch.getFunction() & 0xFFFF) << 32)
|
||||
| (GLStateManager.isEffectiveAlphaTestEnabled() ? ALPHA_ENABLED_BIT : 0L)
|
||||
| (GLStateManager.getTextures().getTextureUnitStates(1).isEnabled() ? LIGHTMAP_ENABLED_BIT : 0L);
|
||||
}
|
||||
|
||||
public static void setBlockEntityDefaults() {
|
||||
@@ -121,7 +263,23 @@ public class GbufferPrograms {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean beginNestedEntityPhase() {
|
||||
if (getCurrentPhase() != WorldRenderingPhase.BLOCK_ENTITIES) {
|
||||
return false;
|
||||
}
|
||||
setOverridePhase(WorldRenderingPhase.ENTITIES);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void endNestedEntityPhase(boolean pushed) {
|
||||
if (pushed) {
|
||||
setOverridePhase(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setOverridePhase(WorldRenderingPhase phase) {
|
||||
overridePhase = phase;
|
||||
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
|
||||
if (pipeline != null) {
|
||||
@@ -129,20 +287,62 @@ public class GbufferPrograms {
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static WorldRenderingPhase overridePhase;
|
||||
|
||||
public static Boolean beginTranslucencyDeclaration(Boolean translucent) {
|
||||
final Boolean previous = declaredTranslucent;
|
||||
declaredTranslucent = translucent;
|
||||
applyTranslucencyDeclaration();
|
||||
return previous;
|
||||
}
|
||||
|
||||
public static void endTranslucencyDeclaration(Boolean previous) {
|
||||
declaredTranslucent = previous;
|
||||
applyTranslucencyDeclaration();
|
||||
}
|
||||
|
||||
public static void setTranslucencyDeclaration(Boolean translucent) {
|
||||
declaredTranslucent = translucent;
|
||||
applyTranslucencyDeclaration();
|
||||
}
|
||||
|
||||
private static Boolean declaredTranslucent;
|
||||
|
||||
private static void applyTranslucencyDeclaration() {
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
|
||||
if (pipeline != null) {
|
||||
pipeline.setDeclaredTranslucency(declaredTranslucent);
|
||||
}
|
||||
}
|
||||
|
||||
private static SpecialCondition currentSpecial;
|
||||
|
||||
public static SpecialCondition getSpecialCondition() {
|
||||
return currentSpecial;
|
||||
}
|
||||
|
||||
public static Boolean getDeclaredTranslucency() {
|
||||
return declaredTranslucent;
|
||||
}
|
||||
|
||||
public static void setupSpecialRenderCondition(SpecialCondition override) {
|
||||
currentSpecial = override;
|
||||
Iris.getPipelineManager().getPipeline().ifPresent(p -> p.setSpecialCondition(override));
|
||||
}
|
||||
|
||||
public static void teardownSpecialRenderCondition() {
|
||||
currentSpecial = null;
|
||||
Iris.getPipelineManager().getPipeline().ifPresent(p -> p.setSpecialCondition(null));
|
||||
}
|
||||
|
||||
|
||||
public static void runPhaseChangeNotifier() {
|
||||
if (phaseChangeListener != null) {
|
||||
phaseChangeListener.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void init() {
|
||||
// Empty initializer to run static
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.coderbot.iris.layer;
|
||||
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPhase;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public record PassOverride(SpecialCondition special, Boolean translucent, WorldRenderingPhase phase) {
|
||||
|
||||
public static final PassOverride NONE = new PassOverride(null, null, null);
|
||||
|
||||
public PassOverride(SpecialCondition special, Boolean translucent) {
|
||||
this(special, translucent, null);
|
||||
}
|
||||
|
||||
public static PassOverride capture() {
|
||||
final SpecialCondition special = GbufferPrograms.getSpecialCondition();
|
||||
final Boolean translucent = GbufferPrograms.getDeclaredTranslucency();
|
||||
final WorldRenderingPhase phase = GbufferPrograms.getOverridePhase();
|
||||
return special == null && translucent == null && phase == null
|
||||
? NONE : new PassOverride(special, translucent, phase);
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
GbufferPrograms.setupSpecialRenderCondition(special);
|
||||
GbufferPrograms.setTranslucencyDeclaration(translucent);
|
||||
GbufferPrograms.setOverridePhase(phase);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
GbufferPrograms.setupSpecialRenderCondition(null);
|
||||
GbufferPrograms.setTranslucencyDeclaration(null);
|
||||
GbufferPrograms.setOverridePhase(null);
|
||||
}
|
||||
|
||||
public boolean isEntityPhase() {
|
||||
return phase == WorldRenderingPhase.ENTITIES;
|
||||
}
|
||||
|
||||
public String nameSuffix() {
|
||||
if (special == null && translucent == null && phase == null) {
|
||||
return "";
|
||||
}
|
||||
return "_" + (special == null ? "plain" : special.name().toLowerCase(Locale.ROOT))
|
||||
+ (translucent == null ? "" : (translucent ? "_translucent" : "_opaque"))
|
||||
+ (phase == null ? "" : "_" + phase.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.shader.Framebuffer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
@@ -83,6 +84,11 @@ public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeli
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeclaredTranslucency(@Nullable Boolean translucent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderTargetStateListener getRenderTargetStateListener() {
|
||||
return RenderTargetStateListener.NOP;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.coderbot.iris.pipeline;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Camera;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.GameModeUtil;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.InteractionHand;
|
||||
import com.gtnewhorizons.angelica.event.RenderHandEvent;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ItemRendererAccessor;
|
||||
import com.gtnewhorizons.angelica.rendering.RenderingState;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.BlockRenderLayer;
|
||||
import lombok.Getter;
|
||||
@@ -83,96 +85,133 @@ public class HandRenderer {
|
||||
!RenderHandEvent.post();
|
||||
}
|
||||
|
||||
public boolean isHandTranslucent(InteractionHand hand) {
|
||||
ItemStack heldItem = hand.getItemInHand(Minecraft.getMinecraft().thePlayer);
|
||||
|
||||
public boolean isItemTranslucent(ItemStack heldItem) {
|
||||
if (heldItem == null) return false;
|
||||
final Item item = heldItem.getItem();
|
||||
|
||||
if (item instanceof ItemBlock itemBlock) {
|
||||
final Block block = itemBlock.field_150939_a;
|
||||
if (block == null) return false;
|
||||
|
||||
final Map<Block, BlockRenderLayer> blockTypeIds = BlockRenderingSettings.INSTANCE.getBlockTypeIds();
|
||||
return blockTypeIds != null && blockTypeIds.get(itemBlock.field_150939_a) == BlockRenderLayer.TRANSLUCENT;
|
||||
final BlockRenderLayer override = blockTypeIds != null ? blockTypeIds.get(block) : null;
|
||||
final BlockRenderLayer layer = override != null ? override : BlockRenderLayer.fromVanillaPass(block.getRenderBlockPass());
|
||||
return layer == BlockRenderLayer.TRANSLUCENT;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isHandTranslucent(InteractionHand hand) {
|
||||
return isItemTranslucent(hand.getItemInHand(Minecraft.getMinecraft().thePlayer));
|
||||
}
|
||||
|
||||
private ItemStack mainHandItem() {
|
||||
return ((ItemRendererAccessor) Minecraft.getMinecraft().entityRenderer.itemRenderer).angelica$getItemToRender();
|
||||
}
|
||||
|
||||
public boolean isAnyHandTranslucent() {
|
||||
return isHandTranslucent(InteractionHand.MAIN_HAND) || isHandTranslucent(InteractionHand.OFF_HAND);
|
||||
return isItemTranslucent(mainHandItem())
|
||||
|| (ModStatus.isBackhandLoaded && isHandTranslucent(InteractionHand.OFF_HAND));
|
||||
}
|
||||
|
||||
public boolean isAnyHandSolid() {
|
||||
return !(isItemTranslucent(mainHandItem())
|
||||
&& (!ModStatus.isBackhandLoaded || isHandTranslucent(InteractionHand.OFF_HAND)));
|
||||
}
|
||||
|
||||
public void renderSolid(float tickDelta, Camera camera, RenderGlobal gameRenderer, WorldRenderingPipeline pipeline) {
|
||||
if (!canRender(camera, gameRenderer) || !IrisApi.getInstance().isShaderPackInUse()) {
|
||||
if (!IrisApi.getInstance().isShaderPackInUse() || !canRender(camera, gameRenderer) || !isAnyHandSolid()) {
|
||||
return;
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
ACTIVE = true;
|
||||
|
||||
final int blendSave = GbufferPrograms.pushBlendState();
|
||||
final long cutoutSave = GbufferPrograms.pushCutoutDefaults();
|
||||
final boolean depthMaskBefore = GLStateManager.isEffectiveDepthMaskEnabled();
|
||||
|
||||
GLStateManager.disableBlend();
|
||||
GLStateManager.defaultBlendFunc();
|
||||
|
||||
pipeline.setPhase(WorldRenderingPhase.HAND_SOLID);
|
||||
|
||||
GLStateManager.glPushMatrix();
|
||||
GLStateManager.glDepthMask(true); // actually write to the depth buffer, it's normally disabled at this point
|
||||
|
||||
mc.mcProfiler.startSection("iris_hand");
|
||||
try {
|
||||
setupGlState(gameRenderer, camera, tickDelta);
|
||||
|
||||
setupGlState(gameRenderer, camera, tickDelta);
|
||||
GbufferPrograms.setBlockEntityDefaults();
|
||||
|
||||
GbufferPrograms.setBlockEntityDefaults();
|
||||
renderingSolid = true;
|
||||
|
||||
renderingSolid = true;
|
||||
mc.entityRenderer.enableLightmap(tickDelta);
|
||||
mc.entityRenderer.itemRenderer.renderItemInFirstPerson(tickDelta);
|
||||
mc.entityRenderer.disableLightmap(tickDelta);
|
||||
} finally {
|
||||
renderingSolid = false;
|
||||
|
||||
mc.entityRenderer.enableLightmap(tickDelta);
|
||||
mc.entityRenderer.itemRenderer.renderItemInFirstPerson(tickDelta);
|
||||
mc.entityRenderer.disableLightmap(tickDelta);
|
||||
mc.mcProfiler.endSection();
|
||||
|
||||
GLStateManager.defaultBlendFunc();
|
||||
GLStateManager.glDepthMask(false);
|
||||
GLStateManager.glPopMatrix();
|
||||
GLStateManager.glPopMatrix();
|
||||
resetProjectionMatrix();
|
||||
|
||||
mc.mcProfiler.endSection();
|
||||
GLStateManager.glDepthMask(depthMaskBefore);
|
||||
GbufferPrograms.popCutoutDefaults(cutoutSave);
|
||||
GbufferPrograms.popBlendState(blendSave);
|
||||
|
||||
resetProjectionMatrix();
|
||||
pipeline.setPhase(WorldRenderingPhase.NONE);
|
||||
|
||||
renderingSolid = false;
|
||||
|
||||
pipeline.setPhase(WorldRenderingPhase.NONE);
|
||||
|
||||
ACTIVE = false;
|
||||
ACTIVE = false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: RenderType
|
||||
public void renderTranslucent(float tickDelta, Camera camera, RenderGlobal gameRenderer, WorldRenderingPipeline pipeline) {
|
||||
if (!canRender(camera, gameRenderer) || !isAnyHandTranslucent() || !IrisApi.getInstance().isShaderPackInUse()) {
|
||||
if (!IrisApi.getInstance().isShaderPackInUse() || !canRender(camera, gameRenderer) || !isAnyHandTranslucent()) {
|
||||
return;
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
ACTIVE = true;
|
||||
|
||||
final int blendSave = GbufferPrograms.pushBlendState();
|
||||
final long cutoutSave = GbufferPrograms.pushCutoutDefaults();
|
||||
final boolean depthMaskBefore = GLStateManager.isEffectiveDepthMaskEnabled();
|
||||
|
||||
GLStateManager.enableBlend();
|
||||
GLStateManager.defaultBlendFunc();
|
||||
|
||||
pipeline.setPhase(WorldRenderingPhase.HAND_TRANSLUCENT);
|
||||
|
||||
GLStateManager.glPushMatrix();
|
||||
GLStateManager.glDepthMask(false);
|
||||
|
||||
mc.mcProfiler.startSection("iris_hand_translucent");
|
||||
try {
|
||||
setupGlState(gameRenderer, camera, tickDelta);
|
||||
|
||||
setupGlState(gameRenderer, camera, tickDelta);
|
||||
GbufferPrograms.setBlockEntityDefaults();
|
||||
|
||||
GbufferPrograms.setBlockEntityDefaults();
|
||||
mc.entityRenderer.enableLightmap(tickDelta);
|
||||
mc.entityRenderer.itemRenderer.renderItemInFirstPerson(tickDelta);
|
||||
mc.entityRenderer.disableLightmap(tickDelta);
|
||||
} finally {
|
||||
mc.mcProfiler.endSection();
|
||||
|
||||
mc.entityRenderer.enableLightmap(tickDelta);
|
||||
mc.entityRenderer.itemRenderer.renderItemInFirstPerson(tickDelta);
|
||||
mc.entityRenderer.disableLightmap(tickDelta);
|
||||
GLStateManager.glPopMatrix();
|
||||
resetProjectionMatrix();
|
||||
|
||||
GLStateManager.glPopMatrix();
|
||||
GLStateManager.glDepthMask(depthMaskBefore);
|
||||
GbufferPrograms.popCutoutDefaults(cutoutSave);
|
||||
GbufferPrograms.popBlendState(blendSave);
|
||||
|
||||
resetProjectionMatrix();
|
||||
pipeline.setPhase(WorldRenderingPhase.NONE);
|
||||
|
||||
Minecraft.getMinecraft().mcProfiler.endSection();
|
||||
|
||||
pipeline.setPhase(WorldRenderingPhase.NONE);
|
||||
|
||||
ACTIVE = false;
|
||||
ACTIVE = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void resetProjectionMatrix() {
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.gtnewhorizons.angelica.rendering.RenderingState;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.AngelicaRenderSectionManager;
|
||||
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasWorldRenderer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import lombok.Setter;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.compat.dh.DHCompat;
|
||||
import net.coderbot.iris.gui.option.IrisVideoSettings;
|
||||
@@ -106,7 +107,8 @@ public class ShadowRenderer {
|
||||
private final ShadowCullState packCullingState;
|
||||
private final ShadowCompositeRenderer compositeRenderer;
|
||||
private boolean packHasVoxelization;
|
||||
private boolean playerReflectionCaptureEnabled = true;
|
||||
@Setter
|
||||
private boolean playerReflectionCaptureEnabled = true;
|
||||
private final boolean shouldRenderTerrain;
|
||||
private final boolean shouldRenderTranslucent;
|
||||
private final boolean shouldRenderEntities;
|
||||
@@ -148,10 +150,19 @@ public class ShadowRenderer {
|
||||
private boolean preSubmitActive;
|
||||
private float preSubmittedShadowAngle = Float.NaN;
|
||||
|
||||
private float shadowAngleDelta() {
|
||||
final Vector4f light = celestialUniforms.getShadowLightPositionInWorldSpace();
|
||||
final float x = light.x(), y = light.y(), z = light.z();
|
||||
final float length = (float) Math.sqrt(x * x + y * y + z * z);
|
||||
return ShadowGraphGate.deltaForElevation(length > 0.0f ? y / length : 1.0f,
|
||||
ShadowGraphGate.degreesToRotation(AngelicaConfig.shadowGraphAngleDelta),
|
||||
AngelicaConfig.shadowGraphHorizonScale);
|
||||
}
|
||||
|
||||
public void preSubmitGraphUpdate(int frame, boolean spectator) {
|
||||
final AngelicaRenderSectionManager rsm = CeleritasWorldRenderer.getInstance().getRenderSectionManager();
|
||||
final float currentShadowAngle = getShadowAngle();
|
||||
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle)) {
|
||||
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle, shadowAngleDelta())) {
|
||||
rsm.markShadowGraphDirty();
|
||||
lastGraphShadowAngle = currentShadowAngle;
|
||||
}
|
||||
@@ -235,13 +246,21 @@ public class ShadowRenderer {
|
||||
|
||||
public void setUsesImages(boolean usesImages) {
|
||||
this.packHasVoxelization = packHasVoxelization || usesImages;
|
||||
this.shadowWritesImages = usesImages;
|
||||
}
|
||||
|
||||
public void setPlayerReflectionCaptureEnabled(boolean enabled) {
|
||||
this.playerReflectionCaptureEnabled = enabled;
|
||||
private boolean shadowWritesImages;
|
||||
|
||||
public boolean shadowTerrainAlwaysRelays() {
|
||||
return !shouldRenderTerrain || voxelizationActive() || shadowWritesImages;
|
||||
}
|
||||
|
||||
public static MatrixStack createShadowModelView(float sunPathRotation, float intervalSize) {
|
||||
public static boolean shadowGraphGateIsNotBypassed() {
|
||||
return !(Iris.getPipelineManager().getPipelineNullable() instanceof DeferredWorldRenderingPipeline deferred)
|
||||
|| deferred.getShadowRenderer() == null || !deferred.getShadowRenderer().shadowTerrainAlwaysRelays();
|
||||
}
|
||||
|
||||
public static MatrixStack createShadowModelView(float sunPathRotation, float intervalSize) {
|
||||
// Use entity position for shadow matrix
|
||||
final Vector3d entityPos = Camera.INSTANCE.getEntityPos();
|
||||
|
||||
@@ -833,7 +852,7 @@ public class ShadowRenderer {
|
||||
globalTileEntities.clear();
|
||||
|
||||
final float currentShadowAngle = getShadowAngle();
|
||||
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle)) {
|
||||
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle, shadowAngleDelta())) {
|
||||
CeleritasWorldRenderer.getInstance().getRenderSectionManager().markShadowGraphDirty();
|
||||
lastGraphShadowAngle = currentShadowAngle;
|
||||
}
|
||||
@@ -843,8 +862,7 @@ public class ShadowRenderer {
|
||||
final boolean consumePreSubmit = preSubmitActive;
|
||||
preSubmitActive = false;
|
||||
|
||||
final boolean relayTerrain = !deferActive
|
||||
|| voxelizationActive()
|
||||
final boolean relayTerrain = shadowTerrainAlwaysRelays()
|
||||
|| !targets.isTerrainSnapshotValid()
|
||||
|| consumePreSubmit
|
||||
|| CeleritasWorldRenderer.getInstance().getRenderSectionManager().isShadowGraphDirty()
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.coderbot.iris.shaderpack.CloudSetting;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
@@ -31,6 +32,7 @@ public interface WorldRenderingPipeline {
|
||||
void setPhase(WorldRenderingPhase phase);
|
||||
void setInputs(InputAvailability availability);
|
||||
void setSpecialCondition(SpecialCondition special);
|
||||
void setDeclaredTranslucency(@Nullable Boolean translucent);
|
||||
RenderTargetStateListener getRenderTargetStateListener();
|
||||
|
||||
int getCurrentNormalTexture();
|
||||
|
||||
@@ -17,6 +17,8 @@ public class ProgramSet {
|
||||
private final PackDirectives packDirectives;
|
||||
|
||||
private final ProgramSource shadow;
|
||||
private final ProgramSource shadowSolid;
|
||||
private final ProgramSource shadowCutout;
|
||||
private final ProgramSource shadowWater;
|
||||
private final ComputeSource[] shadowCompute;
|
||||
|
||||
@@ -34,6 +36,8 @@ public class ProgramSet {
|
||||
private final ProgramSource gbuffersTextured;
|
||||
private final ProgramSource gbuffersTexturedLit;
|
||||
private final ProgramSource gbuffersTerrain;
|
||||
private final ProgramSource gbuffersTerrainSolid;
|
||||
private final ProgramSource gbuffersTerrainCutout;
|
||||
private ProgramSource gbuffersDamagedBlock;
|
||||
private final ProgramSource gbuffersSkyBasic;
|
||||
private final ProgramSource gbuffersSkyTextured;
|
||||
@@ -43,6 +47,8 @@ public class ProgramSet {
|
||||
private final ProgramSource gbuffersEntitiesTrans;
|
||||
private final ProgramSource gbuffersEntitiesGlowing;
|
||||
private final ProgramSource gbuffersLightning;
|
||||
private final ProgramSource gbuffersParticles;
|
||||
private final ProgramSource gbuffersParticlesTrans;
|
||||
private final ProgramSource gbuffersGlint;
|
||||
private final ProgramSource gbuffersEntityEyes;
|
||||
private final ProgramSource gbuffersBlock;
|
||||
@@ -83,6 +89,10 @@ public class ProgramSet {
|
||||
// - https://github.com/IrisShaders/Iris/issues/987
|
||||
this.shadow = readProgramSource(directory, sourceProvider, "shadow", this, shaderProperties,
|
||||
BlendModeOverride.OFF);
|
||||
this.shadowSolid = readProgramSource(directory, sourceProvider, "shadow_solid", this, shaderProperties,
|
||||
BlendModeOverride.OFF);
|
||||
this.shadowCutout = readProgramSource(directory, sourceProvider, "shadow_cutout", this, shaderProperties,
|
||||
BlendModeOverride.OFF);
|
||||
this.shadowWater = readProgramSource(directory, sourceProvider, "shadow_water", this, shaderProperties,
|
||||
BlendModeOverride.OFF);
|
||||
this.shadowCompute = readComputeArray(directory, sourceProvider, "shadow");
|
||||
@@ -114,6 +124,8 @@ public class ProgramSet {
|
||||
this.gbuffersTextured = readProgramSource(directory, sourceProvider, "gbuffers_textured", this, shaderProperties);
|
||||
this.gbuffersTexturedLit = readProgramSource(directory, sourceProvider, "gbuffers_textured_lit", this, shaderProperties);
|
||||
this.gbuffersTerrain = readProgramSource(directory, sourceProvider, "gbuffers_terrain", this, shaderProperties);
|
||||
this.gbuffersTerrainSolid = readProgramSource(directory, sourceProvider, "gbuffers_terrain_solid", this, shaderProperties);
|
||||
this.gbuffersTerrainCutout = readProgramSource(directory, sourceProvider, "gbuffers_terrain_cutout", this, shaderProperties);
|
||||
this.gbuffersDamagedBlock = readProgramSource(directory, sourceProvider, "gbuffers_damagedblock", this, shaderProperties);
|
||||
this.gbuffersSkyBasic = readProgramSource(directory, sourceProvider, "gbuffers_skybasic", this, shaderProperties);
|
||||
this.gbuffersSkyTextured = readProgramSource(directory, sourceProvider, "gbuffers_skytextured", this, shaderProperties);
|
||||
@@ -123,6 +135,8 @@ public class ProgramSet {
|
||||
this.gbuffersEntitiesTrans = readProgramSource(directory, sourceProvider, "gbuffers_entities_translucent", this, shaderProperties);
|
||||
this.gbuffersEntitiesGlowing = readProgramSource(directory, sourceProvider, "gbuffers_entities_glowing", this, shaderProperties);
|
||||
this.gbuffersLightning = readProgramSource(directory, sourceProvider, "gbuffers_lightning", this, shaderProperties);
|
||||
this.gbuffersParticles = readProgramSource(directory, sourceProvider, "gbuffers_particles", this, shaderProperties);
|
||||
this.gbuffersParticlesTrans = readProgramSource(directory, sourceProvider, "gbuffers_particles_translucent", this, shaderProperties);
|
||||
this.gbuffersGlint = readProgramSource(directory, sourceProvider, "gbuffers_armor_glint", this, shaderProperties);
|
||||
this.gbuffersEntityEyes = readProgramSource(directory, sourceProvider, "gbuffers_spidereyes", this, shaderProperties);
|
||||
this.gbuffersBlock = readProgramSource(directory, sourceProvider, "gbuffers_block", this, shaderProperties);
|
||||
@@ -224,6 +238,8 @@ public class ProgramSet {
|
||||
List<ComputeSource> computes = new ArrayList<>();
|
||||
|
||||
programs.add(shadow);
|
||||
programs.add(shadowSolid);
|
||||
programs.add(shadowCutout);
|
||||
programs.add(shadowWater);
|
||||
programs.addAll(Arrays.asList(shadowcomp));
|
||||
programs.addAll(Arrays.asList(begin));
|
||||
@@ -231,8 +247,9 @@ public class ProgramSet {
|
||||
|
||||
programs.addAll (Arrays.asList(
|
||||
gbuffersBasic, gbuffersBeaconBeam, gbuffersTextured, gbuffersTexturedLit, gbuffersTerrain,
|
||||
gbuffersTerrainSolid, gbuffersTerrainCutout,
|
||||
gbuffersDamagedBlock, gbuffersSkyBasic, gbuffersSkyTextured, gbuffersClouds, gbuffersWeather,
|
||||
gbuffersEntities, gbuffersEntitiesTrans, gbuffersEntitiesGlowing, gbuffersLightning, gbuffersGlint, gbuffersEntityEyes, gbuffersBlock, gbuffersBlockTrans,
|
||||
gbuffersEntities, gbuffersEntitiesTrans, gbuffersEntitiesGlowing, gbuffersLightning, gbuffersParticles, gbuffersParticlesTrans, gbuffersGlint, gbuffersEntityEyes, gbuffersBlock, gbuffersBlockTrans,
|
||||
gbuffersHand, dhShadow, dhTerrain, dhGeneric, dhWater
|
||||
));
|
||||
|
||||
@@ -309,6 +326,14 @@ public class ProgramSet {
|
||||
return shadow.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getShadowSolid() {
|
||||
return shadowSolid.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getShadowCutout() {
|
||||
return shadowCutout.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getShadowWater() {
|
||||
return shadowWater.requireValid();
|
||||
}
|
||||
@@ -353,6 +378,14 @@ public class ProgramSet {
|
||||
return gbuffersTerrain.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getGbuffersTerrainSolid() {
|
||||
return gbuffersTerrainSolid.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getGbuffersTerrainCutout() {
|
||||
return gbuffersTerrainCutout.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getGbuffersDamagedBlock() {
|
||||
return gbuffersDamagedBlock.requireValid();
|
||||
}
|
||||
@@ -389,6 +422,14 @@ public class ProgramSet {
|
||||
return gbuffersLightning.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getGbuffersParticles() {
|
||||
return gbuffersParticles.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getGbuffersParticlesTrans() {
|
||||
return gbuffersParticlesTrans.requireValid();
|
||||
}
|
||||
|
||||
public Optional<ProgramSource> getGbuffersGlint() {
|
||||
return gbuffersGlint.requireValid();
|
||||
}
|
||||
@@ -428,6 +469,8 @@ public class ProgramSet {
|
||||
public Optional<ProgramSource> get(ProgramId programId) {
|
||||
return switch (programId) {
|
||||
case Shadow -> getShadow();
|
||||
case ShadowSolid -> getShadowSolid();
|
||||
case ShadowCutout -> getShadowCutout();
|
||||
case ShadowWater -> first(getShadowWater(), getShadow());
|
||||
case Basic -> getGbuffersBasic();
|
||||
case Line -> gbuffersLine.requireValid();
|
||||
@@ -437,6 +480,8 @@ public class ProgramSet {
|
||||
case SkyTextured -> getGbuffersSkyTextured();
|
||||
case Clouds -> getGbuffersClouds();
|
||||
case Terrain -> getGbuffersTerrain();
|
||||
case TerrainSolid -> getGbuffersTerrainSolid();
|
||||
case TerrainCutout -> getGbuffersTerrainCutout();
|
||||
case DamagedBlock -> getGbuffersDamagedBlock();
|
||||
case Block -> getGbuffersBlock();
|
||||
case BlockTrans -> getGbuffersBlockTrans();
|
||||
@@ -445,6 +490,8 @@ public class ProgramSet {
|
||||
case EntitiesTrans -> getGbuffersEntitiesTrans();
|
||||
case EntitiesGlowing -> getGbuffersEntitiesGlowing();
|
||||
case Lightning -> getGbuffersLightning();
|
||||
case Particles -> getGbuffersParticles();
|
||||
case ParticlesTrans -> getGbuffersParticlesTrans();
|
||||
case ArmorGlint -> getGbuffersGlint();
|
||||
case SpiderEyes -> getGbuffersEntityEyes();
|
||||
case Hand -> getGbuffersHand();
|
||||
|
||||
@@ -27,7 +27,9 @@ public enum ProgramId {
|
||||
|
||||
Terrain(ProgramGroup.Gbuffers, "terrain", TexturedLit),
|
||||
TerrainSolid(ProgramGroup.Gbuffers, "terrain_solid", Terrain),
|
||||
TerrainCutoutMip(ProgramGroup.Gbuffers, "terrain_cutout_mip", Terrain),
|
||||
// terrain_cutout_mip program was removed in modern versions of Minecraft. As the goal is to be a faithful backport of Iris
|
||||
// we likely should just group cutout and cutout mipped into the same program.
|
||||
// CUTOUT_MIPPED essentially became CUTOUT and now everything uses mipmaps in modern. We don't as of writing.
|
||||
TerrainCutout(ProgramGroup.Gbuffers, "terrain_cutout", Terrain),
|
||||
DamagedBlock(ProgramGroup.Gbuffers, "damagedblock", Terrain),
|
||||
|
||||
@@ -40,6 +42,8 @@ public enum ProgramId {
|
||||
EntitiesTrans(ProgramGroup.Gbuffers, "entities_translucent", Entities),
|
||||
EntitiesGlowing(ProgramGroup.Gbuffers, "entities_glowing", Entities),
|
||||
Lightning(ProgramGroup.Gbuffers, "lightning", Entities),
|
||||
Particles(ProgramGroup.Gbuffers, "particles", TexturedLit),
|
||||
ParticlesTrans(ProgramGroup.Gbuffers, "particles_translucent", Particles),
|
||||
ArmorGlint(ProgramGroup.Gbuffers, "armor_glint", Textured),
|
||||
SpiderEyes(ProgramGroup.Gbuffers, "spidereyes", Textured,
|
||||
new BlendModeOverride(new BlendState(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO, GL11.GL_ONE)),
|
||||
|
||||
@@ -82,6 +82,10 @@ public class OptionMenuContainer {
|
||||
|
||||
// Screens will call this when they contain a "*" element, so that the list of
|
||||
// unused options can be added after all other screens have been resolved
|
||||
public boolean hasMenuElements() {
|
||||
return !this.originalMainElements.isEmpty();
|
||||
}
|
||||
|
||||
public void queueForUnusedOptionDump(int index, List<OptionMenuElement> elementList) {
|
||||
this.unusedOptionDumpQueue.put(elementList, index);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,24 @@ package net.coderbot.iris.shadows;
|
||||
|
||||
public final class ShadowGraphGate {
|
||||
|
||||
public static final float SHADOW_ANGLE_GRAPH_DELTA = 0.0005f;
|
||||
public static final float DEFAULT_ANGLE_DELTA_DEGREES = 0.03f;
|
||||
|
||||
public static final float DEFAULT_HORIZON_SCALE = 0.5f;
|
||||
|
||||
private ShadowGraphGate() {}
|
||||
|
||||
public static boolean shouldMarkDirty(float last, float current) {
|
||||
float delta = current - last;
|
||||
if (delta > 0.5f) delta -= 1.0f;
|
||||
if (delta < -0.5f) delta += 1.0f;
|
||||
return Float.isNaN(last) || Math.abs(delta) > SHADOW_ANGLE_GRAPH_DELTA;
|
||||
public static float degreesToRotation(float degrees) {
|
||||
return degrees / 360.0f;
|
||||
}
|
||||
|
||||
public static boolean shouldMarkDirty(float last, float current, float delta) {
|
||||
float d = current - last;
|
||||
if (d > 0.5f) d -= 1.0f;
|
||||
if (d < -0.5f) d += 1.0f;
|
||||
return Float.isNaN(last) || Math.abs(d) > delta;
|
||||
}
|
||||
|
||||
public static float deltaForElevation(float sinElevation, float baseDelta, float minElevationScale) {
|
||||
return baseDelta * Math.max(minElevationScale, sinElevation * sinElevation);
|
||||
}
|
||||
}
|
||||
@@ -54,13 +54,20 @@ public class CapturedRenderingState {
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentEntity(int entity) {
|
||||
private void setCurrentEntity(int entity) {
|
||||
this.currentRenderedEntity = entity;
|
||||
|
||||
if (this.entityIdListener != null) {
|
||||
this.entityIdListener.run();
|
||||
}
|
||||
setCurrentRenderedItem(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* I should have done this a while ago, better solution to not forget these exist in tandem.
|
||||
*/
|
||||
public void setCurrentEntityAndItem(int entity, int item) {
|
||||
setCurrentEntity(entity);
|
||||
setCurrentRenderedItem(item);
|
||||
}
|
||||
|
||||
public void setCurrentEntityColor(float r, float g, float b, float a) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_FRAME;
|
||||
import static org.joml.Math.clamp;
|
||||
|
||||
public final class IdMapUniforms {
|
||||
|
||||
@@ -71,6 +72,13 @@ public final class IdMapUniforms {
|
||||
lightValue = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Damn you chisel beacon
|
||||
*/
|
||||
private static int clampEmission(int emission) {
|
||||
return clamp(0, 15, emission);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
|
||||
@@ -98,7 +106,7 @@ public final class IdMapUniforms {
|
||||
intID = itemIdMap.applyAsInt(new NamespacedId(heldItemId.getResourceDomain(), heldItemId.getResourcePath()));
|
||||
|
||||
IrisItemLightProvider lightProvider = (IrisItemLightProvider) heldItem;
|
||||
lightValue = lightProvider.getLightEmission(Minecraft.getMinecraft().thePlayer, heldStack);
|
||||
lightValue = clampEmission(lightProvider.getLightEmission(Minecraft.getMinecraft().thePlayer, heldStack));
|
||||
|
||||
if (applyOldHandLight) {
|
||||
lightProvider = applyOldHandLighting(player, lightProvider);
|
||||
@@ -119,7 +127,7 @@ public final class IdMapUniforms {
|
||||
}
|
||||
|
||||
IrisItemLightProvider lightProvider = (IrisItemLightProvider) offHandItem;
|
||||
int newEmission = lightProvider.getLightEmission(Minecraft.getMinecraft().thePlayer, offHandStack);
|
||||
int newEmission = clampEmission(lightProvider.getLightEmission(Minecraft.getMinecraft().thePlayer, offHandStack));
|
||||
|
||||
if (lightValue < newEmission) {
|
||||
lightValue = newEmission;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ItemIdManager {
|
||||
* Set the item ID for a Block rendered outside of terrain.
|
||||
*/
|
||||
public static void setBlockId(Block block, int metadata) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(Math.max(0, ItemMaterialHelper.getMaterialId(block, metadata)));
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(ItemMaterialHelper.getMaterialId(block, metadata));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,15 +27,13 @@ public class ItemMaterialHelper {
|
||||
|
||||
/**
|
||||
* Get the material ID for an ItemStack.
|
||||
* For ItemBlock: checks block.properties first, then item.properties.
|
||||
* For other items: checks item.properties only.
|
||||
* 0 if unmapped.
|
||||
*
|
||||
* @param itemStack The item stack to get material ID for
|
||||
* @return The material ID, or -1 if not found
|
||||
*/
|
||||
public static int getMaterialId(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check item NBT conditions first
|
||||
@@ -56,7 +54,7 @@ public class ItemMaterialHelper {
|
||||
|
||||
public static int getMaterialId(Item item, int metadata) {
|
||||
if (item == null) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check cache first
|
||||
@@ -84,11 +82,11 @@ public class ItemMaterialHelper {
|
||||
/**
|
||||
* Get the material ID for a Block rendered outside of terrain.
|
||||
*
|
||||
* @return The material ID, or -1 if not found
|
||||
* @return The material ID, or 0 if not found
|
||||
*/
|
||||
public static int getMaterialId(Block block, int metadata) {
|
||||
if (block == null) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Int2IntMap metadataCache = BLOCK_MATERIAL_CACHE.get(block);
|
||||
@@ -112,60 +110,44 @@ public class ItemMaterialHelper {
|
||||
}
|
||||
|
||||
private static int lookupBlockMaterialId(Block block, int metadata) {
|
||||
Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
|
||||
if (blockMetaMatches != null) {
|
||||
Int2IntMap metaMap = blockMetaMatches.get(block);
|
||||
if (metaMap != null) {
|
||||
int id = BlockMaterialMapping.resolveId(metaMap, metadata);
|
||||
if (id != -1) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Item item = Item.getItemFromBlock(block);
|
||||
return item != null ? lookupItemPropertiesId(item) : -1;
|
||||
return lookupBlockPropertiesId(block, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual material ID lookup without caching.
|
||||
*
|
||||
* For block items (ItemBlock): use block.properties first, then fall back to item.properties.
|
||||
* For non-block items: use item.properties only.
|
||||
*
|
||||
* This matches modern Iris behavior where block items use block IDs and non-block items use item IDs.
|
||||
*/
|
||||
private static int lookupMaterialId(Item item, int metadata) {
|
||||
// For ItemBlock: check block.properties first
|
||||
if (item instanceof ItemBlock itemBlock) {
|
||||
final Block block = itemBlock.field_150939_a; // The block this item places
|
||||
|
||||
if (block != null) {
|
||||
Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
|
||||
if (blockMetaMatches != null) {
|
||||
Int2IntMap metaMap = blockMetaMatches.get(block);
|
||||
if (metaMap != null) {
|
||||
int id = BlockMaterialMapping.resolveId(metaMap, itemBlock.getMetadata(metadata));
|
||||
if (id != -1) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return block == null ? 0 : lookupBlockPropertiesId(block, itemBlock.getMetadata(metadata));
|
||||
}
|
||||
|
||||
// Fall back to item.properties
|
||||
return lookupItemPropertiesId(item);
|
||||
}
|
||||
|
||||
private static int lookupBlockPropertiesId(Block block, int metadata) {
|
||||
final Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
|
||||
if (blockMetaMatches == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final Int2IntMap metaMap = blockMetaMatches.get(block);
|
||||
if (metaMap == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final int id = BlockMaterialMapping.resolveId(metaMap, metadata);
|
||||
return id == -1 ? 0 : id;
|
||||
}
|
||||
|
||||
private static int lookupItemPropertiesId(Item item) {
|
||||
final Object2IntFunction<NamespacedId> itemIds = BlockRenderingSettings.INSTANCE.getItemIds();
|
||||
if (itemIds == null) {
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
final NamespacedId name = getCachedItemName(item);
|
||||
return name == null ? -1 : itemIds.applyAsInt(name);
|
||||
return name == null ? 0 : itemIds.applyAsInt(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user