mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-17 19:15:06 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f79ad7f22a | ||
|
|
6947ffa3e2 | ||
|
|
969d2c3710 | ||
|
|
c5988d29c3 | ||
|
|
dc68c2c265 | ||
|
|
51533a81ec | ||
|
|
90eabb5d40 | ||
|
|
74843cb1f9 | ||
|
|
5e0344a529 | ||
|
|
3cdd934987 | ||
|
|
9d90ff137c | ||
|
|
bee9541797 | ||
|
|
b75a5d8f7d |
No files matched your search
+2
-1
@@ -73,7 +73,7 @@ dependencies {
|
||||
compileOnly('org.jetbrains:annotations:26.0.2')
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.9.6:dev")
|
||||
shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0
|
||||
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-25.g3a943bb") {
|
||||
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-26.g5ee7d96-GTNH") {
|
||||
exclude module: "antlr4" // we only want to shadow the runtime module
|
||||
}
|
||||
shadowImplementation("org.antlr:antlr4-runtime:4.13.2")
|
||||
@@ -115,6 +115,7 @@ dependencies {
|
||||
compileOnly(rfg.deobf("curse.maven:campfirebackport-387444:4611675"))
|
||||
compileOnly(rfg.deobf("curse.maven:xaeros-minimap-263420:5060684"))
|
||||
compileOnly(rfg.deobf("curse.maven:security-craft-64760:2818228"))
|
||||
compileOnly(rfg.deobf("curse.maven:et-futurum-requiem-441392:5873837"))
|
||||
|
||||
// runtimeOnlyNonPublishable("com.github.GTNewHorizons:CoreTweaks:0.3.3.6-GTNH")
|
||||
// For testing alternative splash screens, can be sourced from https://github.com/MalTeeez/ModernSplash/releases
|
||||
|
||||
@@ -72,7 +72,6 @@ public class FontStrategist {
|
||||
DefaultResourcePack fontResourcePack = new DefaultResourcePack(packMap);
|
||||
List defaultResourcePacks = ((ResourceAccessor) Minecraft.getMinecraft()).angelica$getDefaultResourcePacks();
|
||||
defaultResourcePacks.add(fontResourcePack);
|
||||
Minecraft.getMinecraft().refreshResources();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -114,7 +114,7 @@ public class ModdedBiomeDetector {
|
||||
}
|
||||
|
||||
// lotr
|
||||
if (lotrBiomeClass.isInstance(biome)) {
|
||||
if (lotrBiomeClass!= null && lotrBiomeClass.isInstance(biome)) {
|
||||
return detectLOTRBiome(biome);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,10 @@ public class AngelicaConfig {
|
||||
@Config.DefaultBoolean(false)
|
||||
public static boolean enableHardcodedCustomUniforms;
|
||||
|
||||
@Config.Comment("Define IS_IRIS in shader macros.")
|
||||
@Config.DefaultBoolean(true)
|
||||
public static boolean defineIsIris;
|
||||
|
||||
@Config.Comment("Renders chunks before neighbors are ready. Improves loading at render distance edges, useful for low render distance servers.")
|
||||
@Config.DefaultBoolean(false)
|
||||
public static boolean useVanillaChunkTracking;
|
||||
|
||||
@@ -44,6 +44,7 @@ public class RenderSystem {
|
||||
private static boolean supportsSSBO;
|
||||
private static boolean supportsBufferStorage;
|
||||
private static boolean supportsClearTexture;
|
||||
private static boolean supportsTesselation;
|
||||
private static boolean supportsSamplerObjects;
|
||||
private static int maxImageUnits;
|
||||
private static int maxSSBOBindings;
|
||||
@@ -73,6 +74,7 @@ public class RenderSystem {
|
||||
}
|
||||
|
||||
supportsCompute = supportsCompute();
|
||||
supportsTesselation = GLStateManager.capabilities.GL_ARB_tessellation_shader || GLStateManager.capabilities.OpenGL40;
|
||||
|
||||
supportsImageLoadStore = GLStateManager.capabilities.OpenGL42 || GLStateManager.capabilities.GL_ARB_shader_image_load_store || GLStateManager.capabilities.GL_EXT_shader_image_load_store;
|
||||
supportsSSBO = GLStateManager.capabilities.OpenGL43 || GLStateManager.capabilities.GL_ARB_shader_storage_buffer_object;
|
||||
@@ -447,6 +449,10 @@ public class RenderSystem {
|
||||
dsaState.textureStorage3D(texture, target, levels, internalFormat, width, height, depth);
|
||||
}
|
||||
|
||||
public static boolean supportsTesselation() {
|
||||
return supportsTesselation;
|
||||
}
|
||||
|
||||
public static boolean supportsSamplerObjects() {
|
||||
return supportsSamplerObjects;
|
||||
}
|
||||
|
||||
+21
-9
@@ -41,6 +41,7 @@ public final class AngelicaRedirector {
|
||||
private static final String Drawable = "org/lwjgl/opengl/Drawable";
|
||||
private static final String GLStateManager = "com/gtnewhorizons/angelica/glsm/GLStateManager";
|
||||
private static final String GL11 = "org/lwjgl/opengl/GL11";
|
||||
private static final String GL11C = "org/lwjgl/opengl/GL11C";
|
||||
private static final String GL12 = "org/lwjgl/opengl/GL12";
|
||||
private static final String GL13 = "org/lwjgl/opengl/GL13";
|
||||
private static final String GL14 = "org/lwjgl/opengl/GL14";
|
||||
@@ -250,6 +251,14 @@ public final class AngelicaRedirector {
|
||||
methodRedirects.put(EXTBlendFunc, RedirectMap.newMap().add("glBlendFuncSeparateEXT", "tryBlendFuncSeparate"));
|
||||
methodRedirects.put(ARBMultiTexture, RedirectMap.newMap().add("glActiveTextureARB"));
|
||||
methodRedirects.put(Project, RedirectMap.newMap().add("gluPerspective"));
|
||||
|
||||
final String glPrefix = "org/lwjgl/opengl/GL";
|
||||
for (var entry : new HashMap<>(methodRedirects).entrySet()) {
|
||||
if (entry.getKey().startsWith(glPrefix)) {
|
||||
methodRedirects.put(entry.getKey() + "C", entry.getValue());
|
||||
cstPoolParser.addString(entry.getKey() + "C");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getTransformerExclusions() {
|
||||
@@ -280,7 +289,7 @@ public final class AngelicaRedirector {
|
||||
boolean redirectInMethod = false;
|
||||
for (AbstractInsnNode node : mn.instructions.toArray()) {
|
||||
if (node instanceof MethodInsnNode mNode) {
|
||||
if (mNode.owner.equals(GL11) && (mNode.name.equals("glEnable") || mNode.name.equals("glDisable")) && mNode.desc.equals("(I)V")) {
|
||||
if ((mNode.owner.equals(GL11) || mNode.owner.equals(GL11C)) && (mNode.name.equals("glEnable") || mNode.name.equals("glDisable")) && mNode.desc.equals("(I)V")) {
|
||||
final AbstractInsnNode prevNode = node.getPrevious();
|
||||
String name = null;
|
||||
if (prevNode instanceof LdcInsnNode ldcNode) {
|
||||
@@ -321,15 +330,18 @@ public final class AngelicaRedirector {
|
||||
}
|
||||
} else {
|
||||
final Map<String, String> redirects = methodRedirects.get(mNode.owner);
|
||||
if (redirects != null && redirects.containsKey(mNode.name)) {
|
||||
if (LOG_SPAM) {
|
||||
final String shortOwner = mNode.owner.substring(mNode.owner.lastIndexOf("/") + 1);
|
||||
LOGGER.info("Redirecting call in {} from {}.{}{} to GLStateManager.{}{}", transformedName, shortOwner, mNode.name, mNode.desc, redirects.get(mNode.name), mNode.desc);
|
||||
if (redirects != null) {
|
||||
final String glsmName = redirects.get(mNode.name);
|
||||
if (glsmName != null) {
|
||||
if (LOG_SPAM) {
|
||||
final String shortOwner = mNode.owner.substring(mNode.owner.lastIndexOf("/") + 1);
|
||||
LOGGER.info("Redirecting call in {} from {}.{}{} to GLStateManager.{}{}", transformedName, shortOwner, mNode.name, mNode.desc, glsmName, mNode.desc);
|
||||
}
|
||||
mNode.owner = GLStateManager;
|
||||
mNode.name = glsmName;
|
||||
changed = true;
|
||||
redirectInMethod = true;
|
||||
}
|
||||
mNode.owner = GLStateManager;
|
||||
mNode.name = redirects.get(mNode.name);
|
||||
changed = true;
|
||||
redirectInMethod = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,8 @@ public enum Mixins implements IMixins {
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris)
|
||||
.addClientMixins(
|
||||
"shaders.MixinEntityPickupFX"
|
||||
"shaders.MixinDroppedItemGlintEdges"
|
||||
, "shaders.MixinEntityPickupFX"
|
||||
, "shaders.MixinEntityRenderer"
|
||||
, "shaders.MixinGuiIngameForge"
|
||||
, "shaders.MixinFramebuffer"
|
||||
@@ -204,6 +205,7 @@ public enum Mixins implements IMixins {
|
||||
, "shaders.MixinLocale"
|
||||
, "shaders.MixinRender"
|
||||
, "shaders.MixinRenderBiped"
|
||||
, "shaders.MixinRenderDragon"
|
||||
, "shaders.MixinRenderEntityFlame"
|
||||
, "shaders.MixinRendererLivingEntity"
|
||||
, "shaders.MixinRenderGlobal"
|
||||
@@ -213,6 +215,8 @@ public enum Mixins implements IMixins {
|
||||
, "shaders.MixinRenderNameTag"
|
||||
, "shaders.MixinRenderPlayerArmor"
|
||||
, "shaders.MixinTileEntityBeaconRenderer"
|
||||
, "shaders.MixinRenderEndPortal"
|
||||
, "shaders.MixinTileEntityRendererDispatcher"
|
||||
)
|
||||
),
|
||||
|
||||
@@ -451,6 +455,12 @@ public enum Mixins implements IMixins {
|
||||
"MixinBlockTFMagicLeaves"
|
||||
))
|
||||
),
|
||||
ET_FUTURUM_ELYTRA_CAPE(new MixinBuilder("Set custom item ID for elytra with cape texture")
|
||||
.setPhase(Phase.LATE)
|
||||
.addRequiredMod(TargetedMod.ET_FUTURUM_REQUIEM)
|
||||
.setApplyIf(() -> AngelicaConfig.enableIris)
|
||||
.addClientMixins("client.etfuturum.MixinLayerBetterElytra")
|
||||
),
|
||||
MCPATCHER_FORGE(new MixinBuilder()
|
||||
.setPhase(Phase.EARLY)
|
||||
.setApplyIf(() -> AngelicaConfig.enableMCPatcherForgeFeatures)
|
||||
|
||||
@@ -14,6 +14,7 @@ public enum TargetedMod implements ITargetMod {
|
||||
DYNAMIC_SURROUNDINGS_MIST("org.blockartistry.mod.DynSurround.mixinplugin.DynamicSurroundingsEarlyMixins", "dsurround"),
|
||||
DYNAMIC_SURROUNDINGS_ORIGINAL("org.blockartistry.mod.DynSurround.asm.TransformLoader", "dsurround"),
|
||||
DRAGON_API("Reika.DragonAPI.Auxiliary.DragonAPIASMHandler", "DragonAPI"),
|
||||
ET_FUTURUM_REQUIEM(null, "etfuturum"),
|
||||
EXTRAUTILS(null, "ExtraUtilities"),
|
||||
FALSETWEAKS("com.falsepattern.falsetweaks.asm.CoreLoadingPlugin", "falsetweaks"),
|
||||
MINEFACTORY_RELOADED(null, "MineFactoryReloaded"),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.prupe.mcpatcher.ctm;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
@@ -8,6 +9,9 @@ import com.prupe.mcpatcher.mal.block.BlockStateMatcher;
|
||||
|
||||
final class BlockOrientation extends RenderBlockState {
|
||||
|
||||
private static final boolean fixedBottomFaceUV = (boolean) Launch.blackboard
|
||||
.getOrDefault("hodgepodge.FixesConfig.fixBottomFaceUV", Boolean.FALSE);
|
||||
|
||||
// NEIGHBOR_OFFSETS[a][b][c] = offset from starting block
|
||||
// a: face 0-5
|
||||
// b: neighbor 0-7
|
||||
@@ -16,7 +20,11 @@ final class BlockOrientation extends RenderBlockState {
|
||||
// 1 2 3
|
||||
// c: coordinate (x,y,z) 0-2
|
||||
private static final int[][][] NEIGHBOR_OFFSET = new int[][][] {
|
||||
makeNeighborOffset(WEST_FACE, SOUTH_FACE, EAST_FACE, NORTH_FACE), // BOTTOM_FACE
|
||||
(
|
||||
fixedBottomFaceUV
|
||||
? makeNeighborOffset(EAST_FACE, SOUTH_FACE, WEST_FACE, NORTH_FACE) // BOTTOM_FACE fixedBottomFaceUV
|
||||
: makeNeighborOffset(WEST_FACE, SOUTH_FACE, EAST_FACE, NORTH_FACE) // BOTTOM_FACE not fixed
|
||||
),
|
||||
makeNeighborOffset(WEST_FACE, SOUTH_FACE, EAST_FACE, NORTH_FACE), // TOP_FACE
|
||||
makeNeighborOffset(EAST_FACE, BOTTOM_FACE, WEST_FACE, TOP_FACE), // NORTH_FACE
|
||||
makeNeighborOffset(WEST_FACE, BOTTOM_FACE, EAST_FACE, TOP_FACE), // SOUTH_FACE
|
||||
|
||||
@@ -8,6 +8,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import jss.notfine.gui.GuiCustomMenu;
|
||||
import jss.notfine.gui.NotFineGameOptionPages;
|
||||
import me.flashyreese.mods.reeses_sodium_options.client.gui.ReeseSodiumVideoOptionsScreen;
|
||||
import me.jellysquid.mods.sodium.client.SodiumClientMod;
|
||||
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -21,6 +22,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
// FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
SodiumClientMod.options();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.coderbot.iris.gl.program.ProgramUniforms;
|
||||
import net.coderbot.iris.pipeline.PatchedShaderPrinter;
|
||||
import net.coderbot.iris.pipeline.transform.PatchShaderType;
|
||||
import net.coderbot.iris.rendertarget.RenderTargets;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.uniforms.CommonUniforms;
|
||||
import net.coderbot.iris.uniforms.builtin.BuiltinReplacementUniforms;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
@@ -146,7 +147,7 @@ public class CeleritasTerrainPipeline {
|
||||
public ProgramUniforms.Builder initUniforms(int programId) {
|
||||
final ProgramUniforms.Builder uniforms = ProgramUniforms.builder("<celeritas shaders>", programId);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(uniforms);
|
||||
CommonUniforms.addDynamicUniforms(uniforms, FogMode.PER_VERTEX);
|
||||
customUniforms.assignTo(uniforms);
|
||||
|
||||
BuiltinReplacementUniforms.addBuiltinReplacementUniforms(uniforms);
|
||||
|
||||
@@ -15,6 +15,10 @@ public enum FeatureFlags {
|
||||
BLOCK_EMISSION_ATTRIBUTE(() -> true, () -> true),
|
||||
CUSTOM_IMAGES(() -> true, RenderSystem::supportsImageLoadStore),
|
||||
SSBO(() -> true, RenderSystem::supportsSSBO),
|
||||
HIGHER_SHADOWCOLOR(() -> true, () -> true),
|
||||
TESSELLATION_SHADERS(() -> true, RenderSystem::supportsTesselation),
|
||||
REVERSED_CULLING(() -> true, () -> true),
|
||||
CAN_DISABLE_WEATHER(() -> true, () -> true),
|
||||
UNKNOWN(() -> false, () -> false);
|
||||
|
||||
private final BooleanSupplier irisRequirement;
|
||||
@@ -55,16 +59,16 @@ public enum FeatureFlags {
|
||||
}
|
||||
|
||||
public static boolean isInvalid(String name) {
|
||||
try {
|
||||
return !FeatureFlags.valueOf(name).isUsable();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return true;
|
||||
}
|
||||
FeatureFlags flag = getValue(name);
|
||||
return flag == UNKNOWN || !flag.isUsable();
|
||||
}
|
||||
|
||||
public static FeatureFlags getValue(String value) {
|
||||
if (value.equalsIgnoreCase("TESSELATION_SHADERS")) {
|
||||
value = "TESSELLATION_SHADERS";
|
||||
}
|
||||
try {
|
||||
return FeatureFlags.valueOf(value);
|
||||
return FeatureFlags.valueOf(value.toUpperCase(java.util.Locale.US));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return FeatureFlags.UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.coderbot.iris.gl.blending;
|
||||
|
||||
public class AlphaTest {
|
||||
public static final AlphaTest ALWAYS = new AlphaTest(AlphaTestFunction.ALWAYS, 0.0f);
|
||||
|
||||
private final AlphaTestFunction function;
|
||||
private final float reference;
|
||||
|
||||
@@ -16,4 +18,45 @@ public class AlphaTest {
|
||||
public float getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public String toExpression(String indentation) {
|
||||
return toExpression("gl_FragData[0].a", "iris_currentAlphaTest", indentation);
|
||||
}
|
||||
|
||||
public String toExpression(String alphaAccessor, String alphaThreshold, String indentation) {
|
||||
String expr = function.getExpression();
|
||||
|
||||
if (function == AlphaTestFunction.ALWAYS) {
|
||||
return "// alpha test disabled\n";
|
||||
} else if (function == AlphaTestFunction.NEVER) {
|
||||
return "discard;\n";
|
||||
}
|
||||
|
||||
return indentation + "if (!(" + alphaAccessor + " " + expr + " " + alphaThreshold + ")) {\n" +
|
||||
indentation + " discard;\n" +
|
||||
indentation + "}\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((function == null) ? 0 : function.hashCode());
|
||||
result = prime * result + Float.floatToIntBits(reference);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AlphaTest other = (AlphaTest) obj;
|
||||
if (function != other.function)
|
||||
return false;
|
||||
return Float.floatToIntBits(reference) == Float.floatToIntBits(other.reference);
|
||||
}
|
||||
}
|
||||
@@ -5,33 +5,35 @@ import org.lwjgl.opengl.GL11;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum AlphaTestFunction {
|
||||
NEVER(GL11.GL_NEVER),
|
||||
LESS(GL11.GL_LESS),
|
||||
EQUAL(GL11.GL_EQUAL),
|
||||
LEQUAL(GL11.GL_LEQUAL),
|
||||
GREATER(GL11.GL_GREATER),
|
||||
NOTEQUAL(GL11.GL_NOTEQUAL),
|
||||
GEQUAL(GL11.GL_GEQUAL),
|
||||
ALWAYS(GL11.GL_ALWAYS);
|
||||
NEVER(GL11.GL_NEVER, null),
|
||||
LESS(GL11.GL_LESS, "<"),
|
||||
EQUAL(GL11.GL_EQUAL, "=="),
|
||||
LEQUAL(GL11.GL_LEQUAL, "<="),
|
||||
GREATER(GL11.GL_GREATER, ">"),
|
||||
NOTEQUAL(GL11.GL_NOTEQUAL, "!="),
|
||||
GEQUAL(GL11.GL_GEQUAL, ">="),
|
||||
ALWAYS(GL11.GL_ALWAYS, null);
|
||||
|
||||
private final int glId;
|
||||
private final String expression;
|
||||
|
||||
AlphaTestFunction(int glFormat) {
|
||||
AlphaTestFunction(int glFormat, String expression) {
|
||||
this.glId = glFormat;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public static Optional<AlphaTestFunction> fromGlId(int glId) {
|
||||
return switch (glId) {
|
||||
case GL11.GL_NEVER -> Optional.of(NEVER);
|
||||
case GL11.GL_LESS -> Optional.of(LESS);
|
||||
case GL11.GL_EQUAL -> Optional.of(EQUAL);
|
||||
case GL11.GL_LEQUAL -> Optional.of(LEQUAL);
|
||||
case GL11.GL_GREATER -> Optional.of(GREATER);
|
||||
case GL11.GL_NOTEQUAL -> Optional.of(NOTEQUAL);
|
||||
case GL11.GL_GEQUAL -> Optional.of(GEQUAL);
|
||||
case GL11.GL_ALWAYS -> Optional.of(ALWAYS);
|
||||
default -> Optional.empty();
|
||||
};
|
||||
return switch (glId) {
|
||||
case GL11.GL_NEVER -> Optional.of(NEVER);
|
||||
case GL11.GL_LESS -> Optional.of(LESS);
|
||||
case GL11.GL_EQUAL -> Optional.of(EQUAL);
|
||||
case GL11.GL_LEQUAL -> Optional.of(LEQUAL);
|
||||
case GL11.GL_GREATER -> Optional.of(GREATER);
|
||||
case GL11.GL_NOTEQUAL -> Optional.of(NOTEQUAL);
|
||||
case GL11.GL_GEQUAL -> Optional.of(GEQUAL);
|
||||
case GL11.GL_ALWAYS -> Optional.of(ALWAYS);
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
|
||||
public static Optional<AlphaTestFunction> fromString(String name) {
|
||||
@@ -54,4 +56,8 @@ public enum AlphaTestFunction {
|
||||
public int getGlId() {
|
||||
return glId;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,6 @@ public class ImageBinding {
|
||||
public void update() {
|
||||
// We can assume that image bindings are supported here as either the EXT extension or 4.2 core, as otherwise ImageLimits
|
||||
// would report that zero image units are supported.
|
||||
RenderSystem.bindImageTexture(imageUnit, textureID.getAsInt(), 0, false, 0, GL15.GL_READ_WRITE, internalFormat);
|
||||
RenderSystem.bindImageTexture(imageUnit, textureID.getAsInt(), 0, true, 0, GL15.GL_READ_WRITE, internalFormat);
|
||||
}
|
||||
}
|
||||
@@ -34,36 +34,31 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo
|
||||
|
||||
public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource,
|
||||
@Nullable String fragmentSource, ImmutableSet<Integer> reservedTextureUnits) {
|
||||
GlShader vertex;
|
||||
GlShader geometry;
|
||||
GlShader fragment;
|
||||
return begin(name, vertexSource, geometrySource, null, null, fragmentSource, reservedTextureUnits);
|
||||
}
|
||||
|
||||
vertex = buildShader(ShaderType.VERTEX, name + ".vsh", vertexSource);
|
||||
public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource,
|
||||
@Nullable String tessControlSource, @Nullable String tessEvalSource,
|
||||
@Nullable String fragmentSource, ImmutableSet<Integer> reservedTextureUnits) {
|
||||
GlShader vertex = buildShader(ShaderType.VERTEX, name + ".vsh", vertexSource);
|
||||
GlShader geometry = geometrySource != null ? buildShader(ShaderType.GEOMETRY, name + ".gsh", geometrySource) : null;
|
||||
GlShader tessControl = tessControlSource != null ? buildShader(ShaderType.TESSELATION_CONTROL, name + ".tcs", tessControlSource) : null;
|
||||
GlShader tessEval = tessEvalSource != null ? buildShader(ShaderType.TESSELATION_EVAL, name + ".tes", tessEvalSource) : null;
|
||||
GlShader fragment = buildShader(ShaderType.FRAGMENT, name + ".fsh", fragmentSource);
|
||||
|
||||
if (geometrySource != null) {
|
||||
geometry = buildShader(ShaderType.GEOMETRY, name + ".gsh", geometrySource);
|
||||
} else {
|
||||
geometry = null;
|
||||
java.util.List<GlShader> shaders = new java.util.ArrayList<>();
|
||||
shaders.add(vertex);
|
||||
if (geometry != null) shaders.add(geometry);
|
||||
if (tessControl != null) shaders.add(tessControl);
|
||||
if (tessEval != null) shaders.add(tessEval);
|
||||
shaders.add(fragment);
|
||||
|
||||
int programId = ProgramCreator.create(name, shaders.toArray(new GlShader[0]));
|
||||
|
||||
for (GlShader shader : shaders) {
|
||||
shader.destroy();
|
||||
}
|
||||
|
||||
fragment = buildShader(ShaderType.FRAGMENT, name + ".fsh", fragmentSource);
|
||||
|
||||
int programId;
|
||||
|
||||
if (geometry != null) {
|
||||
programId = ProgramCreator.create(name, vertex, geometry, fragment);
|
||||
} else {
|
||||
programId = ProgramCreator.create(name, vertex, fragment);
|
||||
}
|
||||
|
||||
vertex.destroy();
|
||||
|
||||
if (geometry != null) {
|
||||
geometry.destroy();
|
||||
}
|
||||
|
||||
fragment.destroy();
|
||||
|
||||
return new ProgramBuilder(name, programId, reservedTextureUnits);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.lwjgl.opengl.KHRDebug;
|
||||
|
||||
public class ProgramCreator {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(ProgramCreator.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger("ProgramCreator");
|
||||
|
||||
public static final int MC_ENTITY = 11;
|
||||
public static final int MC_MID_TEX_COORD = 12;
|
||||
|
||||
@@ -4,6 +4,7 @@ package net.coderbot.iris.gl.shader;
|
||||
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
import org.lwjgl.opengl.GL40;
|
||||
import org.lwjgl.opengl.GL43;
|
||||
|
||||
/**
|
||||
@@ -12,6 +13,8 @@ import org.lwjgl.opengl.GL43;
|
||||
public enum ShaderType {
|
||||
VERTEX(GL20.GL_VERTEX_SHADER),
|
||||
GEOMETRY(GL32.GL_GEOMETRY_SHADER),
|
||||
TESSELATION_CONTROL(GL40.GL_TESS_CONTROL_SHADER),
|
||||
TESSELATION_EVAL(GL40.GL_TESS_EVALUATION_SHADER),
|
||||
FRAGMENT(GL20.GL_FRAGMENT_SHADER),
|
||||
COMPUTE(GL43.GL_COMPUTE_SHADER);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.coderbot.iris.gl.shader;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.Tags;
|
||||
import com.gtnewhorizons.angelica.config.AngelicaConfig;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.coderbot.iris.parsing.BiomeCategories;
|
||||
import net.coderbot.iris.pipeline.HandRenderer;
|
||||
@@ -75,6 +76,9 @@ public class StandardMacros {
|
||||
define(standardDefines, "MC_RENDER_QUALITY", "1.0");
|
||||
define(standardDefines, "MC_SHADOW_QUALITY", "1.0");
|
||||
define(standardDefines, "IS_ANGELICA");
|
||||
if (AngelicaConfig.defineIsIris) {
|
||||
define(standardDefines, "IS_IRIS");
|
||||
}
|
||||
define(standardDefines, "ANGELICA_VERSION", makeAngelicaVersion());
|
||||
define(standardDefines, "MC_HAND_DEPTH", Float.toString(HandRenderer.DEPTH));
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.coderbot.iris.gl.state;
|
||||
|
||||
public enum FogMode {
|
||||
/**
|
||||
* Fog is disabled.
|
||||
*/
|
||||
OFF,
|
||||
|
||||
/**
|
||||
* Per-vertex fog, applicable to most geometry.
|
||||
*/
|
||||
PER_VERTEX,
|
||||
|
||||
/**
|
||||
* Per-fragment fog, for extra-long geometry like beacon beams.
|
||||
*/
|
||||
PER_FRAGMENT
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.coderbot.iris.pipeline;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.joml.Vector4f;
|
||||
@@ -24,7 +25,7 @@ public class ClearPass {
|
||||
}
|
||||
|
||||
public void execute(Vector4f defaultClearColor) {
|
||||
GL11.glViewport(0, 0, viewportX.getAsInt(), viewportY.getAsInt());
|
||||
GLStateManager.glViewport(0, 0, viewportX.getAsInt(), viewportY.getAsInt());
|
||||
framebuffer.bind();
|
||||
|
||||
Vector4f color = Objects.requireNonNull(defaultClearColor);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ClearPassCreator {
|
||||
// Sort buffers by their clear color so we can group up glClear calls.
|
||||
Map<Vector4f, IntList> clearByColor = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < renderTargetDirectives.getColorSamplingSettings().size(); i++) {
|
||||
for (int i = 0; i < Math.min(renderTargetDirectives.getColorSamplingSettings().size(), renderTargets.getNumColorTextures()); i++) {
|
||||
// unboxed
|
||||
PackShadowDirectives.SamplingSettings settings = renderTargetDirectives.getColorSamplingSettings().get(i);
|
||||
|
||||
|
||||
@@ -9,15 +9,13 @@ import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache;
|
||||
import com.gtnewhorizons.angelica.rendering.RenderingState;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import net.coderbot.iris.gl.buffer.ShaderStorageBufferHolder;
|
||||
import net.coderbot.iris.gl.buffer.ShaderStorageInfo;
|
||||
import net.coderbot.iris.gl.image.GlImage;
|
||||
import net.coderbot.iris.gl.image.ImageInformation;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.block_rendering.BlockMaterialMapping;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.celeritas.CeleritasTerrainPipeline;
|
||||
import net.coderbot.iris.compat.dh.DHCompat;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
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;
|
||||
@@ -26,14 +24,20 @@ import net.coderbot.iris.gbuffer_overrides.state.RenderTargetStateListener;
|
||||
import net.coderbot.iris.gl.blending.AlphaTestOverride;
|
||||
import net.coderbot.iris.gl.blending.BlendModeOverride;
|
||||
import net.coderbot.iris.gl.blending.BufferBlendOverride;
|
||||
import net.coderbot.iris.gl.buffer.ShaderStorageBufferHolder;
|
||||
import net.coderbot.iris.gl.buffer.ShaderStorageInfo;
|
||||
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
|
||||
import net.coderbot.iris.gl.image.GlImage;
|
||||
import net.coderbot.iris.gl.image.ImageInformation;
|
||||
import net.coderbot.iris.gl.program.ComputeProgram;
|
||||
import net.coderbot.iris.gl.program.Program;
|
||||
import net.coderbot.iris.gl.program.ProgramBuilder;
|
||||
import net.coderbot.iris.gl.program.ProgramImages;
|
||||
import net.coderbot.iris.gl.program.ProgramSamplers;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.gl.texture.DepthBufferFormat;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
import net.coderbot.iris.pipeline.transform.PatchShaderType;
|
||||
import net.coderbot.iris.pipeline.transform.TransformPatcher;
|
||||
import net.coderbot.iris.postprocess.BufferFlipper;
|
||||
@@ -48,7 +52,6 @@ import net.coderbot.iris.samplers.IrisImages;
|
||||
import net.coderbot.iris.samplers.IrisSamplers;
|
||||
import net.coderbot.iris.shaderpack.CloudSetting;
|
||||
import net.coderbot.iris.shaderpack.ComputeSource;
|
||||
import net.coderbot.iris.shaderpack.IdMap;
|
||||
import net.coderbot.iris.shaderpack.OptionalBoolean;
|
||||
import net.coderbot.iris.shaderpack.PackDirectives;
|
||||
import net.coderbot.iris.shaderpack.PackShadowDirectives;
|
||||
@@ -58,6 +61,7 @@ import net.coderbot.iris.shaderpack.ProgramSet;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
import net.coderbot.iris.shaderpack.loading.ProgramId;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
import net.coderbot.iris.shadows.ShadowCompositeRenderer;
|
||||
import net.coderbot.iris.shadows.ShadowRenderTargets;
|
||||
import net.coderbot.iris.texture.format.TextureFormat;
|
||||
import net.coderbot.iris.texture.format.TextureFormatLoader;
|
||||
@@ -80,6 +84,7 @@ import org.joml.Vector4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -117,10 +122,14 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private ImmutableList<ClearPass> shadowClearPasses;
|
||||
private ImmutableList<ClearPass> shadowClearPassesFull;
|
||||
|
||||
private final ComputeProgram[] setup;
|
||||
private final CompositeRenderer beginRenderer;
|
||||
private final CompositeRenderer prepareRenderer;
|
||||
|
||||
@Nullable
|
||||
private final ShadowRenderer shadowRenderer;
|
||||
@Nullable
|
||||
private final ShadowCompositeRenderer shadowCompositeRenderer;
|
||||
|
||||
private final CustomUniforms customUniforms;
|
||||
|
||||
@@ -156,6 +165,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private final boolean shouldRenderVignette;
|
||||
private final boolean shouldRenderSun;
|
||||
private final boolean shouldRenderMoon;
|
||||
private final boolean shouldRenderStars;
|
||||
private final boolean shouldRenderSkyDisc;
|
||||
private final boolean shouldRenderWeather;
|
||||
private final boolean shouldRenderWeatherParticles;
|
||||
private final boolean shouldWriteRainAndSnowToDepthBuffer;
|
||||
private final boolean shouldRenderParticlesBeforeDeferred;
|
||||
private final boolean shouldRenderPrepareBeforeShadow;
|
||||
@@ -176,6 +189,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private int currentNormalTexture;
|
||||
private int currentSpecularTexture;
|
||||
private PackDirectives packDirectives;
|
||||
private final Set<FeatureFlags> activeFeatures;
|
||||
|
||||
public DeferredWorldRenderingPipeline(ProgramSet programs) {
|
||||
Objects.requireNonNull(programs);
|
||||
@@ -207,6 +221,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
this.shouldRenderVignette = programs.getPackDirectives().vignette();
|
||||
this.shouldRenderSun = programs.getPackDirectives().shouldRenderSun();
|
||||
this.shouldRenderMoon = programs.getPackDirectives().shouldRenderMoon();
|
||||
this.shouldRenderStars = programs.getPackDirectives().shouldRenderStars();
|
||||
this.shouldRenderSkyDisc = programs.getPackDirectives().shouldRenderSkyDisc();
|
||||
this.shouldRenderWeather = programs.getPackDirectives().shouldRenderWeather();
|
||||
this.shouldRenderWeatherParticles = programs.getPackDirectives().shouldRenderWeatherParticles();
|
||||
this.shouldWriteRainAndSnowToDepthBuffer = programs.getPackDirectives().rainDepth();
|
||||
this.shouldRenderParticlesBeforeDeferred = programs.getPackDirectives().getParticleRenderingSettings()
|
||||
.map(s -> s == net.coderbot.iris.shaderpack.ParticleRenderingSettings.BEFORE || s == net.coderbot.iris.shaderpack.ParticleRenderingSettings.MIXED)
|
||||
@@ -217,6 +235,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
this.updateNotifier = new FrameUpdateNotifier();
|
||||
|
||||
this.packDirectives = programs.getPackDirectives();
|
||||
this.activeFeatures = programs.getPack().getActiveFeatures();
|
||||
|
||||
final Framebuffer main = Minecraft.getMinecraft().getFramebuffer();
|
||||
|
||||
@@ -304,8 +323,6 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
this.flippedBeforeShadow = ImmutableSet.of();
|
||||
|
||||
BufferFlipper flipper = new BufferFlipper();
|
||||
|
||||
this.centerDepthSampler = new CenterDepthSampler(() -> getRenderTargets().getDepthTexture(), programs.getPackDirectives().getCenterDepthHalfLife());
|
||||
@@ -314,7 +331,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
this.shadowTargetsSupplier = () -> {
|
||||
if (shadowRenderTargets == null) {
|
||||
this.shadowRenderTargets = new ShadowRenderTargets(shadowMapResolution, shadowDirectives);
|
||||
this.shadowRenderTargets = new ShadowRenderTargets(this, shadowMapResolution, shadowDirectives);
|
||||
}
|
||||
|
||||
return shadowRenderTargets;
|
||||
@@ -322,18 +339,26 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
PatchedShaderPrinter.resetPrintState();
|
||||
|
||||
final ProgramBuildContext beginBuildContext = new ProgramBuildContext(renderTargets, customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, shadowTargetsSupplier, customTextureManager.getCustomTextureIdMap(TextureStage.BEGIN), customUniforms, customImages, customTextureManager.getIrisCustomTextures(), this);
|
||||
final ProgramBuildContext prepareBuildContext = new ProgramBuildContext(renderTargets, customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, shadowTargetsSupplier, customTextureManager.getCustomTextureIdMap(TextureStage.PREPARE), customUniforms, customImages, customTextureManager.getIrisCustomTextures(), this);
|
||||
final ProgramBuildContext deferredBuildContext = new ProgramBuildContext(renderTargets, customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, shadowTargetsSupplier, customTextureManager.getCustomTextureIdMap(TextureStage.DEFERRED), customUniforms, customImages, customTextureManager.getIrisCustomTextures(), this);
|
||||
final ProgramBuildContext compositeBuildContext = new ProgramBuildContext(renderTargets, customTextureManager.getNoiseTexture(), updateNotifier, centerDepthSampler, shadowTargetsSupplier, customTextureManager.getCustomTextureIdMap(TextureStage.COMPOSITE_AND_FINAL), customUniforms, customImages, customTextureManager.getIrisCustomTextures(), this);
|
||||
this.prepareRenderer = new CompositeRenderer(programs.getPrepare(), programs.getPrepareCompute(), flipper, prepareBuildContext, programs.getPackDirectives().getExplicitFlips("prepare_pre"), prepareTransformFutures, "prepare");
|
||||
|
||||
this.setup = createSetupComputes(programs.getSetup());
|
||||
|
||||
this.beginRenderer = new CompositeRenderer(programs.getBegin(), programs.getBeginCompute(), flipper, beginBuildContext, programs.getPackDirectives().getExplicitFlips("begin_pre"), null, "begin", TextureStage.BEGIN);
|
||||
|
||||
this.flippedBeforeShadow = flipper.snapshot();
|
||||
|
||||
this.prepareRenderer = new CompositeRenderer(programs.getPrepare(), programs.getPrepareCompute(), flipper, prepareBuildContext, programs.getPackDirectives().getExplicitFlips("prepare_pre"), prepareTransformFutures, "prepare", TextureStage.PREPARE);
|
||||
|
||||
flippedAfterPrepare = flipper.snapshot();
|
||||
|
||||
this.deferredRenderer = new CompositeRenderer(programs.getDeferred(), programs.getDeferredCompute(), flipper, deferredBuildContext, programs.getPackDirectives().getExplicitFlips("deferred_pre"), deferredTransformFutures, "deferred");
|
||||
this.deferredRenderer = new CompositeRenderer(programs.getDeferred(), programs.getDeferredCompute(), flipper, deferredBuildContext, programs.getPackDirectives().getExplicitFlips("deferred_pre"), deferredTransformFutures, "deferred", TextureStage.DEFERRED);
|
||||
|
||||
flippedAfterTranslucent = flipper.snapshot();
|
||||
|
||||
this.compositeRenderer = new CompositeRenderer(programs.getComposite(), programs.getCompositeCompute(), flipper, compositeBuildContext, programs.getPackDirectives().getExplicitFlips("composite_pre"), compositeTransformFutures, "composite");
|
||||
this.compositeRenderer = new CompositeRenderer(programs.getComposite(), programs.getCompositeCompute(), flipper, compositeBuildContext, programs.getPackDirectives().getExplicitFlips("composite_pre"), compositeTransformFutures, "composite", TextureStage.COMPOSITE_AND_FINAL);
|
||||
this.finalPassRenderer = new FinalPassRenderer(programs, compositeBuildContext, flipper.snapshot(), this.compositeRenderer.getFlippedAtLeastOnceFinal(), finalTransformFuture, "final");
|
||||
|
||||
// [(textured=false,lightmap=false), (textured=true,lightmap=false), (textured=true,lightmap=true)]
|
||||
@@ -423,16 +448,24 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
});
|
||||
});
|
||||
if (shadowRenderTargets == null && shadowDirectives.isShadowEnabled() == OptionalBoolean.TRUE) {
|
||||
shadowRenderTargets = new ShadowRenderTargets(shadowMapResolution, shadowDirectives);
|
||||
shadowRenderTargets = new ShadowRenderTargets(this, shadowMapResolution, shadowDirectives);
|
||||
}
|
||||
|
||||
if (shadowRenderTargets != null) {
|
||||
this.shadowClearPasses = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, false, shadowDirectives);
|
||||
this.shadowClearPassesFull = ClearPassCreator.createShadowClearPasses(shadowRenderTargets, true, shadowDirectives);
|
||||
|
||||
this.shadowCompositeRenderer = new ShadowCompositeRenderer(this, programs.getPackDirectives(),
|
||||
programs.getShadowComposite(), programs.getShadowCompCompute(), this.shadowRenderTargets,
|
||||
ssboHolder,
|
||||
customTextureManager.getNoiseTexture(), updateNotifier,
|
||||
customTextureManager.getCustomTextureIdMap(TextureStage.SHADOWCOMP),
|
||||
customImages, programs.getPackDirectives().getExplicitFlips("shadowcomp_pre"),
|
||||
customTextureManager.getIrisCustomTextures(), customUniforms);
|
||||
|
||||
if (programs.getPackDirectives().getShadowDirectives().isShadowEnabled().orElse(true)) {
|
||||
this.shadowRenderer = new ShadowRenderer(programs.getShadow().orElse(null),
|
||||
programs.getPackDirectives(), shadowRenderTargets);
|
||||
programs.getPackDirectives(), shadowRenderTargets, shadowCompositeRenderer);
|
||||
Program shadowProgram = table.match(RenderCondition.SHADOW, new InputAvailability(true, true)).getProgram();
|
||||
shadowRenderer.setUsesImages(shadowProgram != null && shadowProgram.getActiveImages() > 0);
|
||||
} else {
|
||||
@@ -441,6 +474,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
} else {
|
||||
this.shadowClearPasses = ImmutableList.of();
|
||||
this.shadowClearPassesFull = ImmutableList.of();
|
||||
this.shadowCompositeRenderer = null;
|
||||
this.shadowRenderer = null;
|
||||
}
|
||||
|
||||
@@ -449,6 +483,25 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
this.clearPassesFull = ClearPassCreator.createClearPasses(renderTargets, true, programs.getPackDirectives().getRenderTargetDirectives());
|
||||
this.clearPasses = ClearPassCreator.createClearPasses(renderTargets, false, programs.getPackDirectives().getRenderTargetDirectives());
|
||||
|
||||
boolean hasSetup = false;
|
||||
for (ComputeProgram program : setup) {
|
||||
if (program != null) {
|
||||
if (!hasSetup) {
|
||||
hasSetup = true;
|
||||
renderTargets.onFullClear();
|
||||
final Vector4f fogColor = new Vector4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
clearPassesFull.forEach(clearPass -> clearPass.execute(fogColor));
|
||||
}
|
||||
program.use();
|
||||
customUniforms.push(program);
|
||||
program.dispatch(1, 1);
|
||||
}
|
||||
}
|
||||
if (hasSetup) {
|
||||
ComputeProgram.unbind();
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
}
|
||||
|
||||
// Terrain pipeline sampler/image factory setup follows.
|
||||
|
||||
Supplier<ImmutableSet<Integer>> flipped = () -> isBeforeTranslucent ? flippedAfterPrepare : flippedAfterTranslucent;
|
||||
@@ -586,6 +639,26 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
return shouldRenderMoon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderStars() {
|
||||
return shouldRenderStars;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderSkyDisc() {
|
||||
return shouldRenderSkyDisc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderWeather() {
|
||||
return shouldRenderWeather;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderWeatherParticles() {
|
||||
return shouldRenderWeatherParticles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldWriteRainAndSnowToDepthBuffer() {
|
||||
return shouldWriteRainAndSnowToDepthBuffer;
|
||||
@@ -606,6 +679,16 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
return sunPathRotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFeature(FeatureFlags flag) {
|
||||
return activeFeatures.contains(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> getTextureMap() {
|
||||
return packDirectives.getTextureMap();
|
||||
}
|
||||
|
||||
private RenderCondition getCondition(WorldRenderingPhase phase) {
|
||||
if (isRenderingShadow) {
|
||||
return RenderCondition.SHADOW;
|
||||
@@ -704,17 +787,21 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
transformed = TransformPatcher.patchAttributes(
|
||||
source.getVertexSource().orElseThrow(NullPointerException::new),
|
||||
source.getGeometrySource().orElse(null),
|
||||
source.getTessControlSource().orElse(null),
|
||||
source.getTessEvalSource().orElse(null),
|
||||
source.getFragmentSource().orElseThrow(NullPointerException::new),
|
||||
availability);
|
||||
}
|
||||
|
||||
String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
|
||||
String tessEval = transformed.get(PatchShaderType.TESS_EVAL);
|
||||
String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment);
|
||||
|
||||
ProgramBuilder builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
|
||||
ProgramBuilder builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment,
|
||||
IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS);
|
||||
|
||||
return createPassInner(builder, source.getDirectives(), availability, shadow, id);
|
||||
@@ -722,7 +809,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
|
||||
private Pass createPassInner(ProgramBuilder builder, ProgramDirectives programDirectives, InputAvailability availability, boolean shadow, ProgramId id) {
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.PER_VERTEX);
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
Supplier<ImmutableSet<Integer>> flipped;
|
||||
@@ -868,10 +955,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
if (shadowViewport) {
|
||||
GL11.glViewport(0, 0, shadowMapResolution, shadowMapResolution);
|
||||
GLStateManager.glViewport(0, 0, shadowMapResolution, shadowMapResolution);
|
||||
} else {
|
||||
final Framebuffer main = Minecraft.getMinecraft().getFramebuffer();
|
||||
GL11.glViewport(0, 0, main.framebufferWidth, main.framebufferHeight);
|
||||
GLStateManager.glViewport(0, 0, main.framebufferWidth, main.framebufferHeight);
|
||||
}
|
||||
|
||||
if (program != null) {
|
||||
@@ -931,12 +1018,22 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
// Destroy the composite rendering pipeline
|
||||
//
|
||||
// This destroys all the loaded composite programs as well.
|
||||
beginRenderer.destroy();
|
||||
prepareRenderer.destroy();
|
||||
compositeRenderer.destroy();
|
||||
deferredRenderer.destroy();
|
||||
finalPassRenderer.destroy();
|
||||
centerDepthSampler.destroy();
|
||||
|
||||
// Destroy setup compute programs
|
||||
if (setup != null) {
|
||||
for (ComputeProgram compute : setup) {
|
||||
if (compute != null) {
|
||||
compute.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy shadow compute programs
|
||||
if (shadowComputes != null) {
|
||||
for (ComputeProgram compute : shadowComputes) {
|
||||
@@ -946,6 +1043,11 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy shadow composite renderer
|
||||
if (shadowCompositeRenderer != null) {
|
||||
shadowCompositeRenderer.destroy();
|
||||
}
|
||||
|
||||
horizonRenderer.destroy();
|
||||
|
||||
// Make sure that any custom framebuffers are not bound before destroying render targets
|
||||
@@ -1054,6 +1156,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
main.framebufferHeight, depthBufferFormat, packDirectives);
|
||||
|
||||
if (changed) {
|
||||
beginRenderer.recalculateSizes();
|
||||
prepareRenderer.recalculateSizes();
|
||||
deferredRenderer.recalculateSizes();
|
||||
compositeRenderer.recalculateSizes();
|
||||
@@ -1074,6 +1177,21 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
if (ssboHolder != null) {
|
||||
ssboHolder.hasResizedScreen(main.framebufferWidth, main.framebufferHeight);
|
||||
}
|
||||
|
||||
// Re-run setup computes after resize (SETUP dispatches with 1,1 workgroups)
|
||||
boolean ranSetup = false;
|
||||
for (ComputeProgram program : setup) {
|
||||
if (program != null) {
|
||||
ranSetup = true;
|
||||
program.use();
|
||||
customUniforms.push(program);
|
||||
program.dispatch(1, 1);
|
||||
}
|
||||
}
|
||||
if (ranSetup) {
|
||||
ComputeProgram.unbind();
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
final ImmutableList<ClearPass> passes;
|
||||
@@ -1109,13 +1227,15 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS);
|
||||
String transformed = TransformPatcher.patchCompute(source.getName(), source.getSource().orElse(null), TextureStage.GBUFFERS_AND_SHADOW, getTextureMap());
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName() + "_compute", null, null, null, transformed);
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), transformed, IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
throw new RuntimeException("Shader compilation failed!", e);
|
||||
}
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.PER_VERTEX);
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
Supplier<ImmutableSet<Integer>> flipped;
|
||||
@@ -1158,6 +1278,60 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
return programs;
|
||||
}
|
||||
|
||||
private ComputeProgram[] createSetupComputes(ComputeSource[] compute) {
|
||||
ComputeProgram[] programs = new ComputeProgram[compute.length];
|
||||
for (int i = 0; i < programs.length; i++) {
|
||||
ComputeSource source = compute[i];
|
||||
if (source == null || !source.getSource().isPresent()) {
|
||||
continue;
|
||||
} else {
|
||||
ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
String transformed = TransformPatcher.patchCompute(source.getName(), source.getSource().orElse(null), TextureStage.SETUP, getTextureMap());
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName() + "_compute", null, null, null, transformed);
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), transformed, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
throw new RuntimeException("Shader compilation failed for setup compute " + source.getName() + "!", e);
|
||||
}
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
ImmutableSet<Integer> empty = ImmutableSet.of();
|
||||
Supplier<ImmutableSet<Integer>> flipped = () -> empty;
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor =
|
||||
ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureManager.getCustomTextureIdMap(TextureStage.SETUP));
|
||||
|
||||
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, flipped, renderTargets, true, this);
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, customImages);
|
||||
IrisSamplers.addCustomTextures(customTextureSamplerInterceptor, customTextureManager.getIrisCustomTextures());
|
||||
|
||||
IrisImages.addRenderTargetImages(builder, flipped, renderTargets);
|
||||
IrisImages.addCustomImages(builder, customImages);
|
||||
|
||||
IrisSamplers.addNoiseSampler(customTextureSamplerInterceptor, customTextureManager.getNoiseTexture());
|
||||
IrisSamplers.addCompositeSamplers(customTextureSamplerInterceptor, renderTargets);
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
if (shadowRenderTargets != null) {
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowRenderTargets, null, true);
|
||||
IrisImages.addShadowColorImages(builder, shadowRenderTargets, null);
|
||||
}
|
||||
}
|
||||
|
||||
programs[i] = builder.buildCompute();
|
||||
|
||||
this.customUniforms.mapholderToPass(builder, programs[i]);
|
||||
|
||||
programs[i].setWorkGroupInfo(source.getWorkGroupRelative(), source.getWorkGroups(), null);
|
||||
}
|
||||
}
|
||||
|
||||
return programs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginHand() {
|
||||
// We need to copy the current depth texture so that depthtex2 can contain the depth values for
|
||||
@@ -1280,6 +1454,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
image.clear();
|
||||
}
|
||||
|
||||
isRenderingFullScreenPass = true;
|
||||
beginRenderer.renderAll();
|
||||
isRenderingFullScreenPass = false;
|
||||
|
||||
setPhase(WorldRenderingPhase.SKY);
|
||||
|
||||
// Render our horizon box before actual sky rendering to avoid being broken by mods that do weird things
|
||||
@@ -1413,7 +1591,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
private static final InputAvailability[] INPUT_AVAILABILITIES = { INPUT_NONE, INPUT_TEXTURE, INPUT_TEXTURE_LIGHTMAP };
|
||||
|
||||
private static CompletableFuture<Map<PatchShaderType, String>> submitCompositeTransform(ProgramSource source) {
|
||||
return Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchComposite(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getFragmentSource().orElse(null)));
|
||||
return Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchComposite(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null)));
|
||||
}
|
||||
|
||||
private static Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> submitCompositeTransforms(ProgramSource[] sources) {
|
||||
@@ -1441,7 +1619,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
processedSourceNames.add(source.getName());
|
||||
for (InputAvailability avail : INPUT_AVAILABILITIES) {
|
||||
Pair<String, InputAvailability> key = Pair.of(source.getName(), avail);
|
||||
futures.put(key, Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchAttributes(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getFragmentSource().orElse(null), avail)));
|
||||
futures.put(key, Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchAttributes(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null), avail)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package net.coderbot.iris.pipeline;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Camera;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.celeritas.CeleritasTerrainPipeline;
|
||||
import net.coderbot.iris.compat.dh.DHCompat;
|
||||
import net.coderbot.iris.features.FeatureFlags;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.gbuffer_overrides.state.RenderTargetStateListener;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
import net.coderbot.iris.shaderpack.CloudSetting;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
@@ -166,6 +172,26 @@ public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeli
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderStars() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderSkyDisc() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderWeather() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderWeatherParticles() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldWriteRainAndSnowToDepthBuffer() {
|
||||
return false;
|
||||
@@ -186,4 +212,14 @@ public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeli
|
||||
// No sun tilt
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFeature(FeatureFlags flag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> getTextureMap() {
|
||||
return Object2ObjectMaps.emptyMap();
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,18 @@ public class PatchedShaderPrinter {
|
||||
}
|
||||
|
||||
public static void debugPatchedShaders(String name, String vertex, String geometry, String fragment) {
|
||||
debugPatchedShaders(name, vertex, geometry, null, null, fragment, null);
|
||||
}
|
||||
|
||||
public static void debugPatchedShaders(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment) {
|
||||
debugPatchedShaders(name, vertex, geometry, tessControl, tessEval, fragment, null);
|
||||
}
|
||||
|
||||
public static void debugPatchedShaders(String name, String vertex, String geometry, String fragment, String compute) {
|
||||
debugPatchedShaders(name, vertex, geometry, null, null, fragment, compute);
|
||||
}
|
||||
|
||||
public static void debugPatchedShaders(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, String compute) {
|
||||
if (prettyPrintShaders) {
|
||||
final Path debugOutDir = Minecraft.getMinecraft().mcDataDir.toPath().resolve("patched_shaders");
|
||||
if (!outputLocationCleared) {
|
||||
@@ -59,9 +71,18 @@ public class PatchedShaderPrinter {
|
||||
if (geometry != null) {
|
||||
Files.write(debugOutDir.resolve(prefix + name + ".gsh"), geometry.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
if (tessControl != null) {
|
||||
Files.write(debugOutDir.resolve(prefix + name + ".tcs"), tessControl.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
if (tessEval != null) {
|
||||
Files.write(debugOutDir.resolve(prefix + name + ".tes"), tessEval.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
if (fragment != null) {
|
||||
Files.write(debugOutDir.resolve(prefix + name + ".fsh"), fragment.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
if (compute != null) {
|
||||
Files.write(debugOutDir.resolve(prefix + name + ".csh"), compute.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Iris.logger.warn("Failed to write debug patched shader source", e);
|
||||
}
|
||||
|
||||
@@ -23,11 +23,13 @@ import net.coderbot.iris.shaderpack.PackShadowDirectives;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
import net.coderbot.iris.shadow.ShadowMatrices;
|
||||
import net.coderbot.iris.shadows.CullingDataCache;
|
||||
import net.coderbot.iris.shadows.ShadowCompositeRenderer;
|
||||
import net.coderbot.iris.shadows.ShadowRenderTargets;
|
||||
import net.coderbot.iris.shadows.frustum.BoxCuller;
|
||||
import net.coderbot.iris.shadows.frustum.CullEverythingFrustum;
|
||||
import net.coderbot.iris.shadows.frustum.FrustumHolder;
|
||||
import net.coderbot.iris.shadows.frustum.advanced.AdvancedShadowCullingFrustum;
|
||||
import net.coderbot.iris.shadows.frustum.advanced.SafeZoneCullingFrustum;
|
||||
import net.coderbot.iris.shadows.frustum.fallback.BoxCullingFrustum;
|
||||
import net.coderbot.iris.shadows.frustum.fallback.NonCullingFrustum;
|
||||
import net.coderbot.iris.uniforms.CameraUniforms;
|
||||
@@ -72,6 +74,7 @@ public class ShadowRenderer {
|
||||
|
||||
public static ShadowRenderTargets CURRENT_TARGETS = null;
|
||||
private final float halfPlaneLength;
|
||||
private final float voxelDistance;
|
||||
private final float renderDistanceMultiplier;
|
||||
private final float entityShadowDistanceMultiplier;
|
||||
private final int resolution;
|
||||
@@ -79,6 +82,7 @@ public class ShadowRenderer {
|
||||
private final Float fov;
|
||||
private final ShadowRenderTargets targets;
|
||||
private final ShadowCullState packCullingState;
|
||||
private final ShadowCompositeRenderer compositeRenderer;
|
||||
private boolean packHasVoxelization;
|
||||
private final boolean shouldRenderTerrain;
|
||||
private final boolean shouldRenderTranslucent;
|
||||
@@ -108,13 +112,14 @@ public class ShadowRenderer {
|
||||
private double lastAdvancedBoxCullerDistance = -1;
|
||||
private double lastTileEntityCullerDistance = -1;
|
||||
|
||||
public ShadowRenderer(ProgramSource shadow, PackDirectives directives, ShadowRenderTargets shadowRenderTargets) {
|
||||
public ShadowRenderer(ProgramSource shadow, PackDirectives directives, ShadowRenderTargets shadowRenderTargets, ShadowCompositeRenderer compositeRenderer) {
|
||||
|
||||
this.profiler = Minecraft.getMinecraft().mcProfiler;
|
||||
|
||||
final PackShadowDirectives shadowDirectives = directives.getShadowDirectives();
|
||||
|
||||
this.halfPlaneLength = shadowDirectives.getDistance();
|
||||
this.voxelDistance = shadowDirectives.getVoxelDistance();
|
||||
this.renderDistanceMultiplier = shadowDirectives.getDistanceRenderMul();
|
||||
this.entityShadowDistanceMultiplier = shadowDirectives.getEntityShadowDistanceMul();
|
||||
this.resolution = shadowDirectives.getResolution();
|
||||
@@ -125,6 +130,8 @@ public class ShadowRenderer {
|
||||
this.shouldRenderPlayer = shadowDirectives.shouldRenderPlayer();
|
||||
this.shouldRenderBlockEntities = shadowDirectives.shouldRenderBlockEntities();
|
||||
|
||||
this.compositeRenderer = compositeRenderer;
|
||||
|
||||
debugStringOverall = "half plane = " + halfPlaneLength + " meters @ " + resolution + "x" + resolution;
|
||||
|
||||
this.terrainFrustumHolder = new FrustumHolder();
|
||||
@@ -221,7 +228,8 @@ public class ShadowRenderer {
|
||||
|
||||
configureDepthSampler(targets.getDepthTextureNoTranslucents().getTextureId(), depthSamplingSettings.get(1));
|
||||
|
||||
for (int i = 0; i < colorSamplingSettings.size(); i++) {
|
||||
for (int i = 0; i < Math.min(colorSamplingSettings.size(), targets.getNumColorTextures()); i++) {
|
||||
if (targets.get(i) == null) continue;
|
||||
int glTextureId = targets.get(i).getMainTexture();
|
||||
|
||||
configureSampler(glTextureId, colorSamplingSettings.get(i));
|
||||
@@ -282,7 +290,7 @@ public class ShadowRenderer {
|
||||
// TODO: Cull entities / block entities with Advanced Frustum Culling even if voxelization is detected.
|
||||
String distanceInfo;
|
||||
String cullingInfo;
|
||||
if ((packCullingState == ShadowCullState.DISTANCE || packHasVoxelization) && packCullingState != ShadowCullState.ADVANCED) {
|
||||
if ((packCullingState == ShadowCullState.DISTANCE || packHasVoxelization) && packCullingState != ShadowCullState.ADVANCED && packCullingState != ShadowCullState.SAFE_ZONE) {
|
||||
double distance = halfPlaneLength * renderMultiplier;
|
||||
|
||||
String reason;
|
||||
@@ -304,26 +312,29 @@ public class ShadowRenderer {
|
||||
holder.setInfo(getOrCreateBoxCullingFrustum(distance), distanceInfo, cullingInfo);
|
||||
}
|
||||
} else {
|
||||
final BoxCuller boxCuller;
|
||||
BoxCuller boxCuller;
|
||||
|
||||
double distance = halfPlaneLength * renderMultiplier;
|
||||
boolean hasSafeZone = packCullingState == ShadowCullState.SAFE_ZONE;
|
||||
|
||||
if (hasSafeZone && renderMultiplier < 0) renderMultiplier = 1.0f;
|
||||
|
||||
double distance = (hasSafeZone ? voxelDistance : halfPlaneLength) * renderMultiplier;
|
||||
String setter = "(set by shader pack)";
|
||||
|
||||
if (renderMultiplier < 0) {
|
||||
// TODO: GUI
|
||||
distance = IrisVideoSettings.shadowDistance * 16; // can be zero :(
|
||||
//distance = 32 * 16;
|
||||
setter = "(set by user)";
|
||||
}
|
||||
|
||||
if (distance >= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) {
|
||||
if (distance >= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 && !hasSafeZone) {
|
||||
distanceInfo = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16
|
||||
+ " blocks (capped by normal render distance)";
|
||||
boxCuller = null;
|
||||
} else {
|
||||
distanceInfo = distance + " blocks " + setter;
|
||||
|
||||
if (distance == 0.0) {
|
||||
if (distance == 0.0 && !hasSafeZone) {
|
||||
cullingInfo = "no shadows rendered";
|
||||
return holder.setInfo(CULL_EVERYTHING_FRUSTUM, distanceInfo, cullingInfo);
|
||||
}
|
||||
@@ -331,15 +342,22 @@ public class ShadowRenderer {
|
||||
boxCuller = getOrCreateAdvancedBoxCuller(distance);
|
||||
}
|
||||
|
||||
cullingInfo = "Advanced Frustum Culling enabled";
|
||||
cullingInfo = (hasSafeZone ? "Safe Zone" : "Advanced") + " Frustum Culling enabled";
|
||||
|
||||
final Vector4f shadowLightPosition = celestialUniforms.getShadowLightPositionInWorldSpace();
|
||||
shadowLightVectorCache.set(shadowLightPosition.x(), shadowLightPosition.y(), shadowLightPosition.z());
|
||||
shadowLightVectorCache.normalize();
|
||||
|
||||
cachedAdvancedFrustum.init(RenderingState.INSTANCE.getModelViewMatrix(), RenderingState.INSTANCE.getProjectionMatrix(), shadowLightVectorCache, boxCuller);
|
||||
return holder.setInfo(cachedAdvancedFrustum, distanceInfo, cullingInfo);
|
||||
|
||||
if (hasSafeZone) {
|
||||
BoxCuller distanceCuller = new BoxCuller(halfPlaneLength * renderMultiplier);
|
||||
SafeZoneCullingFrustum safeZoneFrustum = new SafeZoneCullingFrustum(
|
||||
RenderingState.INSTANCE.getModelViewMatrix(), RenderingState.INSTANCE.getProjectionMatrix(),
|
||||
shadowLightVectorCache, boxCuller, distanceCuller);
|
||||
return holder.setInfo(safeZoneFrustum, distanceInfo, cullingInfo);
|
||||
} else {
|
||||
cachedAdvancedFrustum.init(RenderingState.INSTANCE.getModelViewMatrix(), RenderingState.INSTANCE.getProjectionMatrix(), shadowLightVectorCache, boxCuller);
|
||||
return holder.setInfo(cachedAdvancedFrustum, distanceInfo, cullingInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return holder;
|
||||
@@ -382,7 +400,7 @@ public class ShadowRenderer {
|
||||
private void setupGlState(Matrix4f projMatrix) {
|
||||
// Bind shadow framebuffer and set viewport to shadow resolution
|
||||
targets.getDepthSourceFb().bind();
|
||||
GL11.glViewport(0, 0, resolution, resolution);
|
||||
GLStateManager.glViewport(0, 0, resolution, resolution);
|
||||
|
||||
// Set up our projection matrix and load it into the legacy matrix stack
|
||||
RenderSystem.setupProjectionMatrix(projMatrix);
|
||||
@@ -407,7 +425,7 @@ public class ShadowRenderer {
|
||||
// Restore main framebuffer and viewport
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.getFramebuffer().bindFramebuffer(false);
|
||||
GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight);
|
||||
GLStateManager.glViewport(0, 0, mc.displayWidth, mc.displayHeight);
|
||||
}
|
||||
|
||||
private void copyPreTranslucentDepth() {
|
||||
@@ -675,7 +693,7 @@ public class ShadowRenderer {
|
||||
}
|
||||
|
||||
// Reset viewport in case terrain rendering changed it
|
||||
GL11.glViewport(0, 0, resolution, resolution);
|
||||
GLStateManager.glViewport(0, 0, resolution, resolution);
|
||||
|
||||
profiler.endStartSection("entities");
|
||||
|
||||
@@ -750,6 +768,10 @@ public class ShadowRenderer {
|
||||
((CullingDataCache) levelRenderer).restoreState();
|
||||
}
|
||||
|
||||
profiler.endStartSection("shadowcomp");
|
||||
|
||||
if (compositeRenderer != null) compositeRenderer.renderAll();
|
||||
|
||||
ACTIVE = false;
|
||||
CURRENT_TARGETS = null;
|
||||
profiler.endSection();
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package net.coderbot.iris.pipeline;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Camera;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.compat.dh.DHCompat;
|
||||
import net.coderbot.iris.features.FeatureFlags;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.gbuffer_overrides.state.RenderTargetStateListener;
|
||||
import net.coderbot.iris.celeritas.CeleritasTerrainPipeline;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
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;
|
||||
|
||||
@@ -49,9 +54,16 @@ public interface WorldRenderingPipeline {
|
||||
boolean shouldRenderVignette();
|
||||
boolean shouldRenderSun();
|
||||
boolean shouldRenderMoon();
|
||||
boolean shouldRenderStars();
|
||||
boolean shouldRenderSkyDisc();
|
||||
boolean shouldRenderWeather();
|
||||
boolean shouldRenderWeatherParticles();
|
||||
boolean shouldWriteRainAndSnowToDepthBuffer();
|
||||
boolean shouldRenderParticlesBeforeDeferred();
|
||||
boolean allowConcurrentCompute();
|
||||
|
||||
float getSunPathRotation();
|
||||
|
||||
boolean hasFeature(FeatureFlags flag);
|
||||
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> getTextureMap();
|
||||
}
|
||||
@@ -14,8 +14,16 @@ import java.util.Map;
|
||||
class AttributeTransformer {
|
||||
public static void transform(Transformer transformer, AttributeParameters parameters, String profile, int version) {
|
||||
boolean isCore = profile.equals("core") || (version > 140 && !profile.equals("compatibility"));
|
||||
|
||||
// Common patches (compatibility profile)
|
||||
CommonTransformer.transform(transformer, parameters, isCore, version);
|
||||
|
||||
// Entity ID and overlay color patching (uniform path)
|
||||
EntityPatcher.patchEntityId(transformer, parameters);
|
||||
EntityPatcher.patchOverlayColor(transformer, parameters);
|
||||
|
||||
if (isCore) {
|
||||
if (parameters.type == PatchShaderType.VERTEX) {
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
throw new IllegalStateException("Vertex shaders must be in the compatibility profile to run properly!");
|
||||
}
|
||||
return;
|
||||
@@ -28,66 +36,49 @@ class AttributeTransformer {
|
||||
transformer.rename("gl_MultiTexCoord2", "gl_MultiTexCoord1");
|
||||
}
|
||||
|
||||
Map<String, String> texCoordReplacements = new HashMap<>();
|
||||
if (!parameters.inputs.lightmap) {
|
||||
texCoordReplacements.put("gl_MultiTexCoord1", "vec4(240.0, 240.0, 0.0, 1.0)");
|
||||
texCoordReplacements.put("gl_MultiTexCoord2", "vec4(240.0, 240.0, 0.0, 1.0)");
|
||||
}
|
||||
if (!parameters.inputs.texture) {
|
||||
texCoordReplacements.put("gl_MultiTexCoord0", "vec4(240.0, 240.0, 0.0, 1.0)");
|
||||
}
|
||||
texCoordReplacements.forEach(transformer::replaceExpression);
|
||||
Map<String, String> texCoordReplacements = new HashMap<>();
|
||||
if (!parameters.inputs.lightmap) {
|
||||
texCoordReplacements.put("gl_MultiTexCoord1", "vec4(240.0, 240.0, 0.0, 1.0)");
|
||||
texCoordReplacements.put("gl_MultiTexCoord2", "vec4(240.0, 240.0, 0.0, 1.0)");
|
||||
}
|
||||
if (!parameters.inputs.texture) {
|
||||
texCoordReplacements.put("gl_MultiTexCoord0", "vec4(240.0, 240.0, 0.0, 1.0)");
|
||||
}
|
||||
texCoordReplacements.forEach(transformer::replaceExpression);
|
||||
|
||||
patchTextureMatrices(transformer, parameters.inputs.lightmap);
|
||||
|
||||
if (parameters.type.glShaderType == ShaderType.VERTEX
|
||||
&& transformer.hasVariable("gl_MultiTexCoord3")
|
||||
&& !transformer.hasVariable("mc_midTexCoord")) {
|
||||
// TODO: proper type conversion
|
||||
// gl_MultiTexCoord3 is a super legacy alias of mc_midTexCoord. We don't do this
|
||||
// replacement if we think mc_midTexCoord could be defined just we can't handle
|
||||
// an existing declaration robustly. But basically the proper way to do this is
|
||||
// to define mc_midTexCoord only if it's not defined, and if it is defined,
|
||||
// figure out its type, then replace all occurrences of gl_MultiTexCoord3 with
|
||||
// the correct conversion from mc_midTexCoord's declared type to vec4.
|
||||
transformer.rename("gl_MultiTexCoord3", "mc_midTexCoord");
|
||||
if (parameters.type == ShaderType.VERTEX && transformer.hasVariable("gl_MultiTexCoord3") && !transformer.hasVariable("mc_midTexCoord")) {
|
||||
transformer.rename("gl_MultiTexCoord3", "mc_midTexCoord");
|
||||
transformer.injectVariable("attribute vec4 mc_midTexCoord;");
|
||||
}
|
||||
}
|
||||
|
||||
private static void patchTextureMatrices(Transformer transformer, boolean hasLightmap) {
|
||||
transformer.rename("gl_TextureMatrix", "iris_TextureMatrix");
|
||||
transformer.rename("gl_TextureMatrix", "iris_TextureMatrix");
|
||||
|
||||
// TODO: These were originally marked const, but that breaks things
|
||||
// If these are marked const, then using them below in the iris_LightmapTextureMatrix creation
|
||||
// breaks with them being undefined. I suppose the const variables cause them to get defined later than otherwise?
|
||||
// Similarly, if you make them a const, then iris_ONE_OVER_32 breaks because it references iris_ONE_OVER_256.
|
||||
// Not sure if it really matters if these are marked const or not. Alternatively they can be marked const
|
||||
// and the values hardcoded within the places that use them here, that seems to work fine, but this probably
|
||||
// stayed closer to the original way it worked.
|
||||
transformer.injectVariable("float iris_ONE_OVER_256 = 0.00390625;");
|
||||
transformer.injectVariable("float iris_ONE_OVER_32 = iris_ONE_OVER_256 * 8;");
|
||||
transformer.injectVariable("float iris_ONE_OVER_256 = 0.00390625;");
|
||||
transformer.injectVariable("float iris_ONE_OVER_32 = iris_ONE_OVER_256 * 8;");
|
||||
|
||||
if (hasLightmap) {
|
||||
transformer.injectVariable("mat4 iris_LightmapTextureMatrix = gl_TextureMatrix[1];");
|
||||
} else {
|
||||
transformer.injectVariable("mat4 iris_LightmapTextureMatrix =" +
|
||||
"mat4(iris_ONE_OVER_256, 0.0, 0.0, 0.0," +
|
||||
" 0.0, iris_ONE_OVER_256, 0.0, 0.0," +
|
||||
" 0.0, 0.0, iris_ONE_OVER_256, 0.0," +
|
||||
" iris_ONE_OVER_32, iris_ONE_OVER_32, iris_ONE_OVER_32, iris_ONE_OVER_256);");
|
||||
}
|
||||
if (hasLightmap) {
|
||||
transformer.injectVariable("mat4 iris_LightmapTextureMatrix = gl_TextureMatrix[1];");
|
||||
} else {
|
||||
transformer.injectVariable("mat4 iris_LightmapTextureMatrix =" +
|
||||
"mat4(iris_ONE_OVER_256, 0.0, 0.0, 0.0," +
|
||||
" 0.0, iris_ONE_OVER_256, 0.0, 0.0," +
|
||||
" 0.0, 0.0, iris_ONE_OVER_256, 0.0," +
|
||||
" iris_ONE_OVER_32, iris_ONE_OVER_32, iris_ONE_OVER_32, iris_ONE_OVER_256);");
|
||||
}
|
||||
|
||||
// column major
|
||||
transformer.injectVariable("mat4 iris_TextureMatrix[8] = mat4[8](" +
|
||||
"gl_TextureMatrix[0]," +
|
||||
"iris_LightmapTextureMatrix," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)" +
|
||||
");");
|
||||
transformer.injectVariable("mat4 iris_TextureMatrix[8] = mat4[8](" +
|
||||
"gl_TextureMatrix[0]," +
|
||||
"iris_LightmapTextureMatrix," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)," +
|
||||
"mat4(1.0)" +
|
||||
");");
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.coderbot.iris.pipeline.transform.PatchShaderType.FRAGMENT;
|
||||
import static net.coderbot.iris.pipeline.transform.PatchShaderType.VERTEX;
|
||||
|
||||
class CeleritasTransformer {
|
||||
public static void transform(Transformer transformer, Parameters parameters) {
|
||||
public static void transform(Transformer transformer, Parameters parameters, int glslVersion) {
|
||||
CommonTransformer.transform(transformer, parameters, false, glslVersion);
|
||||
|
||||
switch (parameters.type) {
|
||||
// For Celeritas patching, treat fragment and geometry the same
|
||||
case FRAGMENT:
|
||||
case GEOMETRY:
|
||||
transformFragment(transformer, parameters);
|
||||
@@ -26,7 +25,7 @@ class CeleritasTransformer {
|
||||
}
|
||||
|
||||
public static void transformVertex(Transformer transformer, Parameters parameters) {
|
||||
transformer.injectVariable("uniform vec3 u_RegionOffset;"); // Per-region offset from setRegionOffset()
|
||||
transformer.injectVariable("uniform vec3 u_RegionOffset;");
|
||||
transformer.injectVariable("vec4 iris_LightTexCoord;");
|
||||
transformer.injectFunction("vec4 iris_ftransform() { return gl_ModelViewProjectionMatrix * _celeritas_getVertexPosition(); }");
|
||||
transformer.injectFunction(
|
||||
@@ -57,7 +56,6 @@ class CeleritasTransformer {
|
||||
}
|
||||
|
||||
public static void transformFragment(Transformer transformer, Parameters parameters) {
|
||||
// interestingly there is nothing that isn't shared
|
||||
transformShared(transformer, parameters);
|
||||
}
|
||||
|
||||
@@ -82,31 +80,5 @@ class CeleritasTransformer {
|
||||
sharedReplacements.put("gl_TextureMatrix[1]", "iris_LightmapTextureMatrix");
|
||||
sharedReplacements.put("gl_ModelViewProjectionMatrix", "(iris_ProjectionMatrix * iris_ModelViewMatrix)");
|
||||
sharedReplacements.forEach(transformer::replaceExpression);
|
||||
|
||||
transformFog(transformer, parameters);
|
||||
}
|
||||
|
||||
private static void transformFog(Transformer transformer, Parameters parameters) {
|
||||
transformer.injectVariable("uniform float iris_FogDensity;");
|
||||
transformer.injectVariable("uniform float iris_FogStart;");
|
||||
transformer.injectVariable("uniform float iris_FogEnd;");
|
||||
transformer.injectVariable("uniform vec4 iris_FogColor;");
|
||||
|
||||
transformer.injectFunction("struct iris_FogParameters { vec4 color; float density; float start; float end; float scale; };");
|
||||
transformer.injectFunction(
|
||||
"iris_FogParameters iris_Fog = iris_FogParameters(iris_FogColor, iris_FogDensity, " +
|
||||
"iris_FogStart, iris_FogEnd, 1.0 / (iris_FogEnd - iris_FogStart));");
|
||||
|
||||
final Map<String, String> fogRenames = new HashMap<>();
|
||||
fogRenames.put("gl_Fog", "iris_Fog");
|
||||
fogRenames.put("gl_FogFragCoord", "iris_FogFragCoord");
|
||||
transformer.rename(fogRenames);
|
||||
|
||||
if (parameters.type == VERTEX) {
|
||||
transformer.injectVariable("out float iris_FogFragCoord;");
|
||||
transformer.prependMain("iris_FogFragCoord = 0.0;");
|
||||
} else if (parameters.type == FRAGMENT) {
|
||||
transformer.injectVariable("in float iris_FogFragCoord;");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import net.coderbot.iris.gl.blending.AlphaTest;
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CommonTransformer {
|
||||
|
||||
private static final Map<String, String> COMMON_TEXTURE_RENAMES = Map.ofEntries(
|
||||
Map.entry("texture2D", "texture"),
|
||||
Map.entry("texture3D", "texture"),
|
||||
Map.entry("texture2DLod", "textureLod"),
|
||||
Map.entry("texture3DLod", "textureLod"),
|
||||
Map.entry("texture2DProj", "textureProj"),
|
||||
Map.entry("texture3DProj", "textureProj"),
|
||||
Map.entry("texture2DGrad", "textureGrad"),
|
||||
Map.entry("texture2DGradARB", "textureGrad"),
|
||||
Map.entry("texture3DGrad", "textureGrad"),
|
||||
Map.entry("texelFetch2D", "texelFetch"),
|
||||
Map.entry("texelFetch3D", "texelFetch"),
|
||||
Map.entry("textureSize2D", "textureSize")
|
||||
);
|
||||
|
||||
public static void transform(Transformer root, Parameters parameters, boolean core, int glslVersion) {
|
||||
root.rename("gl_FogFragCoord", "iris_FogFragCoord");
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
root.injectVariable("out float iris_FogFragCoord;");
|
||||
root.prependMain("iris_FogFragCoord = 0.0f;");
|
||||
} else if (parameters.type == ShaderType.FRAGMENT) {
|
||||
root.injectVariable("in float iris_FogFragCoord;");
|
||||
}
|
||||
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
root.injectVariable("vec4 iris_FrontColor;");
|
||||
root.rename("gl_FrontColor", "iris_FrontColor");
|
||||
}
|
||||
|
||||
if (parameters.type == ShaderType.FRAGMENT) {
|
||||
if (root.containsCall("gl_FragColor")) {
|
||||
root.replaceExpression("gl_FragColor", "gl_FragData[0]");
|
||||
}
|
||||
|
||||
// Note: In compatibility profile, gl_FragData is a built-in array.
|
||||
if (!core && parameters.getAlphaTest() != AlphaTest.ALWAYS) {
|
||||
root.injectVariable("uniform float iris_currentAlphaTest;");
|
||||
root.appendMain(parameters.getAlphaTest().toExpression("gl_FragData[0].a", "iris_currentAlphaTest", ""));
|
||||
}
|
||||
}
|
||||
|
||||
if (root.containsCall("texture") && root.hasVariable("texture")) {
|
||||
root.rename("texture", "gtexture");
|
||||
}
|
||||
|
||||
if (root.containsCall("gcolor") && root.hasVariable("gcolor")) {
|
||||
root.rename("gcolor", "gtexture");
|
||||
}
|
||||
|
||||
root.rename("gl_Fog", "iris_Fog");
|
||||
root.injectVariable("uniform float iris_FogDensity;");
|
||||
root.injectVariable("uniform float iris_FogStart;");
|
||||
root.injectVariable("uniform float iris_FogEnd;");
|
||||
root.injectVariable("uniform vec4 iris_FogColor;");
|
||||
root.injectFunction("struct iris_FogParameters {vec4 color;float density;float start;float end;float scale;};");
|
||||
root.injectFunction("iris_FogParameters iris_Fog = iris_FogParameters(iris_FogColor, iris_FogDensity, iris_FogStart, iris_FogEnd, 1.0f / (iris_FogEnd - iris_FogStart));");
|
||||
|
||||
// GLSL 120 natively uses texture2D/shadow2D etc. Ttexture/textureLod don't exist in 120, so only rename for versions that support them.
|
||||
if (glslVersion > 120) {
|
||||
root.renameFunctionCall(COMMON_TEXTURE_RENAMES);
|
||||
root.renameAndWrapShadow("shadow2D", "texture");
|
||||
root.renameAndWrapShadow("shadow2DLod", "textureLod");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,7 @@ public class CompatibilityTransformer {
|
||||
|
||||
|
||||
public static void transformEach(Transformer transformer, Parameters parameters) {
|
||||
if (parameters.type == PatchShaderType.VERTEX) {
|
||||
;
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
// TODO: sildur's jankness
|
||||
// This is a hacky patch for sildur's shaders that changes the way it does it's waving water to make it work better?
|
||||
// Why is this the GLSL transformation code in Iris, tell sildur to fix it and remove this?
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
class CompositeDepthTransformer {
|
||||
|
||||
public static void transform(Transformer transformer) {
|
||||
// replace original declaration
|
||||
int type = transformer.findType("centerDepthSmooth");
|
||||
if (type != 0) {
|
||||
transformer.injectVariable("uniform sampler2D iris_centerDepthSmooth;");
|
||||
transformer.replaceExpression("centerDepthSmooth", "texture2D(iris_centerDepthSmooth, vec2(0.5)).r");
|
||||
}
|
||||
public static void transform(Transformer transformer, Parameters parameters, int glslVersion) {
|
||||
CommonTransformer.transform(transformer, parameters, false, glslVersion);
|
||||
|
||||
int type = transformer.findType("centerDepthSmooth");
|
||||
if (type != 0) {
|
||||
transformer.injectVariable("uniform sampler2D iris_centerDepthSmooth;");
|
||||
transformer.replaceExpression("centerDepthSmooth", "texture2D(iris_centerDepthSmooth, vec2(0.5)).r");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
public class ComputeTransformer {
|
||||
|
||||
public static void transform(Transformer transformer, Parameters parameters, int glslVersion) {
|
||||
CommonTransformer.transform(transformer, parameters, true, glslVersion);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
|
||||
import org.taumc.glsl.Transformer;
|
||||
|
||||
class EntityPatcher {
|
||||
|
||||
public static void patchEntityId(Transformer transformer, AttributeParameters parameters) {
|
||||
injectUniformIfUndeclared(transformer, "entityId", "uniform int entityId;");
|
||||
injectUniformIfUndeclared(transformer, "blockEntityId", "uniform int blockEntityId;");
|
||||
injectUniformIfUndeclared(transformer, "currentRenderedItemId", "uniform int currentRenderedItemId;");
|
||||
}
|
||||
|
||||
public static void patchOverlayColor(Transformer transformer, AttributeParameters parameters) {
|
||||
injectUniformIfUndeclared(transformer, "entityColor", "uniform vec4 entityColor;");
|
||||
}
|
||||
|
||||
private static void injectUniformIfUndeclared(Transformer transformer, String name, String declaration) {
|
||||
if (transformer.containsCall(name) && !transformer.hasVariable(name)) {
|
||||
transformer.injectVariable(declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package net.coderbot.iris.pipeline.transform;
|
||||
public enum Patch {
|
||||
ATTRIBUTES,
|
||||
CELERITAS_TERRAIN,
|
||||
COMPOSITE
|
||||
COMPOSITE,
|
||||
COMPUTE
|
||||
}
|
||||
@@ -5,7 +5,10 @@ import net.coderbot.iris.gl.shader.ShaderType;
|
||||
public enum PatchShaderType {
|
||||
VERTEX(ShaderType.VERTEX),
|
||||
GEOMETRY(ShaderType.GEOMETRY),
|
||||
FRAGMENT(ShaderType.FRAGMENT);
|
||||
TESS_CONTROL(ShaderType.TESSELATION_CONTROL),
|
||||
TESS_EVAL(ShaderType.TESSELATION_EVAL),
|
||||
FRAGMENT(ShaderType.FRAGMENT),
|
||||
COMPUTE(ShaderType.COMPUTE);
|
||||
|
||||
public static final PatchShaderType[] VALUES = values();
|
||||
|
||||
@@ -19,8 +22,10 @@ public enum PatchShaderType {
|
||||
return switch (glShaderType) {
|
||||
case VERTEX -> new PatchShaderType[] { VERTEX };
|
||||
case GEOMETRY -> new PatchShaderType[] { GEOMETRY };
|
||||
case TESSELATION_CONTROL -> new PatchShaderType[] { TESS_CONTROL };
|
||||
case TESSELATION_EVAL -> new PatchShaderType[] { TESS_EVAL };
|
||||
case FRAGMENT -> new PatchShaderType[] { FRAGMENT };
|
||||
default -> throw new IllegalArgumentException("Unknown shader type: " + glShaderType);
|
||||
case COMPUTE -> new PatchShaderType[] { COMPUTE };
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,17 @@ import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
|
||||
import org.antlr.v4.runtime.CommonToken;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.embeddedt.embeddium.impl.gl.shader.ShaderConstants;
|
||||
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
|
||||
import org.taumc.glsl.ShaderParser;
|
||||
import org.taumc.glsl.StorageCollector;
|
||||
import org.taumc.glsl.Transformer;
|
||||
import org.taumc.glsl.grammar.GLSLLexer;
|
||||
import org.taumc.glsl.grammar.GLSLParser;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
|
||||
@@ -31,9 +35,9 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class ShaderTransformer {
|
||||
private static final Pattern versionPattern = Pattern.compile("#version\\s+(\\d+)(?:\\s+(\\w+))?");
|
||||
private static final Pattern inOutVaryingPattern = Pattern.compile("(?m)^\\s*(in|out)(\\s+)");
|
||||
private static final Pattern inPattern = Pattern.compile("(?m)^\\s*(in)(\\s+)");
|
||||
private static final Pattern outPattern = Pattern.compile("(?m)^\\s*(out)(\\s+)");
|
||||
private static final Pattern inOutVaryingPattern = Pattern.compile("(?m)^(\\s*(?:(?:flat|smooth|noperspective)\\s+)?)(in|out)(\\s+)");
|
||||
private static final Pattern inPattern = Pattern.compile("(?m)^(\\s*(?:(?:flat|smooth|noperspective)\\s+)?)(in)(\\s+)");
|
||||
private static final Pattern outPattern = Pattern.compile("(?m)^(\\s*(?:(?:flat|smooth|noperspective)\\s+)?)(out)(\\s+)");
|
||||
|
||||
private static final int CACHE_SIZE = 100;
|
||||
private static final Object2ObjectLinkedOpenHashMap<TransformKey<?>, Map<PatchShaderType, String>> shaderTransformationCache = new Object2ObjectLinkedOpenHashMap<>();
|
||||
@@ -156,8 +160,8 @@ public class ShaderTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
public static <P extends Parameters> Map<PatchShaderType, String> transform(String vertex, String geometry, String fragment, P parameters) {
|
||||
if (vertex == null && geometry == null && fragment == null) {
|
||||
public static <P extends Parameters> Map<PatchShaderType, String> transform(String vertex, String geometry, String tessControl, String tessEval, String fragment, P parameters) {
|
||||
if (vertex == null && geometry == null && tessControl == null && tessEval == null && fragment == null) {
|
||||
return null;
|
||||
} else {
|
||||
Map<PatchShaderType, String> result;
|
||||
@@ -167,6 +171,8 @@ public class ShaderTransformer {
|
||||
EnumMap<PatchShaderType, String> inputs = new EnumMap<>(PatchShaderType.class);
|
||||
inputs.put(PatchShaderType.VERTEX, vertex);
|
||||
inputs.put(PatchShaderType.GEOMETRY, geometry);
|
||||
inputs.put(PatchShaderType.TESS_CONTROL, tessControl);
|
||||
inputs.put(PatchShaderType.TESS_EVAL, tessEval);
|
||||
inputs.put(PatchShaderType.FRAGMENT, fragment);
|
||||
|
||||
var key = new TransformKey<>(patchType, inputs, parameters);
|
||||
@@ -195,6 +201,117 @@ public class ShaderTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
public static <P extends Parameters> Map<PatchShaderType, String> transformCompute(String compute, P parameters) {
|
||||
if (compute == null) {
|
||||
return null;
|
||||
} else {
|
||||
Map<PatchShaderType, String> result;
|
||||
|
||||
var patchType = parameters.patch;
|
||||
|
||||
EnumMap<PatchShaderType, String> inputs = new EnumMap<>(PatchShaderType.class);
|
||||
inputs.put(PatchShaderType.COMPUTE, compute);
|
||||
|
||||
var key = new TransformKey<>(patchType, inputs, parameters);
|
||||
|
||||
synchronized (shaderTransformationCache) {
|
||||
result = shaderTransformationCache.getAndMoveToLast(key);
|
||||
}
|
||||
if (result == null || !useCache) {
|
||||
result = transformComputeInternal(compute, patchType, parameters);
|
||||
// Clear this, we don't want whatever random type was last transformed being considered for the key
|
||||
parameters.type = null;
|
||||
synchronized (shaderTransformationCache) {
|
||||
// Double-check in case another thread added it while we were transforming
|
||||
Map<PatchShaderType, String> existing = shaderTransformationCache.getAndMoveToLast(key);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
if (shaderTransformationCache.size() >= CACHE_SIZE) {
|
||||
shaderTransformationCache.removeFirst();
|
||||
}
|
||||
shaderTransformationCache.putAndMoveToLast(key, result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static <P extends Parameters> Map<PatchShaderType, String> transformComputeInternal(String compute, Patch patchType, P parameters) {
|
||||
EnumMap<PatchShaderType, String> result = new EnumMap<>(PatchShaderType.class);
|
||||
|
||||
Stopwatch watch = Stopwatch.createStarted();
|
||||
|
||||
parameters.type = ShaderType.COMPUTE;
|
||||
|
||||
Matcher matcher = versionPattern.matcher(compute);
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("No #version directive found in compute shader source code!");
|
||||
}
|
||||
|
||||
String versionString = matcher.group(1);
|
||||
int versionInt = Integer.parseInt(versionString);
|
||||
|
||||
// Check if shader uses features requiring a higher GLSL version
|
||||
int requiredVersion = getRequiredVersion(compute, versionInt);
|
||||
if (requiredVersion > versionInt) {
|
||||
Iris.logger.debug("Compute shader requires GLSL {} for detected features, hoisting from {}", requiredVersion, versionInt);
|
||||
versionInt = requiredVersion;
|
||||
versionString = String.valueOf(versionInt);
|
||||
}
|
||||
|
||||
// Compute shaders always use core profile, minimum 330
|
||||
if (versionInt < 330) {
|
||||
versionString = "330";
|
||||
versionInt = 330;
|
||||
}
|
||||
String profileString = "#version " + versionString + " core\n";
|
||||
|
||||
// Rename reserved words
|
||||
String input = compute;
|
||||
for (String reservedWord : fullReservedWords) {
|
||||
String newName = "iris_renamed_" + reservedWord;
|
||||
input = input.replaceAll("\\b" + reservedWord + "\\b", newName);
|
||||
}
|
||||
for (int version : versionedReservedWords.keySet()) {
|
||||
if (versionInt < version) {
|
||||
for (String reservedWord : versionedReservedWords.get(version)) {
|
||||
String newName = "iris_renamed_" + reservedWord;
|
||||
input = input.replaceAll("\\b" + reservedWord + "\\b", newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var parsedShader = ShaderParser.parseShader(input);
|
||||
var transformer = new Transformer(parsedShader.full());
|
||||
|
||||
doTransform(transformer, patchType, parameters, "core", versionInt);
|
||||
|
||||
// Extract extensions
|
||||
var extensions = versionPattern.matcher(getFormattedShader(parsedShader.pre(), "")).replaceFirst("").trim();
|
||||
String header = profileString + (extensions.isEmpty() ? "" : "\n" + extensions);
|
||||
|
||||
final String finalHeader = header;
|
||||
final StringBuilder formattedShaderBuilder = new StringBuilder();
|
||||
|
||||
transformer.mutateTree(tree -> {
|
||||
formattedShaderBuilder.append(getFormattedShader(tree, finalHeader));
|
||||
});
|
||||
|
||||
String formattedShader = formattedShaderBuilder.toString();
|
||||
|
||||
// Restore identifiers that were temporarily renamed
|
||||
formattedShader = formattedShader.replace("iris_renamed_texture", "texture");
|
||||
formattedShader = formattedShader.replace("iris_renamed_sample", "sample");
|
||||
|
||||
result.put(PatchShaderType.COMPUTE, formattedShader);
|
||||
|
||||
watch.stop();
|
||||
Iris.logger.info("[Load #{}] Transformed compute shader for {} in {}", Iris.getShaderPackLoadId(), patchType.name(), watch);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static <P extends Parameters> Map<PatchShaderType, String> transformInternal(EnumMap<PatchShaderType, String> inputs, Patch patchType, P parameters) {
|
||||
EnumMap<PatchShaderType, String> result = new EnumMap<>(PatchShaderType.class);
|
||||
EnumMap<PatchShaderType, Transformer> types = new EnumMap<>(PatchShaderType.class);
|
||||
@@ -205,7 +322,7 @@ public class ShaderTransformer {
|
||||
Stopwatch watch = Stopwatch.createStarted();
|
||||
|
||||
for (PatchShaderType type : PatchShaderType.VALUES) {
|
||||
parameters.type = type;
|
||||
parameters.type = type.glShaderType;
|
||||
if (inputs.get(type) == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -261,6 +378,10 @@ public class ShaderTransformer {
|
||||
var parsedShader = ShaderParser.parseShader(input);
|
||||
var transformer = new Transformer(parsedShader.full());
|
||||
|
||||
if (parameters.type == ShaderType.VERTEX || parameters.type == ShaderType.FRAGMENT) {
|
||||
upgradeStorageQualifiers(transformer, parameters);
|
||||
}
|
||||
|
||||
doTransform(transformer, patchType, parameters, profile, versionInt);
|
||||
|
||||
// Check if we need to patch in texture LOD extension enabling
|
||||
@@ -325,13 +446,13 @@ public class ShaderTransformer {
|
||||
if (entry.getKey() == PatchShaderType.VERTEX) {
|
||||
// In vertex shaders, "in" declarations are vertex attributes, not varyings
|
||||
Matcher inMatcher = inPattern.matcher(formattedShader);
|
||||
formattedShader = inMatcher.replaceAll("attribute$2");
|
||||
formattedShader = inMatcher.replaceAll("$1attribute$3");
|
||||
Matcher outMatcher = outPattern.matcher(formattedShader);
|
||||
formattedShader = outMatcher.replaceAll("varying$2");
|
||||
formattedShader = outMatcher.replaceAll("$1varying$3");
|
||||
} else {
|
||||
// In fragment (and geometry) shaders, both in/out become varying
|
||||
Matcher inOutVaryingMatcher = inOutVaryingPattern.matcher(formattedShader);
|
||||
formattedShader = inOutVaryingMatcher.replaceAll("varying$2");
|
||||
formattedShader = inOutVaryingMatcher.replaceAll("$1varying$3");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,18 +466,21 @@ public class ShaderTransformer {
|
||||
private static void doTransform(Transformer transformer, Patch patchType, Parameters parameters, String profile, int versionInt) {
|
||||
switch (patchType) {
|
||||
case CELERITAS_TERRAIN:
|
||||
CeleritasTransformer.transform(transformer, parameters);
|
||||
CeleritasTransformer.transform(transformer, parameters, versionInt);
|
||||
// Handle mc_midTexCoord for Celeritas
|
||||
patchMultiTexCoord3(transformer, parameters);
|
||||
replaceMidTexCoord(transformer, IrisExtendedChunkVertexType.MID_TEX_SCALE);
|
||||
applyIntelHd4000Workaround(transformer);
|
||||
break;
|
||||
case COMPOSITE:
|
||||
CompositeDepthTransformer.transform(transformer);
|
||||
CompositeDepthTransformer.transform(transformer, parameters, versionInt);
|
||||
break;
|
||||
case ATTRIBUTES:
|
||||
AttributeTransformer.transform(transformer, (AttributeParameters) parameters, profile, versionInt);
|
||||
break;
|
||||
case COMPUTE:
|
||||
ComputeTransformer.transform(transformer, parameters, versionInt);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown patch type: " + patchType.name());
|
||||
}
|
||||
@@ -375,7 +499,7 @@ public class ShaderTransformer {
|
||||
}
|
||||
|
||||
public static void patchMultiTexCoord3(Transformer transformer, Parameters parameters) {
|
||||
if (parameters.type.glShaderType == ShaderType.VERTEX && transformer.hasVariable("gl_MultiTexCoord3") && !transformer.hasVariable("mc_midTexCoord")) {
|
||||
if (parameters.type == ShaderType.VERTEX && transformer.hasVariable("gl_MultiTexCoord3") && !transformer.hasVariable("mc_midTexCoord")) {
|
||||
transformer.rename("gl_MultiTexCoord3", "mc_midTexCoord");
|
||||
transformer.injectVariable("attribute vec4 mc_midTexCoord;");
|
||||
}
|
||||
@@ -439,6 +563,33 @@ public class ShaderTransformer {
|
||||
return "\n\n" + chunkVertexHeader + "\n\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts GLSL 120 storage qualifiers (varying/attribute) to modern in/out tokens so downstream AST transforms (e.g. CompatibilityTransformer) can find them.
|
||||
* The hacky120Patches regex pass converts them back for the final output.
|
||||
*/
|
||||
public static void upgradeStorageQualifiers(Transformer root, Parameters parameters) {
|
||||
final List<TerminalNode> tokens = new ArrayList<>();
|
||||
root.mutateTree(tree -> ParseTreeWalker.DEFAULT.walk(new StorageCollector(tokens), tree));
|
||||
|
||||
for (TerminalNode node : tokens) {
|
||||
if (!(node.getSymbol() instanceof CommonToken token)) {
|
||||
return;
|
||||
}
|
||||
if (token.getType() == GLSLParser.ATTRIBUTE) {
|
||||
token.setType(GLSLParser.IN);
|
||||
token.setText(GLSLParser.VOCABULARY.getLiteralName(GLSLParser.IN).replace("'", ""));
|
||||
} else if (token.getType() == GLSLParser.VARYING) {
|
||||
if (parameters.type == ShaderType.VERTEX) {
|
||||
token.setType(GLSLParser.OUT);
|
||||
token.setText(GLSLParser.VOCABULARY.getLiteralName(GLSLParser.OUT).replace("'", ""));
|
||||
} else {
|
||||
token.setType(GLSLParser.IN);
|
||||
token.setText(GLSLParser.VOCABULARY.getLiteralName(GLSLParser.IN).replace("'", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFormattedShader(ParseTree tree, String string) {
|
||||
final StringBuilder sb = new StringBuilder(string + "\n");
|
||||
final String[] tabHolder = {""};
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package net.coderbot.iris.pipeline.transform;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.CeleritasTerrainParameters;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.ComputeParameters;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
|
||||
import net.coderbot.iris.pipeline.transform.parameter.TextureStageParameters;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -23,12 +30,16 @@ public class TransformPatcher {
|
||||
final Parameters parameters;
|
||||
final String vertex;
|
||||
final String geometry;
|
||||
final String tessControl;
|
||||
final String tessEval;
|
||||
final String fragment;
|
||||
|
||||
public CacheKey(Parameters parameters, String vertex, String geometry, String fragment) {
|
||||
public CacheKey(Parameters parameters, String vertex, String geometry, String tessControl, String tessEval, String fragment) {
|
||||
this.parameters = parameters;
|
||||
this.vertex = vertex;
|
||||
this.geometry = geometry;
|
||||
this.tessControl = tessControl;
|
||||
this.tessEval = tessEval;
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
@@ -38,6 +49,8 @@ public class TransformPatcher {
|
||||
int result = 1;
|
||||
result = prime * result + ((fragment == null) ? 0 : fragment.hashCode());
|
||||
result = prime * result + ((geometry == null) ? 0 : geometry.hashCode());
|
||||
result = prime * result + ((tessControl == null) ? 0 : tessControl.hashCode());
|
||||
result = prime * result + ((tessEval == null) ? 0 : tessEval.hashCode());
|
||||
result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
|
||||
result = prime * result + ((vertex == null) ? 0 : vertex.hashCode());
|
||||
return result;
|
||||
@@ -45,39 +58,20 @@ public class TransformPatcher {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
final TransformPatcher.CacheKey other = (TransformPatcher.CacheKey) obj;
|
||||
if (fragment == null) {
|
||||
if (other.fragment != null)
|
||||
return false;
|
||||
} else if (!fragment.equals(other.fragment))
|
||||
return false;
|
||||
if (geometry == null) {
|
||||
if (other.geometry != null)
|
||||
return false;
|
||||
} else if (!geometry.equals(other.geometry))
|
||||
return false;
|
||||
if (parameters == null) {
|
||||
if (other.parameters != null)
|
||||
return false;
|
||||
} else if (!parameters.equals(other.parameters))
|
||||
return false;
|
||||
if (vertex == null) {
|
||||
if (other.vertex != null)
|
||||
return false;
|
||||
} else if (!vertex.equals(other.vertex))
|
||||
return false;
|
||||
return true;
|
||||
return java.util.Objects.equals(fragment, other.fragment)
|
||||
&& java.util.Objects.equals(geometry, other.geometry)
|
||||
&& java.util.Objects.equals(tessControl, other.tessControl)
|
||||
&& java.util.Objects.equals(tessEval, other.tessEval)
|
||||
&& java.util.Objects.equals(parameters, other.parameters)
|
||||
&& java.util.Objects.equals(vertex, other.vertex);
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<PatchShaderType, String> transform(String vertex, String geometry, String fragment, Parameters parameters) {
|
||||
if (vertex == null && geometry == null && fragment == null) {
|
||||
private static Map<PatchShaderType, String> transform(String vertex, String geometry, String tessControl, String tessEval, String fragment, Parameters parameters) {
|
||||
if (vertex == null && geometry == null && tessControl == null && tessEval == null && fragment == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -85,7 +79,7 @@ public class TransformPatcher {
|
||||
TransformPatcher.CacheKey key = null;
|
||||
Map<PatchShaderType, String> result = null;
|
||||
if (useCache) {
|
||||
key = new TransformPatcher.CacheKey(parameters, vertex, geometry, fragment);
|
||||
key = new TransformPatcher.CacheKey(parameters, vertex, geometry, tessControl, tessEval, fragment);
|
||||
synchronized (cache) {
|
||||
result = cache.get(key);
|
||||
}
|
||||
@@ -93,7 +87,7 @@ public class TransformPatcher {
|
||||
|
||||
// if there is no cache result, transform the shaders
|
||||
if (result == null) {
|
||||
result = ShaderTransformer.transform(vertex, geometry, fragment, parameters);
|
||||
result = ShaderTransformer.transform(vertex, geometry, tessControl, tessEval, fragment, parameters);
|
||||
if (useCache) {
|
||||
synchronized (cache) {
|
||||
// Double-check in case another thread added it while we were transforming
|
||||
@@ -109,16 +103,40 @@ public class TransformPatcher {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchAttributes(String vertex, String geometry, String tessControl, String tessEval, String fragment, InputAvailability inputs) {
|
||||
return transform(vertex, geometry, tessControl, tessEval, fragment, new AttributeParameters(Patch.ATTRIBUTES, geometry != null, inputs));
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchAttributes(String vertex, String geometry, String fragment, InputAvailability inputs) {
|
||||
return transform(vertex, geometry, fragment, new AttributeParameters(Patch.ATTRIBUTES, geometry != null, inputs));
|
||||
return patchAttributes(vertex, geometry, null, null, fragment, inputs);
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchCeleritasTerrain(String vertex, String geometry, String fragment) {
|
||||
return transform(vertex, geometry, fragment, new Parameters(Patch.CELERITAS_TERRAIN));
|
||||
return transform(vertex, geometry, null, null, fragment, new CeleritasTerrainParameters(Patch.CELERITAS_TERRAIN));
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchComposite(String vertex, String geometry, String fragment) {
|
||||
return transform(vertex, geometry, fragment, new Parameters(Patch.COMPOSITE));
|
||||
return patchComposite(vertex, geometry, null, null, fragment, TextureStage.COMPOSITE_AND_FINAL, null);
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchComposite(String vertex, String geometry, String tessControl, String tessEval, String fragment) {
|
||||
return patchComposite(vertex, geometry, tessControl, tessEval, fragment, TextureStage.COMPOSITE_AND_FINAL, null);
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchComposite(String vertex, String geometry, String tessControl, String tessEval, String fragment, TextureStage stage, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return transform(vertex, geometry, tessControl, tessEval, fragment, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap));
|
||||
}
|
||||
|
||||
public static Map<PatchShaderType, String> patchComposite(String vertex, String geometry, String fragment, TextureStage stage, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
return patchComposite(vertex, geometry, null, null, fragment, stage, textureMap);
|
||||
}
|
||||
|
||||
public static String patchCompute(String name, String compute, TextureStage stage, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
if (compute == null) {
|
||||
return null;
|
||||
}
|
||||
Map<PatchShaderType, String> result = ShaderTransformer.transformCompute(compute, new ComputeParameters(Patch.COMPUTE, stage, textureMap));
|
||||
return result != null ? result.get(PatchShaderType.COMPUTE) : null;
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
|
||||
+40
-33
@@ -2,42 +2,49 @@ package net.coderbot.iris.pipeline.transform.parameter;
|
||||
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.InputAvailability;
|
||||
import net.coderbot.iris.pipeline.transform.Patch;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
|
||||
public class AttributeParameters extends Parameters {
|
||||
public final boolean hasGeometry;
|
||||
public final InputAvailability inputs;
|
||||
public final boolean hasGeometry;
|
||||
public final InputAvailability inputs;
|
||||
// WARNING: adding new fields requires updating hashCode and equals methods!
|
||||
|
||||
public AttributeParameters(Patch patch, boolean hasGeometry, InputAvailability inputs) {
|
||||
super(patch);
|
||||
this.hasGeometry = hasGeometry;
|
||||
this.inputs = inputs;
|
||||
}
|
||||
public AttributeParameters(Patch patch, boolean hasGeometry, InputAvailability inputs) {
|
||||
super(patch, null);
|
||||
this.hasGeometry = hasGeometry;
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + (hasGeometry ? 1231 : 1237);
|
||||
result = prime * result + ((inputs == null) ? 0 : inputs.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public TextureStage getTextureStage() {
|
||||
return TextureStage.GBUFFERS_AND_SHADOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AttributeParameters other = (AttributeParameters) obj;
|
||||
if (hasGeometry != other.hasGeometry)
|
||||
return false;
|
||||
if (inputs == null) {
|
||||
if (other.inputs != null)
|
||||
return false;
|
||||
} else if (!inputs.equals(other.inputs))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + (hasGeometry ? 1231 : 1237);
|
||||
result = prime * result + ((inputs == null) ? 0 : inputs.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AttributeParameters other = (AttributeParameters) obj;
|
||||
if (hasGeometry != other.hasGeometry)
|
||||
return false;
|
||||
if (inputs == null) {
|
||||
if (other.inputs != null)
|
||||
return false;
|
||||
} else if (!inputs.equals(other.inputs))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package net.coderbot.iris.pipeline.transform.parameter;
|
||||
|
||||
import net.coderbot.iris.pipeline.transform.Patch;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
|
||||
public class CeleritasTerrainParameters extends Parameters {
|
||||
// WARNING: adding new fields requires updating hashCode and equals methods!
|
||||
|
||||
public CeleritasTerrainParameters(Patch patch) {
|
||||
super(patch, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureStage getTextureStage() {
|
||||
return TextureStage.GBUFFERS_AND_SHADOW;
|
||||
}
|
||||
|
||||
// since this class has no additional fields, hashCode() and equals() are inherited from Parameters
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.coderbot.iris.pipeline.transform.parameter;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.gl.blending.AlphaTest;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
import net.coderbot.iris.pipeline.transform.Patch;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
|
||||
public class ComputeParameters extends TextureStageParameters {
|
||||
// WARNING: adding new fields requires updating hashCode and equals methods!
|
||||
|
||||
public ComputeParameters(Patch patch, TextureStage stage, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
super(patch, stage, textureMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlphaTest getAlphaTest() {
|
||||
return AlphaTest.ALWAYS;
|
||||
}
|
||||
|
||||
// since this class has no fields, hashCode() and equals() are inherited from
|
||||
// TextureStageParameters
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package net.coderbot.iris.pipeline.transform.parameter;
|
||||
|
||||
public interface JobParameters {
|
||||
|
||||
JobParameters EMPTY = new JobParameters() {
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
boolean equals(Object other);
|
||||
|
||||
int hashCode();
|
||||
}
|
||||
@@ -1,37 +1,59 @@
|
||||
package net.coderbot.iris.pipeline.transform.parameter;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.gl.blending.AlphaTest;
|
||||
import net.coderbot.iris.gl.shader.ShaderType;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
import net.coderbot.iris.pipeline.transform.Patch;
|
||||
import net.coderbot.iris.pipeline.transform.PatchShaderType;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
|
||||
public class Parameters implements JobParameters {
|
||||
public final Patch patch;
|
||||
public PatchShaderType type;
|
||||
// WARNING: adding new fields requires updating hashCode and equals methods!
|
||||
public abstract class Parameters {
|
||||
public final Patch patch;
|
||||
private final Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap;
|
||||
public ShaderType type;
|
||||
// WARNING: adding new fields requires updating hashCode and equals methods!
|
||||
|
||||
// name of the shader, this should not be part of hash/equals
|
||||
public String name; // set by TransformPatcher
|
||||
public Parameters(Patch patch, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
this.patch = patch;
|
||||
this.textureMap = textureMap;
|
||||
}
|
||||
|
||||
public Parameters(Patch patch) {
|
||||
this.patch = patch;
|
||||
}
|
||||
public AlphaTest getAlphaTest() {
|
||||
return AlphaTest.ALWAYS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((patch == null) ? 0 : patch.hashCode());
|
||||
return result;
|
||||
}
|
||||
public abstract TextureStage getTextureStage();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Parameters other = (Parameters) obj;
|
||||
return patch == other.patch;
|
||||
}
|
||||
public Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> getTextureMap() {
|
||||
return textureMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((patch == null) ? 0 : patch.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
result = prime * result + ((textureMap == null) ? 0 : textureMap.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Parameters other = (Parameters) obj;
|
||||
if (patch != other.patch)
|
||||
return false;
|
||||
if (type != other.type)
|
||||
return false;
|
||||
if (textureMap == null) {
|
||||
return other.textureMap == null;
|
||||
} else return textureMap.equals(other.textureMap);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package net.coderbot.iris.pipeline.transform.parameter;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.gl.blending.AlphaTest;
|
||||
import net.coderbot.iris.gl.texture.TextureType;
|
||||
import net.coderbot.iris.helpers.Tri;
|
||||
import net.coderbot.iris.pipeline.transform.Patch;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
|
||||
public class TextureStageParameters extends Parameters {
|
||||
private final TextureStage stage;
|
||||
// WARNING: adding new fields requires updating hashCode and equals methods!
|
||||
|
||||
public TextureStageParameters(Patch patch, TextureStage stage, Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
|
||||
super(patch, textureMap);
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureStage getTextureStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((stage == null) ? 0 : stage.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TextureStageParameters other = (TextureStageParameters) obj;
|
||||
return stage == other.stage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlphaTest getAlphaTest() {
|
||||
return AlphaTest.ALWAYS;
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class CenterDepthSampler {
|
||||
this.framebuffer.bind();
|
||||
this.program.use();
|
||||
|
||||
GL11.glViewport(0, 0, 1, 1);
|
||||
GLStateManager.glViewport(0, 0, 1, 1);
|
||||
|
||||
FullScreenQuadRenderer.INSTANCE.render();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import lombok.Getter;
|
||||
import net.coderbot.iris.features.FeatureFlags;
|
||||
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
|
||||
import net.coderbot.iris.gl.framebuffer.ViewportData;
|
||||
import net.coderbot.iris.gl.image.GlImage;
|
||||
@@ -29,7 +30,9 @@ import net.coderbot.iris.shaderpack.ComputeSource;
|
||||
import net.coderbot.iris.shaderpack.PackDirectives;
|
||||
import net.coderbot.iris.shaderpack.ProgramDirectives;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
import net.coderbot.iris.shadows.ShadowRenderTargets;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.uniforms.CommonUniforms;
|
||||
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import net.coderbot.iris.uniforms.custom.CustomUniforms;
|
||||
@@ -41,6 +44,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -61,6 +65,7 @@ public class CompositeRenderer {
|
||||
@Nullable private final Set<GlImage> customImages;
|
||||
@Nullable private final Object2ObjectMap<String, TextureAccess> irisCustomTextures;
|
||||
@Nullable private final WorldRenderingPipeline pipeline;
|
||||
private final TextureStage textureStage;
|
||||
@Getter
|
||||
private final ImmutableSet<Integer> flippedAtLeastOnceFinal;
|
||||
|
||||
@@ -71,10 +76,10 @@ public class CompositeRenderer {
|
||||
Object2ObjectMap<String, TextureAccess> customTextureIds, ImmutableMap<Integer, Boolean> explicitPreFlips,
|
||||
CustomUniforms customUniforms,
|
||||
Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> precomputedTransformFutures) {
|
||||
this(sources, computes, bufferFlipper, new ProgramBuildContext(renderTargets, noiseTexture, updateNotifier, centerDepthSampler, shadowTargetsSupplier, customTextureIds, customUniforms, null, null, null), explicitPreFlips, precomputedTransformFutures, "unknown");
|
||||
this(sources, computes, bufferFlipper, new ProgramBuildContext(renderTargets, noiseTexture, updateNotifier, centerDepthSampler, shadowTargetsSupplier, customTextureIds, customUniforms, null, null, null), explicitPreFlips, precomputedTransformFutures, "unknown", TextureStage.COMPOSITE_AND_FINAL);
|
||||
}
|
||||
|
||||
public CompositeRenderer(ProgramSource[] sources, ComputeSource[][] computes, BufferFlipper bufferFlipper, ProgramBuildContext context, ImmutableMap<Integer, Boolean> explicitPreFlips, Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> precomputedTransformFutures, String stageName) {
|
||||
public CompositeRenderer(ProgramSource[] sources, ComputeSource[][] computes, BufferFlipper bufferFlipper, ProgramBuildContext context, ImmutableMap<Integer, Boolean> explicitPreFlips, Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> precomputedTransformFutures, String stageName, TextureStage textureStage) {
|
||||
this.noiseTexture = context.noiseTexture();
|
||||
this.updateNotifier = context.updateNotifier();
|
||||
this.centerDepthSampler = context.centerDepthSampler();
|
||||
@@ -84,6 +89,7 @@ public class CompositeRenderer {
|
||||
this.customImages = context.customImages();
|
||||
this.irisCustomTextures = context.irisCustomTextures();
|
||||
this.pipeline = context.pipeline();
|
||||
this.textureStage = textureStage;
|
||||
|
||||
final ImmutableList.Builder<Pass> passes = ImmutableList.builder();
|
||||
final ImmutableSet.Builder<Integer> flippedAtLeastOnce = new ImmutableSet.Builder<>();
|
||||
@@ -167,7 +173,7 @@ public class CompositeRenderer {
|
||||
OpenGlHelper.func_153171_g/*glBindFramebuffer*/(GL30.GL_READ_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
private static Map<PatchShaderType, String> getTransformed(ProgramSource source, Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> transformFutures, int index, String stageName) {
|
||||
private Map<PatchShaderType, String> getTransformed(ProgramSource source, Map<Integer, CompletableFuture<Map<PatchShaderType, String>>> transformFutures, int index, String stageName) {
|
||||
if (transformFutures != null) {
|
||||
final CompletableFuture<Map<PatchShaderType, String>> future = transformFutures.get(index);
|
||||
if (future != null) {
|
||||
@@ -183,7 +189,7 @@ public class CompositeRenderer {
|
||||
}
|
||||
|
||||
// Fallback: transform synchronously
|
||||
return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new));
|
||||
return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new), this.textureStage, pipeline != null ? pipeline.getTextureMap() : null);
|
||||
}
|
||||
|
||||
public void recalculateSizes() {
|
||||
@@ -258,7 +264,7 @@ public class CompositeRenderer {
|
||||
}
|
||||
|
||||
if (ranCompute) {
|
||||
RenderSystem.memoryBarrier(40);
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
}
|
||||
|
||||
Program.unbind();
|
||||
@@ -279,7 +285,7 @@ public class CompositeRenderer {
|
||||
final float scaledHeight = renderPass.viewHeight * renderPass.viewportScale.scale();
|
||||
final float viewportX = renderPass.viewWidth * renderPass.viewportScale.viewportX();
|
||||
final float viewportY = renderPass.viewHeight * renderPass.viewportScale.viewportY();
|
||||
GL11.glViewport((int) viewportX, (int) viewportY, (int) scaledWidth, (int) scaledHeight);
|
||||
GLStateManager.glViewport((int) viewportX, (int) viewportY, (int) scaledWidth, (int) scaledHeight);
|
||||
|
||||
renderPass.framebuffer.bind();
|
||||
renderPass.program.use();
|
||||
@@ -339,21 +345,23 @@ public class CompositeRenderer {
|
||||
Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
|
||||
String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
|
||||
String tessEval = transformed.get(PatchShaderType.TESS_EVAL);
|
||||
String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment);
|
||||
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment,
|
||||
IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
throw new RuntimeException("Shader compilation failed!", e);
|
||||
}
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
@@ -369,7 +377,7 @@ public class CompositeRenderer {
|
||||
IrisSamplers.addCompositeSamplers(customTextureSamplerInterceptor, renderTargets);
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, false);
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, pipeline != null && pipeline.hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
|
||||
IrisImages.addShadowColorImages(builder, shadowTargetsSupplier.get(), null);
|
||||
}
|
||||
|
||||
@@ -395,7 +403,9 @@ public class CompositeRenderer {
|
||||
ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
String transformed = TransformPatcher.patchCompute(source.getName(), source.getSource().orElse(null), this.textureStage, pipeline != null ? pipeline.getTextureMap() : null);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName() + "_compute", null, null, null, transformed);
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), transformed, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
throw new RuntimeException("Shader compilation failed!", e);
|
||||
@@ -403,7 +413,7 @@ public class CompositeRenderer {
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
@@ -418,7 +428,7 @@ public class CompositeRenderer {
|
||||
IrisSamplers.addCompositeSamplers(customTextureSamplerInterceptor, renderTargets);
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, false);
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, pipeline != null && pipeline.hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
|
||||
IrisImages.addShadowColorImages(builder, shadowTargetsSupplier.get(), null);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.features.FeatureFlags;
|
||||
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
|
||||
import net.coderbot.iris.gl.image.GlImage;
|
||||
import net.coderbot.iris.gl.program.ComputeProgram;
|
||||
@@ -28,7 +29,9 @@ import net.coderbot.iris.shaderpack.ComputeSource;
|
||||
import net.coderbot.iris.shaderpack.ProgramDirectives;
|
||||
import net.coderbot.iris.shaderpack.ProgramSet;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
import net.coderbot.iris.shadows.ShadowRenderTargets;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.uniforms.CommonUniforms;
|
||||
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import net.coderbot.iris.uniforms.custom.CustomUniforms;
|
||||
@@ -40,6 +43,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -155,7 +159,7 @@ public class FinalPassRenderer {
|
||||
throw new RuntimeException("Shader transformation failed for '" + source.getName() + "' in stage '" + stageName + "'", e.getCause() != null ? e.getCause() : e);
|
||||
}
|
||||
}
|
||||
return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new));
|
||||
return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new));
|
||||
}
|
||||
|
||||
private static final class Pass {
|
||||
@@ -220,7 +224,7 @@ public class FinalPassRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
RenderSystem.memoryBarrier(40);
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
|
||||
if (!finalPass.mipmappedBuffers.isEmpty()) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
@@ -349,14 +353,16 @@ public class FinalPassRenderer {
|
||||
Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
|
||||
final String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
final String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
final String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
|
||||
final String tessEval = transformed.get(PatchShaderType.TESS_EVAL);
|
||||
final String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment);
|
||||
|
||||
Objects.requireNonNull(flipped);
|
||||
final ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment,
|
||||
IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
@@ -367,7 +373,7 @@ public class FinalPassRenderer {
|
||||
|
||||
final ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(builder, customTextureIds, flippedAtLeastOnceSnapshot);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true, pipeline);
|
||||
// Bind custom images as samplers BEFORE render target images
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, customImages);
|
||||
@@ -382,7 +388,7 @@ public class FinalPassRenderer {
|
||||
IrisSamplers.addCompositeSamplers(customTextureSamplerInterceptor, renderTargets);
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, false);
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, pipeline != null && pipeline.hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
|
||||
IrisImages.addShadowColorImages(builder, shadowTargetsSupplier.get(), null);
|
||||
}
|
||||
|
||||
@@ -408,7 +414,9 @@ public class FinalPassRenderer {
|
||||
final ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), source.getSource().orElse(null), IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
String transformed = TransformPatcher.patchCompute(source.getName(), source.getSource().orElse(null), TextureStage.COMPOSITE_AND_FINAL, pipeline != null ? pipeline.getTextureMap() : null);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName() + "_compute", null, null, null, transformed);
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), transformed, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
throw new RuntimeException("Shader compilation failed!", e);
|
||||
@@ -418,7 +426,7 @@ public class FinalPassRenderer {
|
||||
|
||||
customUniforms.assignTo(builder);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder);
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
IrisSamplers.addRenderTargetSamplers(customTextureSamplerInterceptor, () -> flipped, renderTargets, true, pipeline);
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, customImages);
|
||||
IrisSamplers.addCustomTextures(customTextureSamplerInterceptor, irisCustomTextures);
|
||||
@@ -430,7 +438,7 @@ public class FinalPassRenderer {
|
||||
IrisSamplers.addCompositeSamplers(customTextureSamplerInterceptor, renderTargets);
|
||||
|
||||
if (IrisSamplers.hasShadowSamplers(customTextureSamplerInterceptor)) {
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, false);
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, shadowTargetsSupplier.get(), null, pipeline != null && pipeline.hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
|
||||
IrisImages.addShadowColorImages(builder, shadowTargetsSupplier.get(), null);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public class IrisSamplers {
|
||||
final ImmutableList.Builder<String> shadowSamplers = ImmutableList.<String>builder()
|
||||
.add("shadowtex0", "shadowtex0HW", "shadowtex0DH", "shadowtex1", "shadowtex1HW", "shadowtex1DH", "shadow", "watershadow", "shadowcolor");
|
||||
|
||||
for (int i = 0; i < PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS; i++) {
|
||||
for (int i = 0; i < PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS_IRIS; i++) {
|
||||
shadowSamplers.add("shadowcolor" + i);
|
||||
shadowSamplers.add("shadowcolorimg" + i);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ public class PackDirectives {
|
||||
private boolean vignette;
|
||||
private boolean sun;
|
||||
private boolean moon;
|
||||
private boolean stars;
|
||||
private boolean sky;
|
||||
private boolean weather;
|
||||
private boolean weatherParticles;
|
||||
private boolean rainDepth;
|
||||
private boolean separateAo;
|
||||
private boolean voxelizeLightBlocks;
|
||||
@@ -76,6 +80,10 @@ public class PackDirectives {
|
||||
vignette = properties.getVignette().orElse(false);
|
||||
sun = properties.getSun().orElse(true);
|
||||
moon = properties.getMoon().orElse(true);
|
||||
stars = properties.getStars().orElse(true);
|
||||
sky = properties.getSky().orElse(true);
|
||||
weather = properties.getWeather().orElse(true);
|
||||
weatherParticles = properties.getWeatherParticles().orElse(true);
|
||||
rainDepth = properties.getRainDepth().orElse(false);
|
||||
separateAo = properties.getSeparateAo().orElse(false);
|
||||
voxelizeLightBlocks = properties.getVoxelizeLightBlocks().orElse(false);
|
||||
@@ -129,6 +137,22 @@ public class PackDirectives {
|
||||
return moon;
|
||||
}
|
||||
|
||||
public boolean shouldRenderStars() {
|
||||
return stars;
|
||||
}
|
||||
|
||||
public boolean shouldRenderSkyDisc() {
|
||||
return sky;
|
||||
}
|
||||
|
||||
public boolean shouldRenderWeather() {
|
||||
return weather;
|
||||
}
|
||||
|
||||
public boolean shouldRenderWeatherParticles() {
|
||||
return weatherParticles;
|
||||
}
|
||||
|
||||
public boolean rainDepth() {
|
||||
return rainDepth;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@ import org.joml.Vector4f;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PackShadowDirectives {
|
||||
// Bump this up if you want more shadow color buffers!
|
||||
// This is currently set at 2 for ShadersMod / OptiFine parity but can theoretically be bumped up to 8.
|
||||
// TODO: Make this configurable?
|
||||
public static final int MAX_SHADOW_COLOR_BUFFERS = 2;
|
||||
public static final int MAX_SHADOW_COLOR_BUFFERS_IRIS = 8;
|
||||
public static final int MAX_SHADOW_COLOR_BUFFERS_OF = 2;
|
||||
|
||||
private final OptionalBoolean shadowEnabled;
|
||||
|
||||
@@ -20,6 +18,7 @@ public class PackShadowDirectives {
|
||||
// Use a boxed form so we can use null to indicate that there is not an FOV specified.
|
||||
private Float fov;
|
||||
private float distance;
|
||||
private float voxelDistance;
|
||||
private float distanceRenderMul;
|
||||
private float entityShadowDistanceMul;
|
||||
private boolean explicitRenderDistance;
|
||||
@@ -54,6 +53,7 @@ public class PackShadowDirectives {
|
||||
// shadowRenderDistanceMul to a nonzero value, since having a high shadow render distance will impact
|
||||
// performance quite heavily on most systems.
|
||||
this.distance = 160.0f;
|
||||
this.voxelDistance = 0.0f;
|
||||
|
||||
// By default, shadows are not culled based on distance from the player. However, pack authors may
|
||||
// enable this by setting shadowRenderDistanceMul to a nonzero value.
|
||||
@@ -86,7 +86,7 @@ public class PackShadowDirectives {
|
||||
|
||||
ImmutableList.Builder<SamplingSettings> colorSamplingSettings = ImmutableList.builder();
|
||||
|
||||
for (int i = 0; i < MAX_SHADOW_COLOR_BUFFERS; i++) {
|
||||
for (int i = 0; i < MAX_SHADOW_COLOR_BUFFERS_IRIS; i++) {
|
||||
colorSamplingSettings.add(new SamplingSettings());
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public class PackShadowDirectives {
|
||||
this.resolution = shadowDirectives.resolution;
|
||||
this.fov = shadowDirectives.fov;
|
||||
this.distance = shadowDirectives.distance;
|
||||
this.voxelDistance = shadowDirectives.voxelDistance;
|
||||
this.distanceRenderMul = shadowDirectives.distanceRenderMul;
|
||||
this.entityShadowDistanceMul = shadowDirectives.entityShadowDistanceMul;
|
||||
this.explicitRenderDistance = shadowDirectives.explicitRenderDistance;
|
||||
@@ -124,6 +125,10 @@ public class PackShadowDirectives {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public float getVoxelDistance() {
|
||||
return voxelDistance;
|
||||
}
|
||||
|
||||
public float getDistanceRenderMul() {
|
||||
return distanceRenderMul;
|
||||
}
|
||||
@@ -192,6 +197,8 @@ public class PackShadowDirectives {
|
||||
directives.acceptConstFloatDirective("shadowIntervalSize",
|
||||
intervalSize -> this.intervalSize = intervalSize);
|
||||
|
||||
directives.acceptConstFloatDirective("voxelDistance", distance -> this.voxelDistance = distance);
|
||||
|
||||
acceptHardwareFilteringSettings(directives, depthSamplingSettings);
|
||||
acceptDepthMipmapSettings(directives, depthSamplingSettings);
|
||||
acceptColorMipmapSettings(directives, colorSamplingSettings);
|
||||
|
||||
@@ -21,6 +21,7 @@ public class ProgramDirectives {
|
||||
private static final ImmutableList<String> LEGACY_RENDER_TARGETS = PackRenderTargetDirectives.LEGACY_RENDER_TARGETS;
|
||||
|
||||
private final int[] drawBuffers;
|
||||
private boolean unknownDrawBuffers;
|
||||
private final ViewportData viewportScale;
|
||||
@Nullable
|
||||
private final AlphaTestOverride alphaTestOverride;
|
||||
@@ -40,6 +41,7 @@ public class ProgramDirectives {
|
||||
this.bufferBlendInformations = bufferBlendInformations;
|
||||
this.mipmappedBuffers = mipmappedBuffers;
|
||||
this.explicitFlips = explicitFlips;
|
||||
this.unknownDrawBuffers = false;
|
||||
}
|
||||
|
||||
ProgramDirectives(ProgramSource source, ShaderProperties properties, Set<Integer> supportedRenderTargets, @Nullable BlendModeOverride defaultBlendOverride) {
|
||||
@@ -53,7 +55,7 @@ public class ProgramDirectives {
|
||||
final Optional<CommentDirective> optionalDrawbuffersDirective = findDrawbuffersDirective(source.getFragmentSource());
|
||||
final Optional<CommentDirective> optionalRendertargetsDirective = findRendertargetsDirective(source.getFragmentSource());
|
||||
|
||||
final Optional<CommentDirective> optionalCommentDirective = getAppliedDirective(optionalDrawbuffersDirective, optionalRendertargetsDirective);
|
||||
Optional<CommentDirective> optionalCommentDirective = getAppliedDirective(optionalDrawbuffersDirective, optionalRendertargetsDirective);
|
||||
drawBuffers = optionalCommentDirective.map(commentDirective -> {
|
||||
if (commentDirective.getType() == CommentDirective.Type.DRAWBUFFERS) {
|
||||
return parseDigits(commentDirective.getDirective().toCharArray());
|
||||
@@ -62,7 +64,10 @@ public class ProgramDirectives {
|
||||
} else {
|
||||
throw new IllegalStateException("Unhandled comment directive type!");
|
||||
}
|
||||
}).orElse(new int[] { 0 });
|
||||
}).orElseGet(() -> {
|
||||
unknownDrawBuffers = true;
|
||||
return new int[]{0};
|
||||
});
|
||||
|
||||
if (properties != null) {
|
||||
viewportScale = properties.getViewportScaleOverrides().getOrDefault(source.getName(), ViewportData.defaultValue());
|
||||
@@ -160,6 +165,10 @@ public class ProgramDirectives {
|
||||
return drawBuffers;
|
||||
}
|
||||
|
||||
public boolean hasUnknownDrawBuffers() {
|
||||
return unknownDrawBuffers;
|
||||
}
|
||||
|
||||
public ViewportData getViewportScale() {
|
||||
return viewportScale;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public class ProgramSet {
|
||||
|
||||
private final ProgramSource[] shadowcomp;
|
||||
private final ComputeSource[][] shadowCompCompute;
|
||||
private final ComputeSource[] setup;
|
||||
private final ProgramSource[] begin;
|
||||
private final ComputeSource[][] beginCompute;
|
||||
private final ProgramSource[] prepare;
|
||||
private final ComputeSource[][] prepareCompute;
|
||||
|
||||
@@ -82,6 +85,14 @@ public class ProgramSet {
|
||||
this.shadowCompCompute[i] = readComputeArray(directory, sourceProvider, "shadowcomp" + ((i == 0) ? "" : i));
|
||||
}
|
||||
|
||||
this.setup = readComputeProgramArray(directory, sourceProvider, "setup");
|
||||
|
||||
this.begin = readProgramArray(directory, sourceProvider, "begin", shaderProperties);
|
||||
this.beginCompute = new ComputeSource[begin.length][];
|
||||
for (int i = 0; i < begin.length; i++) {
|
||||
this.beginCompute[i] = readComputeArray(directory, sourceProvider, "begin" + ((i == 0) ? "" : i));
|
||||
}
|
||||
|
||||
this.prepare = readProgramArray(directory, sourceProvider, "prepare", shaderProperties);
|
||||
this.prepareCompute = new ComputeSource[prepare.length][];
|
||||
for (int i = 0; i < prepare.length; i++) {
|
||||
@@ -162,6 +173,18 @@ public class ProgramSet {
|
||||
return programs;
|
||||
}
|
||||
|
||||
private ComputeSource[] readComputeProgramArray(AbsolutePackPath directory, Function<AbsolutePackPath, String> sourceProvider, String name) {
|
||||
ComputeSource[] programs = new ComputeSource[100];
|
||||
|
||||
for (int i = 0; i < programs.length; i++) {
|
||||
String suffix = i == 0 ? "" : Integer.toString(i);
|
||||
|
||||
programs[i] = readComputeSource(directory, sourceProvider, name + suffix, this);
|
||||
}
|
||||
|
||||
return programs;
|
||||
}
|
||||
|
||||
private ComputeSource[] readComputeArray(AbsolutePackPath directory,
|
||||
Function<AbsolutePackPath, String> sourceProvider, String name) {
|
||||
ComputeSource[] programs = new ComputeSource[27];
|
||||
@@ -187,6 +210,7 @@ public class ProgramSet {
|
||||
|
||||
programs.add(shadow);
|
||||
programs.addAll(Arrays.asList(shadowcomp));
|
||||
programs.addAll(Arrays.asList(begin));
|
||||
programs.addAll(Arrays.asList(prepare));
|
||||
|
||||
programs.addAll (Arrays.asList(
|
||||
@@ -212,6 +236,16 @@ public class ProgramSet {
|
||||
computes.addAll(Arrays.asList(computeSources));
|
||||
}
|
||||
|
||||
for (ComputeSource computeSource : setup) {
|
||||
if (computeSource != null) {
|
||||
computes.add(computeSource);
|
||||
}
|
||||
}
|
||||
|
||||
for (ComputeSource[] computeSources : beginCompute) {
|
||||
computes.addAll(Arrays.asList(computeSources));
|
||||
}
|
||||
|
||||
Collections.addAll(computes, finalCompute);
|
||||
Collections.addAll(computes, shadowCompute);
|
||||
|
||||
@@ -263,6 +297,18 @@ public class ProgramSet {
|
||||
return shadowcomp;
|
||||
}
|
||||
|
||||
public ComputeSource[] getSetup() {
|
||||
return setup;
|
||||
}
|
||||
|
||||
public ProgramSource[] getBegin() {
|
||||
return begin;
|
||||
}
|
||||
|
||||
public ComputeSource[][] getBeginCompute() {
|
||||
return beginCompute;
|
||||
}
|
||||
|
||||
public ProgramSource[] getPrepare() {
|
||||
return prepare;
|
||||
}
|
||||
@@ -431,11 +477,21 @@ public class ProgramSet {
|
||||
AbsolutePackPath geometryPath = directory.resolve(program + ".gsh");
|
||||
String geometrySource = sourceProvider.apply(geometryPath);
|
||||
|
||||
String tessControlSource = null;
|
||||
String tessEvalSource = null;
|
||||
if (programSet.pack.hasFeature(net.coderbot.iris.features.FeatureFlags.TESSELLATION_SHADERS)) {
|
||||
AbsolutePackPath tessControlPath = directory.resolve(program + ".tcs");
|
||||
tessControlSource = sourceProvider.apply(tessControlPath);
|
||||
|
||||
AbsolutePackPath tessEvalPath = directory.resolve(program + ".tes");
|
||||
tessEvalSource = sourceProvider.apply(tessEvalPath);
|
||||
}
|
||||
|
||||
AbsolutePackPath fragmentPath = directory.resolve(program + ".fsh");
|
||||
String fragmentSource = sourceProvider.apply(fragmentPath);
|
||||
|
||||
return new ProgramSource(program, vertexSource, geometrySource, fragmentSource, programSet, properties,
|
||||
defaultBlendModeOverride);
|
||||
return new ProgramSource(program, vertexSource, geometrySource, tessControlSource, tessEvalSource,
|
||||
fragmentSource, programSet, properties, defaultBlendModeOverride);
|
||||
}
|
||||
|
||||
private static ComputeSource readComputeSource(AbsolutePackPath directory,
|
||||
|
||||
@@ -8,25 +8,33 @@ public class ProgramSource {
|
||||
private final String name;
|
||||
private final String vertexSource;
|
||||
private final String geometrySource;
|
||||
private final String tessControlSource;
|
||||
private final String tessEvalSource;
|
||||
private final String fragmentSource;
|
||||
private final ProgramDirectives directives;
|
||||
private final ProgramSet parent;
|
||||
|
||||
private ProgramSource(String name, String vertexSource, String geometrySource, String fragmentSource,
|
||||
private ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource,
|
||||
String tessEvalSource, String fragmentSource,
|
||||
ProgramDirectives directives, ProgramSet parent) {
|
||||
this.name = name;
|
||||
this.vertexSource = vertexSource;
|
||||
this.geometrySource = geometrySource;
|
||||
this.tessControlSource = tessControlSource;
|
||||
this.tessEvalSource = tessEvalSource;
|
||||
this.fragmentSource = fragmentSource;
|
||||
this.directives = directives;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public ProgramSource(String name, String vertexSource, String geometrySource, String fragmentSource,
|
||||
public ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource,
|
||||
String tessEvalSource, String fragmentSource,
|
||||
ProgramSet parent, ShaderProperties properties, BlendModeOverride defaultBlendModeOverride) {
|
||||
this.name = name;
|
||||
this.vertexSource = vertexSource;
|
||||
this.geometrySource = geometrySource;
|
||||
this.tessControlSource = tessControlSource;
|
||||
this.tessEvalSource = tessEvalSource;
|
||||
this.fragmentSource = fragmentSource;
|
||||
this.parent = parent;
|
||||
this.directives = new ProgramDirectives(this, properties,
|
||||
@@ -34,7 +42,7 @@ public class ProgramSource {
|
||||
}
|
||||
|
||||
public ProgramSource withDirectiveOverride(ProgramDirectives overrideDirectives) {
|
||||
return new ProgramSource(name, vertexSource, geometrySource, fragmentSource, overrideDirectives, parent);
|
||||
return new ProgramSource(name, vertexSource, geometrySource, tessControlSource, tessEvalSource, fragmentSource, overrideDirectives, parent);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -49,6 +57,14 @@ public class ProgramSource {
|
||||
return Optional.ofNullable(geometrySource);
|
||||
}
|
||||
|
||||
public Optional<String> getTessControlSource() {
|
||||
return Optional.ofNullable(tessControlSource);
|
||||
}
|
||||
|
||||
public Optional<String> getTessEvalSource() {
|
||||
return Optional.ofNullable(tessEvalSource);
|
||||
}
|
||||
|
||||
public Optional<String> getFragmentSource() {
|
||||
return Optional.ofNullable(fragmentSource);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class ShaderPack {
|
||||
public final CustomUniforms.Builder customUniforms;
|
||||
|
||||
private final ProgramSet base;
|
||||
private final Set<FeatureFlags> activeFeatures;
|
||||
|
||||
private final Map<String, String> dimensionMap;
|
||||
private final Map<String, ProgramSet> dimensionProgramSets;
|
||||
@@ -211,15 +212,32 @@ public class ShaderPack {
|
||||
List<StringPair> finalEnvironmentDefines = new ArrayList<>();
|
||||
environmentDefines.forEach(finalEnvironmentDefines::add);
|
||||
for (FeatureFlags flag : FeatureFlags.values()) {
|
||||
if (flag.isUsable()) {
|
||||
boolean usable = flag.isUsable();
|
||||
Iris.logger.info("FeatureFlag {} usable: {}", flag.name(), usable);
|
||||
if (usable) {
|
||||
finalEnvironmentDefines.add(new StringPair("IRIS_FEATURE_" + flag.name(), ""));
|
||||
if (flag == FeatureFlags.TESSELLATION_SHADERS) {
|
||||
finalEnvironmentDefines.add(new StringPair("IRIS_FEATURE_TESSELATION_SHADERS", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
Iris.logger.info("Environment defines: {}", finalEnvironmentDefines.stream()
|
||||
.map(p -> p.getKey() + "=" + p.getValue())
|
||||
.collect(java.util.stream.Collectors.joining(", ")));
|
||||
|
||||
this.shaderProperties = Optional.ofNullable(readProperties(root, "shaders.properties"))
|
||||
.map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines))
|
||||
.orElseGet(ShaderProperties::empty);
|
||||
|
||||
// Build the set of active feature flags from required and optional flags
|
||||
this.activeFeatures = new HashSet<>();
|
||||
for (String flag : shaderProperties.getRequiredFeatureFlags()) {
|
||||
activeFeatures.add(FeatureFlags.getValue(flag));
|
||||
}
|
||||
for (String flag : shaderProperties.getOptionalFeatureFlags()) {
|
||||
activeFeatures.add(FeatureFlags.getValue(flag));
|
||||
}
|
||||
|
||||
List<FeatureFlags> invalidFlagList = shaderProperties.getRequiredFeatureFlags().stream().filter(FeatureFlags::isInvalid).map(FeatureFlags::getValue).collect(Collectors.toList());
|
||||
List<String> invalidFeatureFlags = invalidFlagList.stream().map(FeatureFlags::getHumanReadableName).collect(Collectors.toList());
|
||||
|
||||
@@ -717,4 +735,11 @@ public class ShaderPack {
|
||||
return Optional.ofNullable(customNoiseTexture);
|
||||
}
|
||||
|
||||
public Set<FeatureFlags> getActiveFeatures() {
|
||||
return activeFeatures;
|
||||
}
|
||||
|
||||
public boolean hasFeature(FeatureFlags feature) {
|
||||
return activeFeatures.contains(feature);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,10 @@ public class ShaderProperties {
|
||||
@Getter private OptionalBoolean underwaterOverlay = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean sun = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean moon = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean stars = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean sky = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean weather = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean weatherParticles = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean vignette = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean backFaceSolid = OptionalBoolean.DEFAULT;
|
||||
@Getter private OptionalBoolean backFaceCutout = OptionalBoolean.DEFAULT;
|
||||
@@ -184,8 +188,8 @@ public class ShaderProperties {
|
||||
shadowCulling = ShadowCullState.DISTANCE;
|
||||
} else if ("true".equals(value)) {
|
||||
shadowCulling = ShadowCullState.ADVANCED;
|
||||
} else if ("reversed".equals(value)) {
|
||||
shadowCulling = ShadowCullState.REVERSED;
|
||||
} else if ("reversed".equals(value) || "safe_zone".equals(value)) {
|
||||
shadowCulling = ShadowCullState.SAFE_ZONE;
|
||||
} else {
|
||||
Iris.logger.error("Unrecognized shadow culling setting: " + value);
|
||||
}
|
||||
@@ -203,6 +207,8 @@ public class ShaderProperties {
|
||||
handleBooleanDirective(key, value, "underwaterOverlay", bool -> underwaterOverlay = bool);
|
||||
handleBooleanDirective(key, value, "sun", bool -> sun = bool);
|
||||
handleBooleanDirective(key, value, "moon", bool -> moon = bool);
|
||||
handleBooleanDirective(key, value, "stars", bool -> stars = bool);
|
||||
handleBooleanDirective(key, value, "sky", bool -> sky = bool);
|
||||
handleBooleanDirective(key, value, "vignette", bool -> vignette = bool);
|
||||
handleBooleanDirective(key, value, "backFace.solid", bool -> backFaceSolid = bool);
|
||||
handleBooleanDirective(key, value, "backFace.cutout", bool -> backFaceCutout = bool);
|
||||
@@ -227,6 +233,14 @@ public class ShaderProperties {
|
||||
handleBooleanDirective(key, value, "supportsColorCorrection", bool -> supportsColorCorrection = bool);
|
||||
handleIntDirective(key, value, "fallbackTex", val -> fallbackTex = val);
|
||||
|
||||
if ("weather".equals(key)) {
|
||||
String[] parts = value.split(" ");
|
||||
weather = parts[0].equals("true") ? OptionalBoolean.TRUE : OptionalBoolean.FALSE;
|
||||
if (parts.length > 1) {
|
||||
weatherParticles = parts[1].equals("true") ? OptionalBoolean.TRUE : OptionalBoolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.startsWith("particles.ordering")) {
|
||||
Optional<ParticleRenderingSettings> settings = ParticleRenderingSettings.fromString(value.trim().toUpperCase(Locale.ROOT));
|
||||
if (settings.isPresent()) {
|
||||
|
||||
@@ -3,6 +3,6 @@ package net.coderbot.iris.shaderpack;
|
||||
public enum ShadowCullState {
|
||||
DEFAULT,
|
||||
ADVANCED,
|
||||
REVERSED,
|
||||
SAFE_ZONE,
|
||||
DISTANCE
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
package net.coderbot.iris.shadows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import net.coderbot.iris.features.FeatureFlags;
|
||||
import net.coderbot.iris.gl.buffer.ShaderStorageBufferHolder;
|
||||
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
|
||||
import net.coderbot.iris.gl.framebuffer.ViewportData;
|
||||
import net.coderbot.iris.gl.image.GlImage;
|
||||
import net.coderbot.iris.gl.program.ComputeProgram;
|
||||
import net.coderbot.iris.gl.program.Program;
|
||||
import net.coderbot.iris.gl.program.ProgramBuilder;
|
||||
import net.coderbot.iris.gl.program.ProgramSamplers;
|
||||
import net.coderbot.iris.gl.program.ProgramUniforms;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.gl.texture.TextureAccess;
|
||||
import net.coderbot.iris.pipeline.PatchedShaderPrinter;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.pipeline.transform.PatchShaderType;
|
||||
import net.coderbot.iris.pipeline.transform.TransformPatcher;
|
||||
import net.coderbot.iris.postprocess.FullScreenQuadRenderer;
|
||||
import net.coderbot.iris.rendertarget.RenderTarget;
|
||||
import net.coderbot.iris.samplers.IrisImages;
|
||||
import net.coderbot.iris.samplers.IrisSamplers;
|
||||
import net.coderbot.iris.shaderpack.ComputeSource;
|
||||
import net.coderbot.iris.shaderpack.FilledIndirectPointer;
|
||||
import net.coderbot.iris.shaderpack.PackDirectives;
|
||||
import net.coderbot.iris.shaderpack.PackRenderTargetDirectives;
|
||||
import net.coderbot.iris.shaderpack.ProgramDirectives;
|
||||
import net.coderbot.iris.shaderpack.ProgramSource;
|
||||
import net.coderbot.iris.shaderpack.texture.TextureStage;
|
||||
import net.coderbot.iris.uniforms.CommonUniforms;
|
||||
import net.coderbot.iris.uniforms.FrameUpdateNotifier;
|
||||
import net.coderbot.iris.uniforms.custom.CustomUniforms;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.shader.Framebuffer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
import org.lwjgl.opengl.GL42;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ShadowCompositeRenderer {
|
||||
|
||||
private final ShadowRenderTargets renderTargets;
|
||||
|
||||
private final ImmutableList<Pass> passes;
|
||||
private final TextureAccess noiseTexture;
|
||||
private final FrameUpdateNotifier updateNotifier;
|
||||
private final Object2ObjectMap<String, TextureAccess> customTextureIds;
|
||||
private final ImmutableSet<Integer> flippedAtLeastOnceFinal;
|
||||
private final CustomUniforms customUniforms;
|
||||
private final Object2ObjectMap<String, TextureAccess> irisCustomTextures;
|
||||
private final WorldRenderingPipeline pipeline;
|
||||
private final Set<GlImage> irisCustomImages;
|
||||
@Nullable
|
||||
private final ShaderStorageBufferHolder ssboHolder;
|
||||
|
||||
public ShadowCompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDirectives, ProgramSource[] sources, ComputeSource[][] computes,
|
||||
ShadowRenderTargets renderTargets, @Nullable ShaderStorageBufferHolder ssboHolder, TextureAccess noiseTexture, FrameUpdateNotifier updateNotifier,
|
||||
Object2ObjectMap<String, TextureAccess> customTextureIds, Set<GlImage> customImages, ImmutableMap<Integer, Boolean> explicitPreFlips,
|
||||
Object2ObjectMap<String, TextureAccess> irisCustomTextures, CustomUniforms customUniforms) {
|
||||
this.pipeline = pipeline;
|
||||
this.noiseTexture = noiseTexture;
|
||||
this.updateNotifier = updateNotifier;
|
||||
this.renderTargets = renderTargets;
|
||||
this.ssboHolder = ssboHolder;
|
||||
this.customTextureIds = customTextureIds;
|
||||
this.irisCustomTextures = irisCustomTextures;
|
||||
this.irisCustomImages = customImages;
|
||||
this.customUniforms = customUniforms;
|
||||
|
||||
final PackRenderTargetDirectives renderTargetDirectives = packDirectives.getRenderTargetDirectives();
|
||||
final Map<Integer, PackRenderTargetDirectives.RenderTargetSettings> renderTargetSettings = renderTargetDirectives.getRenderTargetSettings();
|
||||
|
||||
final ImmutableList.Builder<Pass> passes = ImmutableList.builder();
|
||||
final ImmutableSet.Builder<Integer> flippedAtLeastOnce = new ImmutableSet.Builder<>();
|
||||
|
||||
explicitPreFlips.forEach((buffer, shouldFlip) -> {
|
||||
if (shouldFlip) {
|
||||
renderTargets.flip(buffer);
|
||||
// NB: Flipping deferred_pre or composite_pre does NOT cause the "flippedAtLeastOnce" flag to trigger
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0, sourcesLength = sources.length; i < sourcesLength; i++) {
|
||||
ProgramSource source = sources[i];
|
||||
|
||||
ImmutableSet<Integer> flipped = renderTargets.snapshot();
|
||||
ImmutableSet<Integer> flippedAtLeastOnceSnapshot = flippedAtLeastOnce.build();
|
||||
|
||||
if (source == null || !source.isValid()) {
|
||||
if (computes[i] != null) {
|
||||
ComputeOnlyPass pass = new ComputeOnlyPass();
|
||||
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, renderTargets);
|
||||
passes.add(pass);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Pass pass = new Pass();
|
||||
ProgramDirectives directives = source.getDirectives();
|
||||
|
||||
pass.program = createProgram(source, flipped, flippedAtLeastOnceSnapshot, renderTargets);
|
||||
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, renderTargets);
|
||||
int[] drawBuffers = directives.hasUnknownDrawBuffers() ? new int[] { 0, 1 } : directives.getDrawBuffers();
|
||||
|
||||
GlFramebuffer framebuffer = renderTargets.createColorFramebuffer(flipped, drawBuffers);
|
||||
|
||||
pass.stageReadsFromAlt = flipped;
|
||||
pass.framebuffer = framebuffer;
|
||||
pass.viewportScale = directives.getViewportScale();
|
||||
pass.mipmappedBuffers = directives.getMipmappedBuffers();
|
||||
pass.flippedAtLeastOnce = flippedAtLeastOnceSnapshot;
|
||||
|
||||
passes.add(pass);
|
||||
|
||||
ImmutableMap<Integer, Boolean> explicitFlips = directives.getExplicitFlips();
|
||||
|
||||
// Flip the buffers that this shader wrote to
|
||||
for (int buffer : drawBuffers) {
|
||||
// compare with boxed Boolean objects to avoid NPEs
|
||||
if (explicitFlips.get(buffer) == Boolean.FALSE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
renderTargets.flip(buffer);
|
||||
flippedAtLeastOnce.add(buffer);
|
||||
}
|
||||
|
||||
explicitFlips.forEach((buffer, shouldFlip) -> {
|
||||
if (shouldFlip) {
|
||||
renderTargets.flip(buffer);
|
||||
flippedAtLeastOnce.add(buffer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.passes = passes.build();
|
||||
this.flippedAtLeastOnceFinal = flippedAtLeastOnce.build();
|
||||
|
||||
GLStateManager.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
private static void setupMipmapping(RenderTarget target, boolean readFromAlt) {
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();
|
||||
|
||||
// TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer
|
||||
// (since the last mipmap was generated)
|
||||
//
|
||||
// NB: We leave mipmapping enabled even if the buffer is written to again, this appears to match the
|
||||
// behavior of ShadersMod/OptiFine, however I'm not sure if it's desired behavior. It's possible that a
|
||||
// program could use mipmapped sampling with a stale mipmap, which probably isn't great. However, the
|
||||
// sampling mode is always reset between frames, so this only persists after the first program to use
|
||||
// mipmapping on this buffer.
|
||||
//
|
||||
// Also note that this only applies to one of the two buffers in a render target buffer pair - making it
|
||||
// unlikely that this issue occurs in practice with most shader packs.
|
||||
RenderSystem.generateMipmaps(texture, GL11.GL_TEXTURE_2D);
|
||||
RenderSystem.texParameteri(texture, GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, target.getInternalFormat().getPixelFormat().isInteger() ? GL11.GL_NEAREST_MIPMAP_NEAREST : GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
private static void resetRenderTarget(RenderTarget target) {
|
||||
// Resets the sampling mode of the given render target and then unbinds it to prevent accidental sampling of it
|
||||
// elsewhere.
|
||||
|
||||
int filter = GL11.GL_LINEAR;
|
||||
if (target.getInternalFormat().getPixelFormat().isInteger()) {
|
||||
filter = GL11.GL_NEAREST;
|
||||
}
|
||||
|
||||
RenderSystem.texParameteri(target.getMainTexture(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter);
|
||||
RenderSystem.texParameteri(target.getAltTexture(), GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter);
|
||||
}
|
||||
|
||||
public ImmutableSet<Integer> getFlippedAtLeastOnceFinal() {
|
||||
return this.flippedAtLeastOnceFinal;
|
||||
}
|
||||
|
||||
public void renderAll() {
|
||||
GLStateManager.disableBlend();
|
||||
|
||||
FullScreenQuadRenderer.INSTANCE.begin();
|
||||
|
||||
for (Pass renderPass : passes) {
|
||||
boolean ranCompute = false;
|
||||
for (ComputeProgram computeProgram : renderPass.computes) {
|
||||
if (computeProgram != null) {
|
||||
ranCompute = true;
|
||||
final Framebuffer main = Minecraft.getMinecraft().getFramebuffer();
|
||||
computeProgram.use();
|
||||
this.customUniforms.push(computeProgram);
|
||||
computeProgram.dispatch(main.framebufferWidth, main.framebufferHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if (ranCompute) {
|
||||
// Memory barrier for shader image access and texture fetch
|
||||
RenderSystem.memoryBarrier(GL42.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL42.GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
}
|
||||
|
||||
Program.unbind();
|
||||
|
||||
if (renderPass instanceof ComputeOnlyPass) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!renderPass.mipmappedBuffers.isEmpty()) {
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
for (int index : renderPass.mipmappedBuffers) {
|
||||
setupMipmapping(renderTargets.get(index), renderPass.stageReadsFromAlt.contains(index));
|
||||
}
|
||||
}
|
||||
|
||||
float scaledWidth = renderTargets.getResolution() * renderPass.viewportScale.scale();
|
||||
float scaledHeight = renderTargets.getResolution() * renderPass.viewportScale.scale();
|
||||
int beginWidth = (int) (renderTargets.getResolution() * renderPass.viewportScale.viewportX());
|
||||
int beginHeight = (int) (renderTargets.getResolution() * renderPass.viewportScale.viewportY());
|
||||
GLStateManager.glViewport(beginWidth, beginHeight, (int) scaledWidth, (int) scaledHeight);
|
||||
|
||||
renderPass.framebuffer.bind();
|
||||
renderPass.program.use();
|
||||
|
||||
this.customUniforms.push(renderPass.program);
|
||||
|
||||
FullScreenQuadRenderer.INSTANCE.renderQuad();
|
||||
}
|
||||
|
||||
FullScreenQuadRenderer.INSTANCE.end();
|
||||
|
||||
ProgramUniforms.clearActiveUniforms();
|
||||
ProgramSamplers.clearActiveSamplers();
|
||||
|
||||
for (int i = 0; i < renderTargets.getRenderTargetCount(); i++) {
|
||||
// Reset mipmapping states at the end of the frame.
|
||||
if (renderTargets.get(i) != null) {
|
||||
resetRenderTarget(renderTargets.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
GLStateManager.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
}
|
||||
|
||||
// TODO: Don't just copy this from DeferredWorldRenderingPipeline
|
||||
private Program createProgram(ProgramSource source, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot,
|
||||
ShadowRenderTargets targets) {
|
||||
// TODO: Properly handle empty shaders
|
||||
Map<PatchShaderType, String> transformed = TransformPatcher.patchComposite(
|
||||
source.getVertexSource().orElseThrow(NullPointerException::new),
|
||||
source.getGeometrySource().orElse(null),
|
||||
source.getTessControlSource().orElse(null),
|
||||
source.getTessEvalSource().orElse(null),
|
||||
source.getFragmentSource().orElseThrow(NullPointerException::new));
|
||||
String vertex = transformed.get(PatchShaderType.VERTEX);
|
||||
String geometry = transformed.get(PatchShaderType.GEOMETRY);
|
||||
String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
|
||||
String tessEval = transformed.get(PatchShaderType.TESS_EVAL);
|
||||
String fragment = transformed.get(PatchShaderType.FRAGMENT);
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment);
|
||||
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
throw new RuntimeException("Shader compilation failed for shadow composite " + source.getName() + "!", e);
|
||||
}
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(
|
||||
builder,
|
||||
customTextureIds,
|
||||
flippedAtLeastOnceSnapshot);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
this.customUniforms.assignTo(builder);
|
||||
|
||||
IrisSamplers.addNoiseSampler(customTextureSamplerInterceptor, noiseTexture);
|
||||
IrisSamplers.addCustomTextures(customTextureSamplerInterceptor, irisCustomTextures);
|
||||
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, targets, flipped, pipeline.hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
|
||||
IrisImages.addShadowColorImages(builder, targets, flipped);
|
||||
IrisImages.addCustomImages(builder, irisCustomImages);
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, irisCustomImages);
|
||||
Program build = builder.build();
|
||||
this.customUniforms.mapholderToPass(builder, build);
|
||||
|
||||
return build;
|
||||
}
|
||||
|
||||
private ComputeProgram[] createComputes(ComputeSource[] sources, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot,
|
||||
ShadowRenderTargets targets) {
|
||||
if (sources == null) {
|
||||
return new ComputeProgram[0];
|
||||
}
|
||||
|
||||
ComputeProgram[] programs = new ComputeProgram[sources.length];
|
||||
for (int i = 0; i < programs.length; i++) {
|
||||
ComputeSource source = sources[i];
|
||||
if (source == null || !source.getSource().isPresent()) {
|
||||
continue;
|
||||
} else {
|
||||
Objects.requireNonNull(flipped);
|
||||
ProgramBuilder builder;
|
||||
|
||||
try {
|
||||
String transformed = TransformPatcher.patchCompute(source.getName(), source.getSource().orElse(null),
|
||||
TextureStage.SHADOWCOMP, pipeline.getTextureMap());
|
||||
PatchedShaderPrinter.debugPatchedShaders(source.getName() + "_compute", null, null, null, transformed);
|
||||
builder = ProgramBuilder.beginCompute(source.getName(), transformed, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS);
|
||||
} catch (RuntimeException e) {
|
||||
// TODO: Better error handling
|
||||
throw new RuntimeException("Shader compilation failed for shadowcomp compute " + source.getName() + "!", e);
|
||||
}
|
||||
|
||||
ProgramSamplers.CustomTextureSamplerInterceptor customTextureSamplerInterceptor = ProgramSamplers.customTextureSamplerInterceptor(
|
||||
builder,
|
||||
customTextureIds,
|
||||
flippedAtLeastOnceSnapshot);
|
||||
|
||||
CommonUniforms.addDynamicUniforms(builder, FogMode.OFF);
|
||||
this.customUniforms.assignTo(builder);
|
||||
IrisSamplers.addNoiseSampler(customTextureSamplerInterceptor, noiseTexture);
|
||||
IrisSamplers.addCustomTextures(customTextureSamplerInterceptor, irisCustomTextures);
|
||||
|
||||
IrisSamplers.addShadowSamplers(customTextureSamplerInterceptor, targets, flipped, pipeline.hasFeature(FeatureFlags.SEPARATE_HARDWARE_SAMPLERS));
|
||||
IrisImages.addShadowColorImages(builder, targets, flipped);
|
||||
|
||||
IrisImages.addCustomImages(builder, irisCustomImages);
|
||||
IrisSamplers.addCustomImages(customTextureSamplerInterceptor, irisCustomImages);
|
||||
programs[i] = builder.buildCompute();
|
||||
|
||||
this.customUniforms.mapholderToPass(builder, programs[i]);
|
||||
|
||||
programs[i].setWorkGroupInfo(
|
||||
source.getWorkGroupRelative(),
|
||||
source.getWorkGroups(),
|
||||
ssboHolder != null ? FilledIndirectPointer.basedOff(ssboHolder, source.getIndirectPointer()) : null);
|
||||
}
|
||||
}
|
||||
|
||||
return programs;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
for (Pass renderPass : passes) {
|
||||
renderPass.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Pass {
|
||||
|
||||
Program program;
|
||||
GlFramebuffer framebuffer;
|
||||
ImmutableSet<Integer> flippedAtLeastOnce;
|
||||
ImmutableSet<Integer> stageReadsFromAlt;
|
||||
ImmutableSet<Integer> mipmappedBuffers;
|
||||
ViewportData viewportScale;
|
||||
ComputeProgram[] computes;
|
||||
|
||||
protected void destroy() {
|
||||
this.program.destroy();
|
||||
for (ComputeProgram compute : this.computes) {
|
||||
if (compute != null) {
|
||||
compute.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComputeOnlyPass extends Pass {
|
||||
|
||||
@Override
|
||||
protected void destroy() {
|
||||
for (ComputeProgram compute : this.computes) {
|
||||
if (compute != null) {
|
||||
compute.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import net.coderbot.iris.gl.texture.DepthBufferFormat;
|
||||
import net.coderbot.iris.gl.texture.DepthCopyStrategy;
|
||||
import net.coderbot.iris.gl.texture.InternalTextureFormat;
|
||||
import net.coderbot.iris.rendertarget.DepthTexture;
|
||||
import net.coderbot.iris.features.FeatureFlags;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.rendertarget.RenderTarget;
|
||||
import net.coderbot.iris.shaderpack.PackShadowDirectives;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -35,11 +37,11 @@ public class ShadowRenderTargets {
|
||||
private final InternalTextureFormat[] formats;
|
||||
private final IntList buffersToBeCleared;
|
||||
|
||||
public ShadowRenderTargets(int resolution, PackShadowDirectives shadowDirectives) {
|
||||
public ShadowRenderTargets(WorldRenderingPipeline pipeline, int resolution, PackShadowDirectives shadowDirectives) {
|
||||
this.shadowDirectives = shadowDirectives;
|
||||
this.resolution = resolution;
|
||||
|
||||
final int size = shadowDirectives.getColorSamplingSettings().size();
|
||||
final int size = pipeline.hasFeature(FeatureFlags.HIGHER_SHADOWCOLOR) ? PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS_IRIS : PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS_OF;
|
||||
targets = new RenderTarget[size];
|
||||
formats = new InternalTextureFormat[size];
|
||||
flipped = new boolean[size];
|
||||
|
||||
+3
-3
@@ -74,7 +74,7 @@ public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportPr
|
||||
private int planeCount = 0;
|
||||
|
||||
private final Vector3f shadowLightVectorFromOrigin = new Vector3f();
|
||||
private BoxCuller boxCuller;
|
||||
protected BoxCuller boxCuller;
|
||||
private final Vector3d position = new Vector3d();
|
||||
|
||||
private final BaseClippingPlanes baseClippingPlanes = new BaseClippingPlanes();
|
||||
@@ -277,13 +277,13 @@ public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportPr
|
||||
return new Viewport(this, position.set(xPosition, yPosition, zPosition));
|
||||
}
|
||||
|
||||
private boolean isVisible(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
protected boolean isVisible(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
return this.checkCornerVisibility((float)(minX - xPosition), (float)(minY - yPosition), (float)(minZ - zPosition),
|
||||
(float)(maxX - xPosition), (float)(maxY - yPosition), (float)(maxZ - zPosition));
|
||||
}
|
||||
|
||||
// view-relative coordinates.
|
||||
private boolean checkCornerVisibility(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
protected boolean checkCornerVisibility(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
for (int i = 0; i < planeCount; ++i) {
|
||||
final Vector4f plane = this.planes[i];
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.coderbot.iris.shadows.frustum.advanced;
|
||||
|
||||
import net.coderbot.iris.shadows.frustum.BoxCuller;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class SafeZoneCullingFrustum extends AdvancedShadowCullingFrustum {
|
||||
private final BoxCuller distanceCuller;
|
||||
|
||||
public SafeZoneCullingFrustum(Matrix4f playerView, Matrix4f playerProjection, Vector3f shadowLightVector, BoxCuller voxelCuller, BoxCuller distanceCuller) {
|
||||
super();
|
||||
init(playerView, playerProjection, shadowLightVector, voxelCuller);
|
||||
this.distanceCuller = distanceCuller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(double cameraX, double cameraY, double cameraZ) {
|
||||
if (this.distanceCuller != null) {
|
||||
this.distanceCuller.setPosition(cameraX, cameraY, cameraZ);
|
||||
}
|
||||
super.setPosition(cameraX, cameraY, cameraZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoundingBoxInFrustum(AxisAlignedBB aabb) {
|
||||
// Cull if outside the overall distance limit
|
||||
if (distanceCuller != null && distanceCuller.isCulled(aabb)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If within the voxel safe zone, always render
|
||||
if (boxCuller != null && !boxCuller.isCulled(aabb)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise fall through to advanced frustum culling
|
||||
return isVisible(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
// Cull if outside the overall distance limit
|
||||
if (distanceCuller != null && distanceCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If within the voxel safe zone, always render
|
||||
if (boxCuller != null && !boxCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return checkCornerVisibility(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class TextureManipulationUtil {
|
||||
for (int level = 0; level <= maxLevel; ++level) {
|
||||
final int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH);
|
||||
final int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT);
|
||||
GL11.glViewport(0, 0, width, height);
|
||||
GLStateManager.glViewport(0, 0, width, height);
|
||||
GL30.glFramebufferTexture2D(
|
||||
GL30.GL_FRAMEBUFFER,
|
||||
GL30.GL_COLOR_ATTACHMENT0,
|
||||
@@ -65,7 +65,7 @@ public class TextureManipulationUtil {
|
||||
previousClearColorBuffer.get(2),
|
||||
previousClearColorBuffer.get(3));
|
||||
GLStateManager.glBindTexture(GL11.GL_TEXTURE_2D, previousTextureId);
|
||||
GL11.glViewport(
|
||||
GLStateManager.glViewport(
|
||||
previousViewportBuffer.get(0),
|
||||
previousViewportBuffer.get(1),
|
||||
previousViewportBuffer.get(2),
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.gtnewhorizons.angelica.glsm.texture.TextureInfo;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache;
|
||||
import com.gtnewhorizons.angelica.glsm.texture.TextureTracker;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.EntityRendererAccessor;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import net.coderbot.iris.gl.uniform.DynamicUniformHolder;
|
||||
import net.coderbot.iris.gl.uniform.UniformHolder;
|
||||
@@ -64,11 +65,11 @@ public final class CommonUniforms {
|
||||
}
|
||||
|
||||
// Needs to use a LocationalUniformHolder as we need it for the common uniforms
|
||||
public static void addDynamicUniforms(DynamicUniformHolder uniforms) {
|
||||
public static void addDynamicUniforms(DynamicUniformHolder uniforms, FogMode fogMode) {
|
||||
ExternallyManagedUniforms.addExternallyManagedUniforms116(uniforms);
|
||||
IdMapUniforms.addEntityIdMapUniforms(uniforms);
|
||||
FogUniforms.addFogUniforms(uniforms);
|
||||
IrisInternalUniforms.addFogUniforms(uniforms);
|
||||
FogUniforms.addFogUniforms(uniforms, fogMode);
|
||||
IrisInternalUniforms.addFogUniforms(uniforms, fogMode);
|
||||
|
||||
uniforms.uniform2i("atlasSize", () -> {
|
||||
final int glId = GLStateManager.getBoundTextureForServerState(0);
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package net.coderbot.iris.uniforms;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.effect.EntityLightningBolt;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
* Shared utility for resolving entity IDs with support for special entities and caching.
|
||||
*/
|
||||
public final class EntityIdHelper {
|
||||
private static final NamespacedId CONVERTING_VILLAGER = new NamespacedId("minecraft", "zombie_villager_converting");
|
||||
private static final NamespacedId CURRENT_PLAYER = new NamespacedId("minecraft", "current_player");
|
||||
private static final NamespacedId LIGHTNING_BOLT_ID = new NamespacedId("minecraft", "lightning_bolt");
|
||||
|
||||
private static final Object2IntMap<Class<?>> entityIdCache = new Object2IntOpenHashMap<>();
|
||||
private static Object2IntFunction<NamespacedId> cachedEntityIdMap;
|
||||
|
||||
static {
|
||||
entityIdCache.defaultReturnValue(Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
private EntityIdHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity ID for the given entity.
|
||||
*
|
||||
* @param entity The entity to get the ID for
|
||||
* @return The entity ID, or -1 if no mapping exists
|
||||
*/
|
||||
public static int getEntityId(Entity entity) {
|
||||
Object2IntFunction<NamespacedId> entityIdMap = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
if (entityIdMap == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Invalidate cache if the map changed (shader reload)
|
||||
if (entityIdMap != cachedEntityIdMap) {
|
||||
entityIdCache.clear();
|
||||
cachedEntityIdMap = entityIdMap;
|
||||
}
|
||||
|
||||
// Normal entity type lookup
|
||||
int normalId = getNormalEntityId(entity, entityIdMap);
|
||||
|
||||
// Check for special entity type overrides
|
||||
int specialId = getSpecialEntityId(entity, entityIdMap);
|
||||
if (specialId != -1) {
|
||||
return specialId;
|
||||
}
|
||||
|
||||
return normalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the entity should use a special hardcoded entity ID.
|
||||
*/
|
||||
private static int getSpecialEntityId(Entity entity, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
// Check if this is the current player (3rd person only)
|
||||
Entity cameraEntity = Minecraft.getMinecraft().renderViewEntity;
|
||||
if (entity == cameraEntity && entity instanceof EntityPlayer) {
|
||||
int currentPlayerId = entityIdMap.applyAsInt(CURRENT_PLAYER);
|
||||
if (currentPlayerId != -1) {
|
||||
return currentPlayerId;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this is a converting zombie villager
|
||||
if (entity instanceof EntityZombie zombie) {
|
||||
if (zombie.isConverting()) {
|
||||
return entityIdMap.applyAsInt(CONVERTING_VILLAGER);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the normal entity ID based on entity type, with caching.
|
||||
* Uses Class<?> as cache key for fast reference-equality lookups.
|
||||
*/
|
||||
private static int getNormalEntityId(Entity entity, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
// Use entity class as cache key
|
||||
Class<?> entityClass = entity.getClass();
|
||||
|
||||
// Check cache first
|
||||
int cached = entityIdCache.getInt(entityClass);
|
||||
if (cached != Integer.MIN_VALUE) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
// Cache miss, store for next lookup
|
||||
int resolvedId = resolveEntityId(entity, entityClass, entityIdMap);
|
||||
entityIdCache.put(entityClass, resolvedId);
|
||||
|
||||
return resolvedId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve entity ID for a cache miss. Try in order:
|
||||
* 1. Registered entity name (e.g., "Zombie")
|
||||
* 2. Simple class name (e.g., "EntityLightningBolt")
|
||||
* 3. Fully qualified class name (e.g., "net.minecraft.entity.effect.EntityLightningBolt")
|
||||
* 4. Special hardcoded cases (e.g., "minecraft:lightning_bolt")
|
||||
*/
|
||||
private static int resolveEntityId(Entity entity, Class<?> entityClass, Object2IntFunction<NamespacedId> entityIdMap) {
|
||||
// Try registered entity name first (most common)
|
||||
String entityType = EntityList.getEntityString(entity);
|
||||
if (entityType != null) {
|
||||
return entityIdMap.applyAsInt(new NamespacedId(entityType));
|
||||
}
|
||||
|
||||
String simpleClassName = entityClass.getSimpleName();
|
||||
int id = entityIdMap.applyAsInt(new NamespacedId(simpleClassName));
|
||||
|
||||
if (id == -1) {
|
||||
String className = entityClass.getName();
|
||||
id = entityIdMap.applyAsInt(new NamespacedId(className));
|
||||
}
|
||||
|
||||
if (id == -1 && entity instanceof EntityLightningBolt) {
|
||||
// Shaderpacks use "minecraft:lightning_bolt" so we should continue to provide it here
|
||||
// Even if we can just use EntityLightningBolt
|
||||
id = entityIdMap.applyAsInt(LIGHTNING_BOLT_ID);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,30 @@
|
||||
package net.coderbot.iris.uniforms;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import net.coderbot.iris.gl.uniform.DynamicUniformHolder;
|
||||
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
|
||||
|
||||
public class FogUniforms {
|
||||
private FogUniforms() {
|
||||
// no construction
|
||||
}
|
||||
|
||||
public static void addFogUniforms(DynamicUniformHolder uniforms) {
|
||||
uniforms.uniform1i("fogMode", () -> {
|
||||
if(!GLStateManager.getFogMode().isEnabled()) return 0;
|
||||
|
||||
return GLStateManager.getFogState().getFogMode();
|
||||
}, ValueUpdateNotifier.NONE);
|
||||
public static void addFogUniforms(DynamicUniformHolder uniforms, FogMode fogMode) {
|
||||
if (fogMode == FogMode.OFF) {
|
||||
uniforms.uniform1i(UniformUpdateFrequency.ONCE, "fogMode", () -> 0);
|
||||
uniforms.uniform1i(UniformUpdateFrequency.ONCE, "fogShape", () -> -1);
|
||||
} else {
|
||||
uniforms.uniform1i("fogMode", () -> {
|
||||
if (!GLStateManager.getFogMode().isEnabled()) return 0;
|
||||
return GLStateManager.getFogState().getFogMode();
|
||||
}, ValueUpdateNotifier.NONE);
|
||||
uniforms.uniform1i("fogShape", () -> 0, ValueUpdateNotifier.NONE);
|
||||
}
|
||||
|
||||
uniforms.uniform1f("fogDensity", () -> GLStateManager.getFogState().getDensity(), ValueUpdateNotifier.NONE);
|
||||
|
||||
uniforms.uniform1f("fogStart", () -> GLStateManager.getFogState().getStart(), ValueUpdateNotifier.NONE);
|
||||
|
||||
uniforms.uniform1f("fogEnd", () -> GLStateManager.getFogState().getEnd(), ValueUpdateNotifier.NONE);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.coderbot.iris.uniforms;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import net.coderbot.iris.gl.state.FogMode;
|
||||
import net.coderbot.iris.gl.uniform.DynamicUniformHolder;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector4f;
|
||||
@@ -13,7 +14,7 @@ public class IrisInternalUniforms {
|
||||
private IrisInternalUniforms() {
|
||||
}
|
||||
|
||||
public static void addFogUniforms(DynamicUniformHolder uniforms) {
|
||||
public static void addFogUniforms(DynamicUniformHolder uniforms, FogMode fogMode) {
|
||||
uniforms.uniform4f(PER_FRAME, "iris_FogColor", () -> {
|
||||
final Vector3d color = GLStateManager.getFogState().getFogColor();
|
||||
return FOG_COLOR.set((float) color.x, (float) color.y, (float) color.z, GLStateManager.getFogState().getFogAlpha());
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.coderbot.iris.uniforms;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Helper class to manage the currentRenderedItem ID uniform.
|
||||
*/
|
||||
public class ItemIdManager {
|
||||
/**
|
||||
* Set the item ID for an armor piece or held item.
|
||||
* If the ItemStack is null/empty, resets to 0.
|
||||
* Otherwise, looks up the material ID and sets it.
|
||||
*
|
||||
* @param itemStack The armor or item being rendered
|
||||
*/
|
||||
public static void setItemId(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the item ID to 0.
|
||||
* Used when entering/exiting render sections or before glint rendering.
|
||||
*/
|
||||
public static void resetItemId() {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -32,11 +32,11 @@ public abstract class MixinEntityRenderer implements EntityRendererAccessor {
|
||||
|
||||
Camera.INSTANCE.update(viewEntity, partialTicks);
|
||||
|
||||
// Set RenderingState to use the correct camera position
|
||||
// Use entity eye position for cameraPosition uniform, not the third-person camera position.
|
||||
RenderingState.INSTANCE.setCameraPosition(
|
||||
Camera.INSTANCE.getPos().x,
|
||||
Camera.INSTANCE.getPos().y,
|
||||
Camera.INSTANCE.getPos().z
|
||||
Camera.INSTANCE.getEntityPos().x,
|
||||
Camera.INSTANCE.getEntityPos().y,
|
||||
Camera.INSTANCE.getEntityPos().z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.util.IIcon;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
|
||||
@Mixin(RenderItem.class)
|
||||
public class MixinDroppedItemGlintEdges {
|
||||
|
||||
/**
|
||||
* Fix enchantment glint not rendering on item edges by using the actual icon dimensions
|
||||
* instead of hardcoded 255x255. This ensures the edge geometry calculation matches the
|
||||
* main item render, allowing GL_EQUAL depth test to pass on all edges.
|
||||
|
||||
* First glint pass (ordinal 1)
|
||||
*/
|
||||
@ModifyArgs(
|
||||
method = "renderDroppedItem(Lnet/minecraft/entity/item/EntityItem;Lnet/minecraft/util/IIcon;IFFFFI)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItemIn2D(Lnet/minecraft/client/renderer/Tessellator;FFFFIIF)V", ordinal = 1)
|
||||
)
|
||||
private void iris$fixFirstGlintDimensions(Args args, EntityItem entity, IIcon icon, int count, float partialTicks, float r, float g, float b, int pass) {
|
||||
args.set(5, icon.getIconWidth());
|
||||
args.set(6, icon.getIconHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Second glint pass (ordinal 2)
|
||||
*/
|
||||
@ModifyArgs(
|
||||
method = "renderDroppedItem(Lnet/minecraft/entity/item/EntityItem;Lnet/minecraft/util/IIcon;IFFFFI)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItemIn2D(Lnet/minecraft/client/renderer/Tessellator;FFFFIIF)V", ordinal = 2)
|
||||
)
|
||||
private void iris$fixSecondGlintDimensions(Args args, EntityItem entity, IIcon icon, int count, float partialTicks, float r, float g, float b, int pass) {
|
||||
args.set(5, icon.getIconWidth());
|
||||
args.set(6, icon.getIconHeight());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@ public class MixinEntityPickupFX {
|
||||
|
||||
@WrapOperation(
|
||||
method = "renderParticle",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderManager;func_147940_a(Lnet/minecraft/entity/Entity;DDDFF)Z")
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderManager;renderEntityWithPosYaw(Lnet/minecraft/entity/Entity;DDDFF)Z")
|
||||
)
|
||||
private boolean iris$wrapPickupRender(RenderManager renderManager, Entity entity, double x, double y, double z, float yaw, float partialTicks, Operation<Boolean> original) {
|
||||
GbufferPrograms.beginEntities();
|
||||
|
||||
+12
-5
@@ -95,17 +95,24 @@ public abstract class MixinEntityRenderer implements IResourceManagerReloadListe
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V"))
|
||||
private void iris$beginWeatherAndwriteRainAndSnowToDepthBuffer(float partialTicks, long startTime, CallbackInfo ci, @Share("pipeline") LocalRef<WorldRenderingPipeline> pipeline) {
|
||||
@WrapOperation(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V"))
|
||||
private void iris$wrapWeather(EntityRenderer instance, float partialTicks, Operation<Void> original, @Share("pipeline") LocalRef<WorldRenderingPipeline> pipeline) {
|
||||
pipeline.get().setPhase(WorldRenderingPhase.RAIN_SNOW);
|
||||
if (pipeline.get().shouldWriteRainAndSnowToDepthBuffer()) {
|
||||
GLStateManager.glDepthMask(true);
|
||||
}
|
||||
if (pipeline.get().shouldRenderWeather()) {
|
||||
original.call(instance, partialTicks);
|
||||
}
|
||||
pipeline.get().setPhase(WorldRenderingPhase.NONE);
|
||||
}
|
||||
|
||||
@Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V", shift = At.Shift.AFTER))
|
||||
private void iris$endWeather(float partialTicks, long startTime, CallbackInfo ci, @Share("pipeline") LocalRef<WorldRenderingPipeline> pipeline) {
|
||||
pipeline.get().setPhase(WorldRenderingPhase.NONE);
|
||||
@WrapOperation(method = "updateRenderer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;addRainParticles()V"))
|
||||
private void iris$wrapRainParticles(EntityRenderer instance, Operation<Void> original) {
|
||||
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline == null || pipeline.shouldRenderWeatherParticles()) {
|
||||
original.call(instance);
|
||||
}
|
||||
}
|
||||
|
||||
@WrapOperation(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V", remap = false))
|
||||
|
||||
+35
-40
@@ -4,8 +4,7 @@ import com.gtnewhorizons.angelica.compat.mojang.InteractionHand;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.pipeline.HandRenderer;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemMaterialHelper;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
@@ -16,12 +15,15 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Mixin to handle hand rendering and item ID tracking.
|
||||
* Mixin to handle item rendering in first-person.
|
||||
*/
|
||||
@Mixin(ItemRenderer.class)
|
||||
public class MixinItemRenderer {
|
||||
/**
|
||||
* Render held item in first person.
|
||||
*/
|
||||
@Inject(method = "renderItemInFirstPerson", at = @At("HEAD"), cancellable = true)
|
||||
private void iris$handleFirstPersonRender(float partialTicks, CallbackInfo ci) {
|
||||
private void iris$setFirstPersonItemId(float partialTicks, CallbackInfo ci) {
|
||||
if (IrisApi.getInstance().isShaderPackInUse()) {
|
||||
boolean isHandTranslucent = HandRenderer.INSTANCE.isHandTranslucent(InteractionHand.MAIN_HAND);
|
||||
boolean isRenderingSolid = HandRenderer.INSTANCE.isRenderingSolid();
|
||||
@@ -39,40 +41,8 @@ public class MixinItemRenderer {
|
||||
|
||||
ItemStack itemStack = mc.thePlayer.getCurrentEquippedItem();
|
||||
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get material ID from item.properties or block.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate GLINT shader before rendering enchantment glint on held items.
|
||||
* Injects at the first glDepthFunc inside the if(hasEffect) block.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;ILnet/minecraftforge/client/IItemRenderer$ItemRenderType;)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 0),
|
||||
remap = false
|
||||
)
|
||||
private void iris$activateGlintShaderHeldItem(net.minecraft.entity.EntityLivingBase entity, ItemStack itemStack, int renderPass, net.minecraftforge.client.IItemRenderer.ItemRenderType type, CallbackInfo ci) {
|
||||
GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.GLINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate GLINT shader after rendering enchantment glint on held items.
|
||||
* Injects at the last glDepthFunc inside the if(hasEffect) block.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;ILnet/minecraftforge/client/IItemRenderer$ItemRenderType;)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 1, shift = At.Shift.AFTER),
|
||||
remap = false
|
||||
)
|
||||
private void iris$deactivateGlintShaderHeldItem(net.minecraft.entity.EntityLivingBase entity, ItemStack itemStack, int renderPass, net.minecraftforge.client.IItemRenderer.ItemRenderType type, CallbackInfo ci) {
|
||||
GbufferPrograms.teardownSpecialRenderCondition();
|
||||
// Set item ID for first-person hand/item
|
||||
ItemIdManager.setItemId(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +52,32 @@ public class MixinItemRenderer {
|
||||
method = "renderItemInFirstPerson",
|
||||
at = @At("RETURN")
|
||||
)
|
||||
private void iris$resetHeldItemId(float partialTicks, CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
private void iris$resetFirstPersonItemId(float partialTicks, CallbackInfo ci) {
|
||||
ItemIdManager.resetItemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate GLINT shader before rendering enchantment glint on held items (third person).
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;ILnet/minecraftforge/client/IItemRenderer$ItemRenderType;)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 0),
|
||||
remap = false
|
||||
)
|
||||
private void iris$glintStart(CallbackInfo ci) {
|
||||
ItemIdManager.resetItemId();
|
||||
GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.GLINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate GLINT shader after rendering enchantment glint on held items (third person).
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;ILnet/minecraftforge/client/IItemRenderer$ItemRenderType;)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 1, shift = At.Shift.AFTER),
|
||||
remap = false
|
||||
)
|
||||
private void iris$glintEnd(CallbackInfo ci) {
|
||||
GbufferPrograms.teardownSpecialRenderCondition();
|
||||
}
|
||||
}
|
||||
+17
-57
@@ -2,94 +2,54 @@ package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemMaterialHelper;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderBiped;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
||||
/**
|
||||
* Mixin to set the currentRenderedItem ID when rendering armor on entities.
|
||||
* This allows shaders to identify and apply different materials to armor pieces.
|
||||
* Mixin to set currentRenderedItem ID when rendering armor and equipment on biped entities.
|
||||
* RENDER ORDER:
|
||||
* 1. doRender() starts (parent resets item ID to 0)
|
||||
* 2. Main entity body
|
||||
* 3. Armor loop (4 slots) - we set ID per armor piece
|
||||
* 4. renderEquippedItems(): - Handled via ItemRenderer
|
||||
* - Held item
|
||||
*/
|
||||
@Mixin(RenderBiped.class)
|
||||
public class MixinRenderBiped {
|
||||
|
||||
/**
|
||||
* Set the item ID when rendering armor.
|
||||
* Wraps the setRenderPassModel call to inject our ID setting logic.
|
||||
* Set item ID when rendering armor on biped entities.
|
||||
* Wraps setRenderPassModel() which is called inside shouldRenderPass().
|
||||
*/
|
||||
@WrapOperation(
|
||||
method = "shouldRenderPass(Lnet/minecraft/entity/EntityLiving;IF)I",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderBiped;setRenderPassModel(Lnet/minecraft/client/model/ModelBase;)V")
|
||||
)
|
||||
private void iris$setArmorItemId(RenderBiped instance, ModelBase model, Operation<Void> original, EntityLiving entity, int armorSlot, float partialTicks) {
|
||||
// Get the armor item stack for this slot
|
||||
// Get the armor item stack for this slot (slot 0=boots, 1=legs, 2=chest, 3=helmet)
|
||||
ItemStack itemStack = entity.func_130225_q(3 - armorSlot);
|
||||
ItemIdManager.setItemId(itemStack);
|
||||
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
original.call(instance, model);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get material ID from item.properties or block.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
|
||||
// Call original method
|
||||
original.call(instance, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the item ID at the start of rendering each entity.
|
||||
* This ensures a clean slate and prevents ID bleed between entities.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/entity/EntityLiving;DDDFF)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void iris$resetAtStart(EntityLiving entity, double x, double y, double z, float entityYaw, float partialTicks, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the item ID at the start of renderEquippedItems.
|
||||
* This prevents armor IDs from bleeding into held item rendering.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderEquippedItems(Lnet/minecraft/entity/EntityLiving;F)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void iris$resetInEquippedItems(EntityLiving entity, float partialTicks, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item ID when rendering held items in third person.
|
||||
* Wraps renderItem calls to set the ID based on the held item.
|
||||
* Set item ID when rendering held items on entities (third person).
|
||||
*/
|
||||
@WrapOperation(
|
||||
method = "renderEquippedItems(Lnet/minecraft/entity/EntityLiving;F)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;I)V")
|
||||
)
|
||||
private void iris$setHeldItemId(net.minecraft.client.renderer.ItemRenderer itemRenderer, net.minecraft.entity.EntityLivingBase entity, ItemStack itemStack, int renderPass, Operation<Void> original) {
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
original.call(itemRenderer, entity, itemStack, renderPass);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get material ID from item.properties or block.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
private void iris$setHeldItemId(ItemRenderer itemRenderer, EntityLivingBase entity, ItemStack itemStack, int renderPass, Operation<Void> original) {
|
||||
ItemIdManager.setItemId(itemStack);
|
||||
|
||||
original.call(itemRenderer, entity, itemStack, renderPass);
|
||||
|
||||
// Reset after rendering the held item
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.minecraft.client.renderer.entity.RenderDragon;
|
||||
import net.minecraft.entity.boss.EntityDragon;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Mixin to set the entity ID to "end_crystal_beam" when rendering ender dragon healing beams.
|
||||
* This allows shaders to apply special effects to the healing beams separately from the dragon itself.
|
||||
*/
|
||||
@Mixin(RenderDragon.class)
|
||||
public class MixinRenderDragon {
|
||||
@Unique
|
||||
private static final NamespacedId END_CRYSTAL_BEAM = new NamespacedId("minecraft", "end_crystal_beam");
|
||||
|
||||
@Unique
|
||||
private int angelica$previousEntityId = -1;
|
||||
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/entity/boss/EntityDragon;DDDFF)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPushMatrix()V", ordinal = 0, shift = At.Shift.AFTER, remap = false)
|
||||
)
|
||||
private void iris$setBeamEntityId(EntityDragon dragon, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
// Only set the ID if the dragon is being healed by a crystal
|
||||
if (dragon.healingEnderCrystal != null) {
|
||||
Object2IntFunction<NamespacedId> entityIdMap = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
if (entityIdMap != null) {
|
||||
// Save the current entity ID
|
||||
angelica$previousEntityId = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity();
|
||||
|
||||
int beamId = entityIdMap.applyAsInt(END_CRYSTAL_BEAM);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(beamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/entity/boss/EntityDragon;DDDFF)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPopMatrix()V", ordinal = 0, shift = At.Shift.BEFORE, remap = false)
|
||||
)
|
||||
private void iris$restoreEntityId(EntityDragon dragon, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
if (angelica$previousEntityId != -1) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(angelica$previousEntityId);
|
||||
angelica$previousEntityId = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.uniforms.SystemTimeUniforms;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.tileentity.RenderEndPortal;
|
||||
import net.minecraft.tileentity.TileEntityEndPortal;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(RenderEndPortal.class)
|
||||
public class MixinRenderEndPortal {
|
||||
|
||||
@Unique
|
||||
private static final ResourceLocation iris$END_PORTAL_TEXTURE = new ResourceLocation("textures/entity/end_portal.png");
|
||||
|
||||
@Unique private static final float iris$TOP = 0.75f;
|
||||
@Unique private static final float iris$BOTTOM = 0.375f;
|
||||
@Unique private static final float iris$RED = 0.075f;
|
||||
@Unique private static final float iris$GREEN = 0.15f;
|
||||
@Unique private static final float iris$BLUE = 0.2f;
|
||||
|
||||
@Inject(method = "renderTileEntityAt(Lnet/minecraft/tileentity/TileEntityEndPortal;DDDF)V", at = @At("HEAD"), cancellable = true)
|
||||
private void iris$renderShaderPortal(TileEntityEndPortal te, double x, double y, double z, float partialTicks, CallbackInfo ci) {
|
||||
if (!Iris.getCurrentPack().isPresent()) return;
|
||||
|
||||
ci.cancel();
|
||||
|
||||
float progress = (SystemTimeUniforms.TIMER.getFrameTimeCounter() * 0.01f) % 1.0f;
|
||||
float u0 = progress;
|
||||
float u1 = 0.2f + progress;
|
||||
float v0 = progress;
|
||||
float v1 = 0.2f + progress;
|
||||
|
||||
float top = (float) y + iris$TOP;
|
||||
float bottom = (float) y + iris$BOTTOM;
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(iris$END_PORTAL_TEXTURE);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA_F(iris$RED, iris$GREEN, iris$BLUE, 1.0f);
|
||||
tess.setBrightness(240 | (240 << 16));
|
||||
|
||||
// UP face
|
||||
tess.setNormal(0, 1, 0);
|
||||
tess.addVertexWithUV(x, top, z + 1, u0, v1);
|
||||
tess.addVertexWithUV(x + 1, top, z + 1, u1, v1);
|
||||
tess.addVertexWithUV(x + 1, top, z, u1, v0);
|
||||
tess.addVertexWithUV(x, top, z, u0, v0);
|
||||
|
||||
// DOWN face
|
||||
tess.setNormal(0, -1, 0);
|
||||
tess.addVertexWithUV(x, bottom, z + 1, u0, v1);
|
||||
tess.addVertexWithUV(x, bottom, z, u0, v0);
|
||||
tess.addVertexWithUV(x + 1, bottom, z, u1, v0);
|
||||
tess.addVertexWithUV(x + 1, bottom, z + 1, u1, v1);
|
||||
|
||||
// NORTH face (z=0)
|
||||
tess.setNormal(0, 0, -1);
|
||||
tess.addVertexWithUV(x, top, z, u0, v0);
|
||||
tess.addVertexWithUV(x + 1, top, z, u1, v0);
|
||||
tess.addVertexWithUV(x + 1, bottom, z, u1, v1);
|
||||
tess.addVertexWithUV(x, bottom, z, u0, v1);
|
||||
|
||||
// SOUTH face (z=1)
|
||||
tess.setNormal(0, 0, 1);
|
||||
tess.addVertexWithUV(x, top, z + 1, u0, v1);
|
||||
tess.addVertexWithUV(x, bottom, z + 1, u0, v0);
|
||||
tess.addVertexWithUV(x + 1, bottom, z + 1, u1, v0);
|
||||
tess.addVertexWithUV(x + 1, top, z + 1, u1, v1);
|
||||
|
||||
// WEST face (x=0)
|
||||
tess.setNormal(-1, 0, 0);
|
||||
tess.addVertexWithUV(x, top, z + 1, u0, v1);
|
||||
tess.addVertexWithUV(x, top, z, u0, v0);
|
||||
tess.addVertexWithUV(x, bottom, z, u1, v0);
|
||||
tess.addVertexWithUV(x, bottom, z + 1, u1, v1);
|
||||
|
||||
// EAST face (x=1)
|
||||
tess.setNormal(1, 0, 0);
|
||||
tess.addVertexWithUV(x + 1, top, z + 1, u1, v1);
|
||||
tess.addVertexWithUV(x + 1, bottom, z + 1, u1, v0);
|
||||
tess.addVertexWithUV(x + 1, bottom, z, u0, v0);
|
||||
tess.addVertexWithUV(x + 1, top, z, u0, v1);
|
||||
|
||||
tess.draw();
|
||||
}
|
||||
}
|
||||
+56
-65
@@ -4,27 +4,21 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.llamalad7.mixinextras.sugar.Share;
|
||||
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.ITessellatorInstance;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPhase;
|
||||
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.EntityIdHelper;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.culling.ICamera;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.effect.EntityLightningBolt;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
@@ -32,13 +26,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(RenderGlobal.class)
|
||||
public class MixinRenderGlobal {
|
||||
@Unique private static final NamespacedId LIGHTNING_BOLT_ID = new NamespacedId("minecraft", "lightning_bolt");
|
||||
@Unique private static final Object2IntOpenHashMap<String> angelica$entityIdCache = new Object2IntOpenHashMap<>();
|
||||
@Unique private static Object2IntFunction<NamespacedId> angelica$cachedEntityIdMap;
|
||||
|
||||
static {
|
||||
angelica$entityIdCache.defaultReturnValue(Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
@Inject(method = "renderSky", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/Tessellator;instance:Lnet/minecraft/client/renderer/Tessellator;"))
|
||||
private void iris$renderSky$beginNormalSky(float partialTicks, CallbackInfo ci, @Share("pipeline") LocalRef<WorldRenderingPipeline> pipeline) {
|
||||
@@ -78,6 +65,58 @@ public class MixinRenderGlobal {
|
||||
GL11.glRotatef(pipeline.get().getSunPathRotation(), 0.0F, 0.0F, 1.0F);
|
||||
}
|
||||
|
||||
// Sky disc: wrap the glCallList(glSkyList) call — the first glCallList in the surface world branch
|
||||
@WrapOperation(method = "renderSky",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", ordinal = 0, remap = false),
|
||||
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getSkyColor(Lnet/minecraft/entity/Entity;F)Lnet/minecraft/util/Vec3;")))
|
||||
private void iris$skipSkyDisc(int list, Operation<Void> original) {
|
||||
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline == null || pipeline.shouldRenderSkyDisc()) {
|
||||
original.call(list);
|
||||
}
|
||||
}
|
||||
|
||||
// Sun: wrap Tessellator.draw() after sun texture bind, before moon texture bind
|
||||
@WrapOperation(method = "renderSky",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 0),
|
||||
slice = @Slice(
|
||||
from = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;locationSunPng:Lnet/minecraft/util/ResourceLocation;"),
|
||||
to = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;locationMoonPhasesPng:Lnet/minecraft/util/ResourceLocation;")))
|
||||
private int iris$skipSun(Tessellator instance, Operation<Integer> original) {
|
||||
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline == null || pipeline.shouldRenderSun()) {
|
||||
return original.call(instance);
|
||||
}
|
||||
((ITessellatorInstance) instance).discard();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Moon: wrap Tessellator.draw() after moon texture bind, before getStarBrightness
|
||||
@WrapOperation(method = "renderSky",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 0),
|
||||
slice = @Slice(
|
||||
from = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;locationMoonPhasesPng:Lnet/minecraft/util/ResourceLocation;"),
|
||||
to = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getStarBrightness(F)F")))
|
||||
private int iris$skipMoon(Tessellator instance, Operation<Integer> original) {
|
||||
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline == null || pipeline.shouldRenderMoon()) {
|
||||
return original.call(instance);
|
||||
}
|
||||
((ITessellatorInstance) instance).discard();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Stars: wrap glCallList(starGLCallList) — the glCallList after getStarBrightness
|
||||
@WrapOperation(method = "renderSky",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", ordinal = 0, remap = false),
|
||||
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getStarBrightness(F)F")))
|
||||
private void iris$skipStars(int list, Operation<Void> original) {
|
||||
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline == null || pipeline.shouldRenderStars()) {
|
||||
original.call(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method="drawSelectionBox", at=@At(value="HEAD"))
|
||||
private void iris$startOutline(EntityPlayer player, MovingObjectPosition pos, int p_72731_3_, float p_72731_4_, CallbackInfo ci) {
|
||||
GbufferPrograms.beginOutline();
|
||||
@@ -89,55 +128,7 @@ public class MixinRenderGlobal {
|
||||
|
||||
@WrapOperation(method="renderEntities", at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/entity/RenderManager;renderEntitySimple(Lnet/minecraft/entity/Entity;F)Z"))
|
||||
private boolean angelica$renderEntitySimple(RenderManager instance, Entity entity, float partialTicks, Operation<Boolean> original) {
|
||||
int entityId = entity.getEntityId();
|
||||
|
||||
Object2IntFunction<NamespacedId> entityIdMap = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
if (entityIdMap != null) {
|
||||
// Invalidate cache if the map changed (shader reload)
|
||||
if (entityIdMap != angelica$cachedEntityIdMap) {
|
||||
angelica$entityIdCache.clear();
|
||||
angelica$cachedEntityIdMap = entityIdMap;
|
||||
}
|
||||
|
||||
String entityType = EntityList.getEntityString(entity);
|
||||
String cacheKey;
|
||||
|
||||
if (entityType != null) {
|
||||
// Use registered entity name
|
||||
cacheKey = entityType;
|
||||
int cached = angelica$entityIdCache.getInt(cacheKey);
|
||||
if (cached == Integer.MIN_VALUE) {
|
||||
cached = entityIdMap.applyAsInt(new NamespacedId(entityType));
|
||||
angelica$entityIdCache.put(cacheKey, cached);
|
||||
}
|
||||
entityId = cached;
|
||||
} else {
|
||||
// Unregistered entity check
|
||||
Class<?> entityClass = entity.getClass();
|
||||
String className = entityClass.getName();
|
||||
cacheKey = className;
|
||||
|
||||
int cached = angelica$entityIdCache.getInt(cacheKey);
|
||||
if (cached == Integer.MIN_VALUE) {
|
||||
// Try simple class name first (e.g., "EntityLightningBolt")
|
||||
String simpleClassName = entityClass.getSimpleName();
|
||||
cached = entityIdMap.applyAsInt(new NamespacedId(simpleClassName));
|
||||
|
||||
// If not found, try FQN (e.g., "net.minecraft.entity.effect.EntityLightningBolt")
|
||||
if (cached == -1) {
|
||||
cached = entityIdMap.applyAsInt(new NamespacedId(className));
|
||||
}
|
||||
|
||||
// Special case: Shaderpacks have "minecraft:lightning_bolt" so we should continue to provide this
|
||||
if (cached == -1 && entity instanceof EntityLightningBolt) {
|
||||
cached = entityIdMap.applyAsInt(LIGHTNING_BOLT_ID);
|
||||
}
|
||||
|
||||
angelica$entityIdCache.put(cacheKey, cached);
|
||||
}
|
||||
entityId = cached;
|
||||
}
|
||||
}
|
||||
int entityId = EntityIdHelper.getEntityId(entity);
|
||||
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(entityId);
|
||||
GbufferPrograms.beginEntities();
|
||||
|
||||
+2
-2
@@ -3,6 +3,7 @@ package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.coderbot.iris.uniforms.ItemMaterialHelper;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.entity.RenderHorse;
|
||||
@@ -65,7 +66,6 @@ public abstract class MixinRenderHorse {
|
||||
}
|
||||
|
||||
if (armorItem != null) {
|
||||
// Get material ID from item.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(armorItem, 0);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
hasArmor = true;
|
||||
@@ -78,7 +78,7 @@ public abstract class MixinRenderHorse {
|
||||
|
||||
// Reset only if we set it
|
||||
if (hasArmor) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
ItemIdManager.resetItemId();
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
-38
@@ -1,10 +1,10 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemMaterialHelper;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -12,8 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* Mixin to set the currentRenderedItem ID when rendering dropped items (EntityItem).
|
||||
* This allows shaders to identify and apply different materials to items on the ground.
|
||||
* Mixin to set the currentRenderedItem ID when rendering dropped items.
|
||||
*/
|
||||
@Mixin(RenderItem.class)
|
||||
public class MixinRenderItem {
|
||||
@@ -26,38 +25,9 @@ public class MixinRenderItem {
|
||||
method = "doRender(Lnet/minecraft/entity/item/EntityItem;DDDFF)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void iris$setItemIdBeforeRender(net.minecraft.entity.item.EntityItem entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
private void iris$setItemIdBeforeRender(EntityItem entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
ItemStack itemStack = entity.getEntityItem();
|
||||
|
||||
// Get material ID from item.properties or block.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate GLINT shader before rendering enchantment glint.
|
||||
* Injects at the first glDepthFunc inside the if(hasEffect) block.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderDroppedItem(Lnet/minecraft/entity/item/EntityItem;Lnet/minecraft/util/IIcon;IFFFFI)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 0),
|
||||
remap = false
|
||||
)
|
||||
private void iris$activateGlintShader(net.minecraft.entity.item.EntityItem entity, net.minecraft.util.IIcon icon, int count, float partialTicks, float r, float g, float b, int pass, CallbackInfo ci) {
|
||||
GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.GLINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate GLINT shader after rendering enchantment glint.
|
||||
* Injects at the last glDepthFunc inside the if(hasEffect) block.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderDroppedItem(Lnet/minecraft/entity/item/EntityItem;Lnet/minecraft/util/IIcon;IFFFFI)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 1, shift = At.Shift.AFTER),
|
||||
remap = false
|
||||
)
|
||||
private void iris$deactivateGlintShader(net.minecraft.entity.item.EntityItem entity, net.minecraft.util.IIcon icon, int count, float partialTicks, float r, float g, float b, int pass, CallbackInfo ci) {
|
||||
GbufferPrograms.teardownSpecialRenderCondition();
|
||||
ItemIdManager.setItemId(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +37,32 @@ public class MixinRenderItem {
|
||||
method = "doRender(Lnet/minecraft/entity/item/EntityItem;DDDFF)V",
|
||||
at = @At("RETURN")
|
||||
)
|
||||
private void iris$resetItemIdAfterRender(net.minecraft.entity.item.EntityItem entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
private void iris$resetItemIdAfterRender(EntityItem entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
ItemIdManager.resetItemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate GLINT shader before rendering enchantment glint on dropped items.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderDroppedItem(Lnet/minecraft/entity/item/EntityItem;Lnet/minecraft/util/IIcon;IFFFFI)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 0),
|
||||
remap = false
|
||||
)
|
||||
private void iris$glintStart(CallbackInfo ci) {
|
||||
ItemIdManager.resetItemId();
|
||||
GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.GLINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate GLINT shader after rendering enchantment glint on dropped items.
|
||||
*/
|
||||
@Inject(
|
||||
method = "renderDroppedItem(Lnet/minecraft/entity/item/EntityItem;Lnet/minecraft/util/IIcon;IFFFFI)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 1, shift = At.Shift.AFTER),
|
||||
remap = false
|
||||
)
|
||||
private void iris$glintEnd(CallbackInfo ci) {
|
||||
GbufferPrograms.teardownSpecialRenderCondition();
|
||||
}
|
||||
}
|
||||
+12
-93
@@ -2,113 +2,32 @@ package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntFunction;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemMaterialHelper;
|
||||
import net.coderbot.iris.uniforms.EntityIdHelper;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
/**
|
||||
* Mixin to handle material ID setting for entities rendered through renderEntityWithPosYaw.
|
||||
* This is needed for EntityPickupFX which renders entities during pickup animation
|
||||
* Entity ID mapping is handled by MixinRenderGlobal for the normal rendering path.
|
||||
* Mixin to handle entity ID and item ID for entities rendered through renderEntityWithPosYaw and renderEntityStatic.
|
||||
* Sets the entity ID for all entities and resets item ID to prevent inheritance from previous renders.
|
||||
* Specific entities (EntityItem, armor, etc.) can override the item ID in their renderer mixins.
|
||||
*/
|
||||
|
||||
// TODO: Find a way to de-duplicate this code.
|
||||
@Mixin(RenderManager.class)
|
||||
public class MixinRenderManager {
|
||||
@Unique private static final Object2IntOpenHashMap<String> angelica$entityIdCache = new Object2IntOpenHashMap<>();
|
||||
@Unique private static Object2IntFunction<NamespacedId> angelica$cachedEntityIdMap;
|
||||
|
||||
static {
|
||||
angelica$entityIdCache.defaultReturnValue(Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
@WrapOperation(
|
||||
method = "func_147939_a",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/Render;doRender(Lnet/minecraft/entity/Entity;DDDFF)V")
|
||||
)
|
||||
private void iris$wrapDoRender(net.minecraft.client.renderer.entity.Render render, Entity entity, double x, double y, double z, float entityYaw, float partialTicks, Operation<Void> original) {
|
||||
// Set appropriate material ID when entities are rendered through renderEntityWithPosYaw
|
||||
// (used by EntityPickupFX during pickup animation)
|
||||
// Note: Entity ID mapping is handled by MixinRenderGlobal for the normal path
|
||||
boolean setItemId = false;
|
||||
boolean setEntityId = false;
|
||||
|
||||
if (entity instanceof EntityItem) {
|
||||
EntityItem entityItem = (EntityItem) entity;
|
||||
ItemStack itemStack = entityItem.getEntityItem();
|
||||
int itemId = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(itemId);
|
||||
setItemId = true;
|
||||
} else {
|
||||
Object2IntFunction<NamespacedId> entityIdMap = BlockRenderingSettings.INSTANCE.getEntityIds();
|
||||
if (entityIdMap != null) {
|
||||
// Invalidate cache if the map changed (shader reload)
|
||||
if (entityIdMap != angelica$cachedEntityIdMap) {
|
||||
angelica$entityIdCache.clear();
|
||||
angelica$cachedEntityIdMap = entityIdMap;
|
||||
}
|
||||
|
||||
int entityId = entity.getEntityId();
|
||||
|
||||
String entityType = EntityList.getEntityString(entity);
|
||||
String cacheKey;
|
||||
|
||||
if (entityType != null) {
|
||||
// Use registered entity name
|
||||
cacheKey = entityType;
|
||||
int cached = angelica$entityIdCache.getInt(cacheKey);
|
||||
if (cached == Integer.MIN_VALUE) {
|
||||
cached = entityIdMap.applyAsInt(new NamespacedId(entityType));
|
||||
angelica$entityIdCache.put(cacheKey, cached);
|
||||
}
|
||||
entityId = cached;
|
||||
} else {
|
||||
// Unregistered entity - try class names
|
||||
Class<?> entityClass = entity.getClass();
|
||||
String className = entityClass.getName();
|
||||
cacheKey = className;
|
||||
|
||||
int cached = angelica$entityIdCache.getInt(cacheKey);
|
||||
if (cached == Integer.MIN_VALUE) {
|
||||
// Try simple class name first (e.g., "EntityLightningBolt")
|
||||
String simpleClassName = entityClass.getSimpleName();
|
||||
cached = entityIdMap.applyAsInt(new NamespacedId(simpleClassName));
|
||||
|
||||
// If not found, try FQN (e.g., "net.minecraft.entity.effect.EntityLightningBolt")
|
||||
if (cached == -1) {
|
||||
cached = entityIdMap.applyAsInt(new NamespacedId(className));
|
||||
}
|
||||
|
||||
angelica$entityIdCache.put(cacheKey, cached);
|
||||
}
|
||||
entityId = cached;
|
||||
}
|
||||
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(entityId);
|
||||
setEntityId = true;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
original.call(render, entity, x, y, z, entityYaw, partialTicks);
|
||||
} finally {
|
||||
if (setItemId) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
if (setEntityId) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(-1);
|
||||
}
|
||||
}
|
||||
private void iris$wrapDoRender(Render render, Entity entity, double x, double y, double z, float entityYaw, float partialTicks, Operation<Void> original) {
|
||||
int entityId = EntityIdHelper.getEntityId(entity);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(entityId);
|
||||
ItemIdManager.resetItemId();
|
||||
original.call(render, entity, x, y, z, entityYaw, partialTicks);
|
||||
CapturedRenderingState.INSTANCE.setCurrentEntity(-1);
|
||||
}
|
||||
}
|
||||
+38
-50
@@ -2,94 +2,82 @@ package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemMaterialHelper;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Mixin to set the currentRenderedItem ID when rendering armor on the player.
|
||||
* This allows shaders to identify and apply different materials to player armor pieces.
|
||||
* Mixin to set currentRenderedItem ID when rendering armor and equipment on players.
|
||||
* RENDER ORDER (same as parent RendererLivingEntity):
|
||||
* 1. doRender() starts (parent resets item ID to 0)
|
||||
* 2. Main player body
|
||||
* 3. Armor loop (4 slots) - we set ID per armor piece
|
||||
* 4. renderEquippedItems(): - Handled via ItemRenderer
|
||||
* - Helmet (Pumpkin head or other items)
|
||||
* - Deadmau5 ears
|
||||
* - Cape - sets "minecraft:player_cape" ID here
|
||||
* - Held item
|
||||
*/
|
||||
@Mixin(RenderPlayer.class)
|
||||
public class MixinRenderPlayerArmor {
|
||||
@Unique
|
||||
private static final NamespacedId PLAYER_CAPE = new NamespacedId("minecraft", "player_cape");
|
||||
|
||||
/**
|
||||
* Set the item ID when rendering player armor.
|
||||
* Wraps the setRenderPassModel call to inject our ID setting logic.
|
||||
* Set item ID when rendering player armor.
|
||||
*/
|
||||
@WrapOperation(
|
||||
method = "shouldRenderPass(Lnet/minecraft/client/entity/AbstractClientPlayer;IF)I",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderPlayer;setRenderPassModel(Lnet/minecraft/client/model/ModelBase;)V")
|
||||
)
|
||||
private void iris$setArmorItemId(RenderPlayer instance, ModelBase model, Operation<Void> original, AbstractClientPlayer player, int armorSlot, float partialTicks) {
|
||||
// Get the armor item stack for this slot
|
||||
ItemStack itemStack = player.getCurrentArmor(3 - armorSlot);
|
||||
ItemIdManager.setItemId(itemStack);
|
||||
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
original.call(instance, model);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get material ID from item.properties or block.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
|
||||
// Call original method
|
||||
original.call(instance, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the item ID at the start of rendering each player.
|
||||
* This ensures a clean slate and prevents ID bleed between entities.
|
||||
* Set "minecraft:player_cape" when rendering the player's cape.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/client/entity/AbstractClientPlayer;DDDFF)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void iris$resetAtStart(AbstractClientPlayer player, double x, double y, double z, float entityYaw, float partialTicks, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the item ID at the start of renderEquippedItems.
|
||||
* This prevents armor IDs from bleeding into cape/held items rendering.
|
||||
*/
|
||||
@Inject(
|
||||
@WrapOperation(
|
||||
method = "renderEquippedItems(Lnet/minecraft/client/entity/AbstractClientPlayer;F)V",
|
||||
at = @At("HEAD")
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelBiped;renderCloak(F)V")
|
||||
)
|
||||
private void iris$resetInEquippedItems(AbstractClientPlayer player, float partialTicks, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
private void iris$setCapeItemId(ModelBiped modelBiped, float scale, Operation<Void> original) {
|
||||
if (BlockRenderingSettings.INSTANCE.getItemIds() != null) {
|
||||
assert BlockRenderingSettings.INSTANCE.getItemIds() != null;
|
||||
int capeId = Objects.requireNonNull(BlockRenderingSettings.INSTANCE.getItemIds()).applyAsInt(PLAYER_CAPE);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(capeId);
|
||||
}
|
||||
|
||||
original.call(modelBiped, scale);
|
||||
ItemIdManager.resetItemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item ID when rendering held items in third person.
|
||||
* Wraps renderItem calls to set the ID based on the held item.
|
||||
* Set item ID when rendering held items in third person.
|
||||
*/
|
||||
@WrapOperation(
|
||||
method = "renderEquippedItems(Lnet/minecraft/client/entity/AbstractClientPlayer;F)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItem(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;I)V")
|
||||
)
|
||||
private void iris$setHeldItemId(net.minecraft.client.renderer.ItemRenderer itemRenderer, net.minecraft.entity.EntityLivingBase entity, ItemStack itemStack, int renderPass, Operation<Void> original) {
|
||||
if (itemStack == null || itemStack.getItem() == null) {
|
||||
original.call(itemRenderer, entity, itemStack, renderPass);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get material ID from item.properties or block.properties
|
||||
int id = ItemMaterialHelper.getMaterialId(itemStack);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(id);
|
||||
private void iris$setHeldItemId(ItemRenderer itemRenderer, EntityLivingBase entity, ItemStack itemStack, int renderPass, Operation<Void> original) {
|
||||
ItemIdManager.setItemId(itemStack);
|
||||
|
||||
original.call(itemRenderer, entity, itemStack, renderPass);
|
||||
|
||||
// Reset after rendering the held item
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
}
|
||||
}
|
||||
+17
-10
@@ -5,6 +5,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import net.coderbot.iris.gbuffer_overrides.matching.SpecialCondition;
|
||||
import net.coderbot.iris.layer.GbufferPrograms;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.entity.RenderDragon;
|
||||
import net.minecraft.client.renderer.entity.RenderEnderman;
|
||||
@@ -21,19 +22,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(RendererLivingEntity.class)
|
||||
public class MixinRendererLivingEntity {
|
||||
/**
|
||||
* Reset currentRenderedItemId at the start of rendering each living entity, otherwise entity materials don't apply.
|
||||
* Reset currentRenderedItemId at the start of rendering each living entity.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void iris$resetItemIdAtStart(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(0);
|
||||
ItemIdManager.resetItemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture entity color for shader access.
|
||||
*/
|
||||
@WrapOperation(
|
||||
method="doRender",
|
||||
at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/entity/RendererLivingEntity;getColorMultiplier(Lnet/minecraft/entity/EntityLivingBase;FF)I")
|
||||
method = "doRender",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RendererLivingEntity;getColorMultiplier(Lnet/minecraft/entity/EntityLivingBase;FF)I")
|
||||
)
|
||||
private int iris$setEntityColor(RendererLivingEntity instance, EntityLivingBase elb, float f0, float f1, Operation<Integer> original) {
|
||||
final int j = original.call(instance, elb, f0, f1);
|
||||
@@ -45,6 +49,9 @@ public class MixinRendererLivingEntity {
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle special render conditions for entity eyes (spiders, endermen, ender dragon).
|
||||
*/
|
||||
@WrapOperation(
|
||||
method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelBase;render(Lnet/minecraft/entity/Entity;FFFFFF)V", ordinal = 0),
|
||||
@@ -64,28 +71,28 @@ public class MixinRendererLivingEntity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate GLINT shader before rendering armor enchantment glint.
|
||||
* Injects at the first glDepthFunc inside the armor glint rendering block.
|
||||
* Activate GLINT shader before rendering enchantment glint on armor.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 0),
|
||||
remap = false
|
||||
)
|
||||
private void iris$activateArmorGlintShader(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
private void iris$glintStart(CallbackInfo ci) {
|
||||
ItemIdManager.resetItemId();
|
||||
GbufferPrograms.setupSpecialRenderCondition(SpecialCondition.GLINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate GLINT shader after rendering armor enchantment glint.
|
||||
* Injects at the last glDepthFunc inside the armor glint rendering block.
|
||||
* Deactivate GLINT shader after rendering enchantment glint on armor.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDepthFunc(I)V", ordinal = 1, shift = At.Shift.AFTER),
|
||||
remap = false
|
||||
)
|
||||
private void iris$deactivateArmorGlintShader(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
|
||||
private void iris$glintEnd(CallbackInfo ci) {
|
||||
GbufferPrograms.teardownSpecialRenderCondition();
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.shaders;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TileEntityRendererDispatcher.class)
|
||||
public class MixinTileEntityRendererDispatcher {
|
||||
|
||||
@Inject(method = "renderTileEntityAt(Lnet/minecraft/tileentity/TileEntity;DDDF)V", at = @At("HEAD"))
|
||||
private void iris$setBlockEntityId(TileEntity te, double x, double y, double z, float partialTicks, CallbackInfo ci) {
|
||||
Block block = te.getBlockType();
|
||||
if (block == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference2ObjectMap<Block, Int2IntMap> blockMetaMatches = BlockRenderingSettings.INSTANCE.getBlockMetaMatches();
|
||||
if (blockMetaMatches == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Int2IntMap metaMap = blockMetaMatches.get(block);
|
||||
if (metaMap == null) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int meta = te.getBlockMetadata();
|
||||
int id = metaMap.get(meta);
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(Math.max(0, id));
|
||||
}
|
||||
|
||||
@Inject(method = "renderTileEntityAt(Lnet/minecraft/tileentity/TileEntity;DDDF)V", at = @At("RETURN"))
|
||||
private void iris$resetBlockEntityId(TileEntity te, double x, double y, double z, float partialTicks, CallbackInfo ci) {
|
||||
CapturedRenderingState.INSTANCE.setCurrentBlockEntity(0);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.gtnewhorizons.angelica.mixins.late.client.etfuturum;
|
||||
|
||||
import ganymedes01.etfuturum.client.renderer.entity.elytra.LayerBetterElytra;
|
||||
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
|
||||
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
|
||||
import net.coderbot.iris.uniforms.CapturedRenderingState;
|
||||
import net.coderbot.iris.uniforms.ItemIdManager;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Sets a custom material ID for elytra when rendered with a cape texture.
|
||||
* This allows shader developers to target elytra with capes using "minecraft:elytra_with_cape"
|
||||
* in their item.properties files.
|
||||
*/
|
||||
@Mixin(value = LayerBetterElytra.class, remap = false)
|
||||
public class MixinLayerBetterElytra {
|
||||
|
||||
@Unique
|
||||
private static final NamespacedId ELYTRA_WITH_CAPE = new NamespacedId("minecraft", "elytra_with_cape");
|
||||
@Unique
|
||||
private static final NamespacedId ELYTRA = new NamespacedId("etfuturum", "elytra");
|
||||
@Unique
|
||||
private static boolean iris$didSetId = false;
|
||||
|
||||
/**
|
||||
* Before rendering the elytra model, set the appropriate material ID based on whether
|
||||
* the player has a cape or not. This allows shader developers to target both cases.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRenderLayer",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPushMatrix()V", ordinal = 0, shift = At.Shift.BEFORE),
|
||||
remap = false
|
||||
)
|
||||
private static void iris$setElytraId(EntityLivingBase entityIn, float limbSwing, float limbSwingAmount,
|
||||
float partialTicks, float ageInTicks, float scale, CallbackInfo ci) {
|
||||
iris$didSetId = false;
|
||||
|
||||
if (entityIn instanceof AbstractClientPlayer player) {
|
||||
if (BlockRenderingSettings.INSTANCE.getItemIds() != null) {
|
||||
// Check if the player has a cape and set appropriate ID
|
||||
NamespacedId elytraId = player.func_152122_n() ? ELYTRA_WITH_CAPE : ELYTRA;
|
||||
int materialId = Objects.requireNonNull(BlockRenderingSettings.INSTANCE.getItemIds()).applyAsInt(elytraId);
|
||||
CapturedRenderingState.INSTANCE.setCurrentRenderedItem(materialId);
|
||||
iris$didSetId = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* After rendering the elytra, reset the material ID only if we set it.
|
||||
*/
|
||||
@Inject(
|
||||
method = "doRenderLayer",
|
||||
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPopAttrib()V", ordinal = 0, shift = At.Shift.AFTER),
|
||||
remap = false
|
||||
)
|
||||
private static void iris$resetElytraId(EntityLivingBase entityIn, float limbSwing, float limbSwingAmount,
|
||||
float partialTicks, float ageInTicks, float scale, CallbackInfo ci) {
|
||||
// Reset only if we set it
|
||||
if (iris$didSetId) {
|
||||
ItemIdManager.resetItemId();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user