Uniform Additions and fixes (#1102)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2025-11-07 14:39:10 -08:00
1 parent e6e230e270
commit 72ca675c93
22 files changed
+846 -156

No files matched your search

@@ -203,43 +203,45 @@ public class ProgramUniforms {
final int size = sizeType.get(0);
final int type = sizeType.get(1);
UniformType provided = uniformNames.get(name);
final UniformType provided = uniformNames.get(name);
final UniformType expected = getExpectedType(type);
if (provided == null && !name.startsWith("gl_")) {
final String typeName = getTypeName(type);
if(AngelicaConfig.enableHardcodedCustomUniforms) {
// Legacy Checks from hardcoded custom uniforms
if (provided == null && !name.startsWith("gl_")) {
final String typeName = getTypeName(type);
if (isSampler(type) || isImage(type)) {
// don't print a warning, samplers and images are managed elsewhere.
// TODO: Detect unsupported samplers/images?
continue;
}
if (isSampler(type) || isImage(type)) {
// don't print a warning, samplers and images are managed elsewhere.
continue;
}
final UniformType externalProvided = externalUniformNames.get(name);
final UniformType externalProvided = externalUniformNames.get(name);
if (externalProvided != null) {
if (externalProvided != expected) {
String expectedName;
if (externalProvided != null) {
if (externalProvided != expected) {
final String expectedName;
if (expected != null) {
expectedName = expected.toString();
} else {
expectedName = "(unsupported type: " + getTypeName(type) + ")";
if (expected != null) {
expectedName = expected.toString();
} else {
expectedName = "(unsupported type: " + getTypeName(type) + ")";
}
Iris.logger.error("[" + this.name + "] Wrong uniform type for externally-managed uniform " + name + ": " + externalProvided + " is provided but the program expects " + expectedName + ".");
}
Iris.logger.error("[" + this.name + "] Wrong uniform type for externally-managed uniform " + name + ": " + externalProvided + " is provided but the program expects " + expectedName + ".");
continue;
}
if (size == 1) {
Iris.logger.warn("[" + this.name + "] Unsupported uniform: " + typeName + " " + name);
} else {
Iris.logger.warn("[" + this.name + "] Unsupported uniform: " + name + " of size " + size + " and type " + typeName);
}
continue;
}
if (size == 1) {
Iris.logger.warn("[" + this.name + "] Unsupported uniform: " + typeName + " " + name);
} else {
Iris.logger.warn("[" + this.name + "] Unsupported uniform: " + name + " of size " + size + " and type " + typeName);
}
continue;
}
if (provided != null && provided != expected) {
@@ -291,6 +293,7 @@ public class ProgramUniforms {
return switch(type) {
case GL11.GL_FLOAT -> "float";
case GL11.GL_INT -> "int";
case GL20.GL_BOOL -> "bool";
case GL20.GL_FLOAT_MAT4 -> "mat4";
case GL20.GL_FLOAT_VEC4 -> "vec4";
case GL20.GL_FLOAT_MAT3 -> "mat3";
@@ -316,12 +319,13 @@ public class ProgramUniforms {
return switch (type) {
case GL11.GL_FLOAT -> UniformType.FLOAT;
case GL11.GL_INT -> UniformType.INT;
case GL20.GL_BOOL -> UniformType.INT;
case GL20.GL_FLOAT_MAT4 -> UniformType.MAT4;
case GL20.GL_FLOAT_VEC4 -> UniformType.VEC4;
case GL20.GL_INT_VEC4 -> UniformType.VEC4I;
case GL20.GL_FLOAT_VEC3 -> UniformType.VEC3;
case GL20.GL_FLOAT_MAT3 -> null;
case GL20.GL_INT_VEC3 -> null;
case GL20.GL_FLOAT_MAT3 -> UniformType.MAT3;
case GL20.GL_INT_VEC3 -> UniformType.VEC3I;
case GL20.GL_FLOAT_MAT2 -> null;
case GL20.GL_FLOAT_VEC2 -> UniformType.VEC2;
case GL20.GL_INT_VEC2 -> UniformType.VEC2I;
@@ -3,11 +3,13 @@ package net.coderbot.iris.gl.shader;
import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.angelica.Tags;
import cpw.mods.fml.common.Loader;
import net.coderbot.iris.parsing.BiomeCategories;
import net.coderbot.iris.pipeline.HandRenderer;
import net.coderbot.iris.pipeline.WorldRenderingPhase;
import net.coderbot.iris.shaderpack.StringPair;
import net.coderbot.iris.texture.format.TextureFormat;
import net.coderbot.iris.texture.format.TextureFormatLoader;
import net.coderbot.iris.uniforms.VanillaBiomeList;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;
@@ -88,6 +90,9 @@ public class StandardMacros {
define(standardDefines, irisDefine);
}
getBiomeCategoryDefines().forEach((category, ordinal) -> define(standardDefines, category, ordinal));
getVanillaBiomeDefines().forEach((biome, id) -> define(standardDefines, biome, id));
return ImmutableList.copyOf(standardDefines);
}
@@ -98,7 +103,7 @@ public class StandardMacros {
* @see <a href="https://github.com/sp614x/optifine/blob/9c6a5b5326558ccc57c6490b66b3be3b2dc8cbef/OptiFineDoc/doc/shaders.txt#L696-L699">Optifine Doc</a>
*/
public static String getMcVersion() {
final String version = Loader.MC_VERSION;;
final String version = Loader.MC_VERSION;
String[] splitVersion = version.split("\\.");
@@ -117,10 +122,10 @@ public class StandardMacros {
}
if (minor.length() == 1) {
minor = 0 + minor;
minor = "0" + minor;
}
if (bugfix.length() == 1) {
bugfix = 0 + bugfix;
bugfix = "0" + bugfix;
}
return major + minor + bugfix;
@@ -283,4 +288,47 @@ public class StandardMacros {
return defines;
}
/**
* Returns biome category defines for use in shaders.
* Generates #define CAT_<CATEGORY_NAME> <ordinal> for each BiomeCategories enum value.
*
* @return Map of biome category defines and their ordinal values
*/
public static Map<String, String> getBiomeCategoryDefines() {
Map<String, String> defines = new HashMap<>();
for (BiomeCategories category : BiomeCategories.values()) {
defines.put("CAT_" + category.name(), String.valueOf(category.ordinal()));
}
return defines;
}
/**
* Returns vanilla biome ID defines for use in shaders.
* Generates #define BIOME_<BIOME_NAME> <biomeID> for all vanilla biomes.
*
* @return Map of vanilla biome defines and their IDs
*/
public static Map<String, String> getVanillaBiomeDefines() {
final Map<String, String> defines = new HashMap<>();
for (VanillaBiomeList.BiomeEntry entry : VanillaBiomeList.getVanillaBiomes()) {
if (entry.biome != null) {
defines.put("BIOME_" + entry.name, String.valueOf(entry.biome.biomeID));
}
}
// Modern biomes that don't exist in 1.7.10 - add dummy IDs that will never match
// This allows shader expressions to parse without errors while always evaluating to false/0
// Using negative IDs to avoid conflicts with actual biome IDs
defines.put("BIOME_NETHER_WASTES", "-1000");
defines.put("BIOME_SOUL_SAND_VALLEY", "-1001");
defines.put("BIOME_CRIMSON_FOREST", "-1002");
defines.put("BIOME_WARPED_FOREST", "-1003");
defines.put("BIOME_BASALT_DELTAS", "-1004");
defines.put("BIOME_LUSH_CAVES", "-1005");
defines.put("BIOME_PALE_GARDEN", "-1006");
return defines;
}
}
@@ -2,7 +2,9 @@ package net.coderbot.iris.gl.uniform;
public enum UniformType {
INT,
BOOL,
FLOAT,
MAT3,
MAT4,
VEC2,
VEC2I,
@@ -1,6 +1,7 @@
package net.coderbot.iris.pipeline;
import com.gtnewhorizons.angelica.compat.mojang.Camera;
import com.gtnewhorizons.angelica.compat.mojang.GameModeUtil;
import com.gtnewhorizons.angelica.compat.mojang.InteractionHand;
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
@@ -26,7 +27,7 @@ public class HandRenderer {
public static final float DEPTH = 0.125F;
private void setupGlState(RenderGlobal gameRenderer, Camera camera, float tickDelta) {
Minecraft mc = Minecraft.getMinecraft();
final Minecraft mc = Minecraft.getMinecraft();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
@@ -72,8 +73,7 @@ public class HandRenderer {
mc.gameSettings.thirdPersonView == 0 &&
!camera.getEntity().isPlayerSleeping() &&
!mc.gameSettings.hideGUI &&
// TODO: SPECTATOR
// mc.playerController.currentGameType
!GameModeUtil.isSpectator() &&
!mc.playerController.enableEverythingIsScrewedUpMode();
}
@@ -9,6 +9,7 @@ import net.coderbot.iris.pipeline.transform.TransformPatcher;
import net.coderbot.iris.shaderpack.ProgramSet;
import net.coderbot.iris.shaderpack.ProgramSource;
import net.coderbot.iris.uniforms.CommonUniforms;
import net.coderbot.iris.uniforms.ExternallyManagedUniforms;
import net.coderbot.iris.uniforms.builtin.BuiltinReplacementUniforms;
import net.coderbot.iris.uniforms.custom.CustomUniforms;
@@ -143,6 +144,8 @@ public class SodiumTerrainPipeline {
CommonUniforms.addDynamicUniforms(uniforms);
customUniforms.assignTo(uniforms);
ExternallyManagedUniforms.addExternallyManagedUniforms116(uniforms);
BuiltinReplacementUniforms.addBuiltinReplacementUniforms(uniforms);
return uniforms;
}
@@ -18,13 +18,17 @@ import net.coderbot.iris.gl.blending.BlendModeFunction;
import net.coderbot.iris.gl.blending.BlendModeOverride;
import net.coderbot.iris.gl.blending.BufferBlendInformation;
import net.coderbot.iris.gl.texture.TextureScaleOverride;
import net.coderbot.iris.pipeline.PatchedShaderPrinter;
import net.coderbot.iris.shaderpack.option.ShaderPackOptions;
import net.coderbot.iris.shaderpack.preprocessor.PropertiesPreprocessor;
import net.coderbot.iris.shaderpack.texture.TextureStage;
import net.coderbot.iris.uniforms.custom.CustomUniforms;
import net.minecraft.client.Minecraft;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
@@ -98,6 +102,15 @@ public class ShaderProperties {
public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable<StringPair> environmentDefines) {
final String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines);
if (PatchedShaderPrinter.prettyPrintShaders) {
try {
Files.write(Minecraft.getMinecraft().mcDataDir.toPath().resolve("preprocessed.properties"), preprocessedContents.getBytes(StandardCharsets.UTF_8));
Files.write(Minecraft.getMinecraft().mcDataDir.toPath().resolve("original.properties"), contents.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
final Properties preprocessed = new OrderBackedProperties();
final Properties original = new OrderBackedProperties();
try {
@@ -181,7 +194,7 @@ public class ShaderProperties {
});
handlePassDirective("alphaTest.", key, value, pass -> {
if ("off".equals(value)) {
if ("off".equals(value) || "false".equals(value)) {
alphaTestOverrides.put(pass, AlphaTestOverride.OFF);
return;
}
@@ -6,6 +6,7 @@ import net.coderbot.iris.shaderpack.option.ShaderPackOptions;
import org.anarres.cpp.Feature;
import org.anarres.cpp.LexerException;
import org.anarres.cpp.Preprocessor;
import org.anarres.cpp.PreprocessorCommand;
import org.anarres.cpp.StringLexerSource;
import org.anarres.cpp.Token;
@@ -14,18 +15,19 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
public class PropertiesPreprocessor {
// Derived from ShaderProcessor.glslPreprocessSource, which is derived from GlShader from Canvas, licenced under LGPL
public static String preprocessSource(String source, ShaderPackOptions shaderPackOptions, Iterable<StringPair> environmentDefines) {
if (source.contains(PropertyCollectingListener.PROPERTY_MARKER)) {
if (source.contains(PropertyCollectingListener.PROPERTY_MARKER) || source.contains("IRIS_PASSTHROUGHBACKSLASH")) {
throw new RuntimeException("Some shader author is trying to exploit internal Iris implementation details, stop!");
}
List<String> booleanValues = getBooleanValues(shaderPackOptions);
Map<String, String> stringValues = getStringValues(shaderPackOptions);
final List<String> booleanValues = getBooleanValues(shaderPackOptions);
final Map<String, String> stringValues = getStringValues(shaderPackOptions);
try (Preprocessor pp = new Preprocessor()) {
for (String value : booleanValues) {
@@ -57,7 +59,7 @@ public class PropertiesPreprocessor {
throw new RuntimeException("Some shader author is trying to exploit internal Iris implementation details, stop!");
}
Preprocessor preprocessor = new Preprocessor();
final Preprocessor preprocessor = new Preprocessor();
try {
for (StringPair envDefine : environmentDefines) {
@@ -78,19 +80,23 @@ public class PropertiesPreprocessor {
// Not super efficient, but this removes trailing whitespace on lines, fixing an issue with whitespace after
// line continuations (see PreprocessorTest#testWeirdPropertiesLineContinuation)
// Required for Voyager Shader
source = Arrays.stream(source.split("\\R")).map(String::trim)
source = Arrays.stream(source.split("\\R")).map(String::trim).filter(s -> !s.isEmpty())
.map(line -> {
if (line.startsWith("#")) {
// In PropertyCollectingListener we suppress "unknown preprocessor directive errors" and
// assume the line to be a comment, since in .properties files `#` also functions as a comment
// marker.
return line;
} else {
// This is a hack to ensure that non-macro lines don't have any preprocessing applied...
// In properties files, we don't substitute #define values except on macro lines.
return "#warning IRIS_PASSTHROUGH " + line;
for (PreprocessorCommand command : PreprocessorCommand.values()) {
if (line.startsWith("#" + (command.name().replace("PP_", "").toLowerCase(Locale.ROOT)))) {
return line;
}
}
return "";
}
// In PropertyCollectingListener we suppress "unknown preprocessor directive errors" and
// assume the line to be a comment, since in .properties files `#` also functions as a comment
// marker.
return line.replace("#", "");
}).collect(Collectors.joining("\n")) + "\n";
// TODO: This is a horrible fix to trick the preprocessor into not seeing the backslashes during processing. We need a better way to do this.
source = source.replace("\\", "IRIS_PASSTHROUGHBACKSLASH");
preprocessor.addInput(new StringLexerSource(source, true));
preprocessor.addFeature(Feature.KEEPCOMMENTS);
@@ -110,7 +116,7 @@ public class PropertiesPreprocessor {
source = builder.toString();
return listener.collectLines() + source;
return (listener.collectLines() + source).replace("IRIS_PASSTHROUGHBACKSLASH", "\\");
}
private static List<String> getBooleanValues(ShaderPackOptions shaderPackOptions) {
@@ -0,0 +1,369 @@
package net.coderbot.iris.uniforms;
import com.gtnewhorizons.angelica.compat.iris.BiomeCategoryCache;
import com.gtnewhorizons.angelica.compat.iris.ModdedBiomeDetector;
import net.coderbot.iris.gl.uniform.UniformHolder;
import net.coderbot.iris.parsing.BiomeCategories;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MathHelper;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.BiomeGenBeach;
import net.minecraft.world.biome.BiomeGenDesert;
import net.minecraft.world.biome.BiomeGenEnd;
import net.minecraft.world.biome.BiomeGenForest;
import net.minecraft.world.biome.BiomeGenHell;
import net.minecraft.world.biome.BiomeGenHills;
import net.minecraft.world.biome.BiomeGenJungle;
import net.minecraft.world.biome.BiomeGenMesa;
import net.minecraft.world.biome.BiomeGenMushroomIsland;
import net.minecraft.world.biome.BiomeGenMutated;
import net.minecraft.world.biome.BiomeGenOcean;
import net.minecraft.world.biome.BiomeGenPlains;
import net.minecraft.world.biome.BiomeGenRiver;
import net.minecraft.world.biome.BiomeGenSavanna;
import net.minecraft.world.biome.BiomeGenSnow;
import net.minecraft.world.biome.BiomeGenStoneBeach;
import net.minecraft.world.biome.BiomeGenSwamp;
import net.minecraft.world.biome.BiomeGenTaiga;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.HashMap;
import java.util.Map;
import static net.coderbot.iris.gl.uniform.UniformUpdateFrequency.PER_TICK;
public class BiomeUniforms {
private static final Logger LOGGER = LogManager.getLogger("BiomeUniforms");
private static final Minecraft client = Minecraft.getMinecraft();
// Cache to avoid multiple biome lookups per tick
private static BiomeGenBase cachedBiome = null;
private static long cachedWorldTime = -1;
private static int cachedPlayerX = Integer.MIN_VALUE;
private static int cachedPlayerZ = Integer.MIN_VALUE;
/**
* Adds biome-related uniforms that change based on the player's current biome.
*/
public static void addBiomeUniforms(UniformHolder uniforms) {
uniforms.uniform1i(PER_TICK, "biome", BiomeUniforms::getBiomeId)
.uniform1i(PER_TICK, "biome_category", BiomeUniforms::getBiomeCategory)
.uniform1i(PER_TICK, "biome_precipitation", BiomeUniforms::getBiomePrecipitation)
.uniform1f(PER_TICK, "rainfall", BiomeUniforms::getBiomeRainfall)
.uniform1f(PER_TICK, "temperature", BiomeUniforms::getBiomeTemperature);
}
/**
* Gets the current biome, with caching to avoid repeated lookups within the same tick.
* Returns null if player or world is not available.
*/
private static BiomeGenBase getCachedBiome() {
if (client.thePlayer == null || client.theWorld == null) {
return null;
}
final long worldTime = client.theWorld.getTotalWorldTime();
final int playerX = MathHelper.floor_double(client.thePlayer.posX);
final int playerZ = MathHelper.floor_double(client.thePlayer.posZ);
// Invalidate cache if time or position changed
if (cachedBiome == null || cachedWorldTime != worldTime || cachedPlayerX != playerX || cachedPlayerZ != playerZ) {
cachedBiome = client.theWorld.getBiomeGenForCoords(playerX, playerZ);
cachedWorldTime = worldTime;
cachedPlayerX = playerX;
cachedPlayerZ = playerZ;
}
return cachedBiome;
}
public static int getBiomePrecipitation() {
final BiomeGenBase biome = getCachedBiome();
if (biome == null) {
return 0;
}
if (!biome.enableRain && !biome.enableSnow) {
return 0;
}
final float temp = biome.getFloatTemperature(
MathHelper.floor_double(client.thePlayer.posX),
MathHelper.floor_double(client.thePlayer.posY),
MathHelper.floor_double(client.thePlayer.posZ));
return temp > 0.15F ? 1 : 2;
}
public static float getBiomeRainfall() {
final BiomeGenBase biome = getCachedBiome();
return biome != null ? biome.rainfall : 0.0F;
}
public static float getBiomeTemperature() {
final BiomeGenBase biome = getCachedBiome();
return biome != null ? biome.temperature : 0.0F;
}
public static int getBiomeId() {
final BiomeGenBase biome = getCachedBiome();
return biome != null ? biome.biomeID : 0;
}
public static int getBiomeCategory() {
final BiomeGenBase biome = getCachedBiome();
if (biome == null) {
return BiomeCategories.NONE.ordinal();
}
// Check cache first
if (biome instanceof BiomeCategoryCache cache) {
final int cached = cache.iris$getCachedCategory();
if (cached != -1) {
return cached;
}
// Not cached yet, determine and cache it
final int category = determineBiomeCategory(biome);
cache.iris$setCachedCategory(category);
final BiomeCategories[] categories = BiomeCategories.values();
final String categoryName = (category >= 0 && category < categories.length)
? categories[category].name()
: "INVALID(" + category + ")";
LOGGER.debug("Cached biome category for '{}': {}", biome.biomeName, categoryName);
return category;
}
// Fallback if mixin didn't apply (shouldn't happen)
return determineBiomeCategory(biome);
}
private static int determineBiomeCategory(BiomeGenBase biome) {
// Tier 1: Hardcoded vanilla biome IDs
BiomeGenBase lookupBiome = biome;
if (biome instanceof BiomeGenMutated mutated && mutated.baseBiome != null) {
lookupBiome = mutated.baseBiome;
}
BiomeCategories category = getVanillaBiomeCategory(lookupBiome.biomeID);
if (category != null) {
return category.ordinal();
}
// Tier 2: Class-based detection for vanilla biome types
category = detectVanillaBiomeByClass(biome);
if (category != null) {
return category.ordinal();
}
// Tier 3: Modded biome detection (BiomesOPlenty, Realistic World Gen)
category = detectModdedBiome(biome);
if (category != null) {
return category.ordinal();
}
// Tier 4: Name pattern matching
category = detectBiomeByName(biome);
if (category != null) {
return category.ordinal();
}
// Tier 5: Temperature/rainfall heuristics
category = detectBiomeByProperties(biome);
if (category != null) {
return category.ordinal();
}
// Default: NONE
return BiomeCategories.NONE.ordinal();
}
private static BiomeCategories getVanillaBiomeCategory(int biomeID) {
return switch (biomeID) {
// OCEAN
case 0, 10, 24 -> BiomeCategories.OCEAN; // ocean, frozenOcean, deepOcean
// PLAINS
case 1 -> BiomeCategories.PLAINS; // plains
// DESERT
case 2, 17 -> BiomeCategories.DESERT; // desert, desertHills
// EXTREME_HILLS (Vanilla mountains)
case 3, 20, 34 -> BiomeCategories.EXTREME_HILLS; // extremeHills, extremeHillsEdge, extremeHillsPlus
// FOREST
case 4, 18, 27, 28, 29 ->
BiomeCategories.FOREST; // forest, forestHills, birchForest, birchForestHills, roofedForest
// TAIGA
case 5, 19, 30, 31, 32, 33 ->
BiomeCategories.TAIGA; // taiga, taigaHills, coldTaiga, coldTaigaHills, megaTaiga, megaTaigaHills
// SWAMP
case 6 -> BiomeCategories.SWAMP; // swampland
// RIVER
case 7, 11 -> BiomeCategories.RIVER; // river, frozenRiver
// NETHER
case 8 -> BiomeCategories.NETHER; // hell
// THE_END
case 9 -> BiomeCategories.THE_END; // sky
// ICY
case 12, 13 -> BiomeCategories.ICY; // icePlains, iceMountains
// MUSHROOM
case 14, 15 -> BiomeCategories.MUSHROOM; // mushroomIsland, mushroomIslandShore
// BEACH
case 16, 25, 26 -> BiomeCategories.BEACH; // beach, stoneBeach, coldBeach
// JUNGLE
case 21, 22, 23 -> BiomeCategories.JUNGLE; // jungle, jungleHills, jungleEdge
// SAVANNA
case 35, 36 -> BiomeCategories.SAVANNA; // savanna, savannaPlateau
// MESA
case 37, 38, 39 -> BiomeCategories.MESA; // mesa, mesaPlateau_F, mesaPlateau
default -> null; // Not a vanilla biome or unknown
};
}
private static final Map<Class<? extends BiomeGenBase>, BiomeCategories> VANILLA_CLASS_MAP = createVanillaClassMap();
private static Map<Class<? extends BiomeGenBase>, BiomeCategories> createVanillaClassMap() {
final Map<Class<? extends BiomeGenBase>, BiomeCategories> map = new HashMap<>();
// Most specific first (subclasses before superclasses)
map.put(BiomeGenStoneBeach.class, BiomeCategories.BEACH);
map.put(BiomeGenBeach.class, BiomeCategories.BEACH);
map.put(BiomeGenMushroomIsland.class, BiomeCategories.MUSHROOM);
map.put(BiomeGenOcean.class, BiomeCategories.OCEAN);
map.put(BiomeGenPlains.class, BiomeCategories.PLAINS);
map.put(BiomeGenDesert.class, BiomeCategories.DESERT);
map.put(BiomeGenHills.class, BiomeCategories.EXTREME_HILLS);
map.put(BiomeGenForest.class, BiomeCategories.FOREST);
map.put(BiomeGenTaiga.class, BiomeCategories.TAIGA);
map.put(BiomeGenSwamp.class, BiomeCategories.SWAMP);
map.put(BiomeGenRiver.class, BiomeCategories.RIVER);
map.put(BiomeGenHell.class, BiomeCategories.NETHER);
map.put(BiomeGenEnd.class, BiomeCategories.THE_END);
map.put(BiomeGenSnow.class, BiomeCategories.ICY);
map.put(BiomeGenJungle.class, BiomeCategories.JUNGLE);
map.put(BiomeGenSavanna.class, BiomeCategories.SAVANNA);
map.put(BiomeGenMesa.class, BiomeCategories.MESA);
return map;
}
private static BiomeCategories detectVanillaBiomeByClass(BiomeGenBase biome) {
// Direct class lookup (O(1) for exact matches)
final BiomeCategories direct = VANILLA_CLASS_MAP.get(biome.getClass());
if (direct != null) {
return direct;
}
// Fallback: instanceof checks for subclasses (modded biomes extending vanilla)
for (Map.Entry<Class<? extends BiomeGenBase>, BiomeCategories> entry : VANILLA_CLASS_MAP.entrySet()) {
if (entry.getKey().isInstance(biome)) {
return entry.getValue();
}
}
return null;
}
private static BiomeCategories detectModdedBiome(BiomeGenBase biome) {
return ModdedBiomeDetector.detectModdedBiome(biome);
}
private static BiomeCategories detectBiomeByName(BiomeGenBase biome) {
if (biome.biomeName == null) return null;
final String name = biome.biomeName.toLowerCase();
// Check for keywords in biome names
// Priority order matters - check more specific terms first
if (name.contains("nether")) return BiomeCategories.NETHER;
if (name.contains("end")) return BiomeCategories.THE_END;
if (name.contains("ocean") || name.contains("sea")) return BiomeCategories.OCEAN;
if (name.contains("river") || name.contains("stream")) return BiomeCategories.RIVER;
if (name.contains("beach") || name.contains("shore") || name.contains("coast")) return BiomeCategories.BEACH;
if (name.contains("mushroom")) return BiomeCategories.MUSHROOM;
if (name.contains("swamp") || name.contains("marsh") || name.contains("bog")) return BiomeCategories.SWAMP;
if (name.contains("jungle")) return BiomeCategories.JUNGLE;
if (name.contains("savanna") || name.contains("savannah")) return BiomeCategories.SAVANNA;
if (name.contains("mesa") || name.contains("badlands")) return BiomeCategories.MESA;
if (name.contains("desert")) return BiomeCategories.DESERT;
// Mountain detection - for modded biomes
if (name.contains("mountain") || name.contains("peak") || name.contains("alpine") ||
name.contains("cliff") || name.contains("crag")) return BiomeCategories.MOUNTAIN;
// Ice/Snow detection
if (name.contains("ice") || name.contains("frozen") || name.contains("snow") ||
name.contains("arctic") || name.contains("tundra") || name.contains("glacier")) return BiomeCategories.ICY;
if (name.contains("taiga") || name.contains("boreal") || name.contains("conifer")) return BiomeCategories.TAIGA;
if (name.contains("forest") || name.contains("wood") || name.contains("grove") ||
name.contains("thicket")) return BiomeCategories.FOREST;
if (name.contains("plain") || name.contains("field") || name.contains("meadow") ||
name.contains("grassland") || name.contains("prairie")) return BiomeCategories.PLAINS;
return null;
}
private static BiomeCategories detectBiomeByProperties(BiomeGenBase biome) {
final float temp = biome.temperature;
final float rain = biome.rainfall;
// Very cold biomes with snow
if (temp <= 0.0F && biome.enableSnow) {
return BiomeCategories.ICY;
}
// Hot, dry biomes
if (temp >= 2.0F && !biome.enableRain) {
return BiomeCategories.DESERT;
}
// Warm, dry biomes (savanna-like)
if (temp >= 1.0F && rain <= 0.1F && !biome.enableRain) {
return BiomeCategories.SAVANNA;
}
// Wet biomes with high rainfall
if (rain >= 0.85F && temp >= 0.5F && temp <= 1.0F) {
return BiomeCategories.SWAMP;
}
// Cold forested biomes
if (temp >= 0.0F && temp <= 0.4F && rain >= 0.4F) {
return BiomeCategories.TAIGA;
}
// Temperate forested biomes
if (temp >= 0.4F && temp <= 0.9F && rain >= 0.5F) {
return BiomeCategories.FOREST;
}
// Default to plains for temperate, moderate biomes
if (temp >= 0.4F && temp <= 1.0F && rain >= 0.3F && rain <= 0.6F) {
return BiomeCategories.PLAINS;
}
return null;
}
}
@@ -20,14 +20,11 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.biome.BiomeGenBase;
import org.joml.Math;
import org.joml.Vector2f;
import org.joml.Vector2i;
@@ -53,6 +50,7 @@ public final class CommonUniforms {
ViewportUniforms.addViewportUniforms(uniforms);
WorldTimeUniforms.addWorldTimeUniforms(uniforms);
SystemTimeUniforms.addSystemTimeUniforms(uniforms);
BiomeUniforms.addBiomeUniforms(uniforms);
new CelestialUniforms(directives.getSunPathRotation()).addCelestialUniforms(uniforms);
IrisExclusiveUniforms.addIrisExclusiveUniforms(uniforms);
IdMapUniforms.addIdMapUniforms(updateNotifier, uniforms, idMap, directives.isOldHandLight());
@@ -67,6 +65,7 @@ public final class CommonUniforms {
// Needs to use a LocationalUniformHolder as we need it for the common uniforms
public static void addDynamicUniforms(DynamicUniformHolder uniforms) {
ExternallyManagedUniforms.addExternallyManagedUniforms116(uniforms);
IdMapUniforms.addEntityIdMapUniforms(uniforms);
FogUniforms.addFogUniforms(uniforms);
@@ -113,6 +112,7 @@ public final class CommonUniforms {
uniforms
.uniform1f(ONCE, "darknessFactor", () -> 0.0F) // This is PER_FRAME in modern, it is an effect added by The Warden. We're just setting to 0 because 1.7.10 doesn't have it.
.uniform1f(ONCE, "darknessLightFactor", () -> 0.0F) // Warden darkness current light factor - 1.7.10 doesn't have it so hardcode to 0
.uniform1b(PER_FRAME, "hideGUI", () -> client.gameSettings.hideGUI)
.uniform1i(PER_FRAME, "isEyeInWater", CommonUniforms::isEyeInWater)
.uniform1f(PER_FRAME, "blindness", CommonUniforms::getBlindness)
@@ -137,11 +137,7 @@ public final class CommonUniforms {
.uniform1f(PER_TICK, "rainStrength", CommonUniforms::getRainStrength)
.uniform1f(PER_TICK, "wetness", new SmoothedFloat(directives.getWetnessHalfLife(), directives.getDrynessHalfLife(), CommonUniforms::getRainStrength, updateNotifier))
.uniform3d(PER_FRAME, "skyColor", CommonUniforms::getSkyColor)
.uniform3d(PER_FRAME, "fogColor", GLStateManager::getFogColor)
.uniform1i(PER_TICK, "biome_precipitation", CommonUniforms::getBiomePrecipitation)
.uniform1f(PER_TICK, "rainfall", CommonUniforms::getBiomeRainfall)
.uniform1f(PER_TICK, "temperature", CommonUniforms::getBiomeTemperature);
.uniform3d(PER_FRAME, "fogColor", GLStateManager::getFogColor);
}
private static boolean isOnGround() {
@@ -153,38 +149,7 @@ public final class CommonUniforms {
return (client.thePlayer != null && client.thePlayer.hurtTime > 0);
}
private static BiomeGenBase getBiome() {
return client.theWorld.getBiomeGenForCoords(MathHelper.floor_double(client.thePlayer.posX), MathHelper.floor_double(client.thePlayer.posZ));
}
private static int getBiomePrecipitation() {
if (client.thePlayer == null || client.theWorld == null) {
return 0;
}
BiomeGenBase biome = getBiome();
float temp = biome.getFloatTemperature(MathHelper.floor_double(client.thePlayer.posX), MathHelper.floor_double(client.thePlayer.posY), MathHelper.floor_double(client.thePlayer.posZ));
if (!biome.enableRain && !biome.enableSnow) {
return 0;
} else if (temp > 0.15F) {
return 1;
} else {
return 2;
}
}
private static float getBiomeRainfall() {
if (client.thePlayer == null || client.theWorld == null) return 0.0F;
return getBiome().rainfall;
}
private static float getBiomeTemperature() {
if (client.thePlayer == null || client.theWorld == null) return 0.0F;
return getBiome().temperature;
}
private static boolean isInvisible() {
private static boolean isInvisible() {
return (client.thePlayer != null && client.thePlayer.isInvisible());
}
@@ -12,9 +12,9 @@ public class ExternallyManagedUniforms {
addMat4(uniformHolder, "iris_ModelViewMatrix");
addMat4(uniformHolder, "u_ModelViewProjectionMatrix");
addMat4(uniformHolder, "iris_NormalMatrix");
// Exclusive to pre-1.19
addFloat(uniformHolder, "darknessFactor");
addFloat(uniformHolder, "darknessLightFactor");
// 1.21.6+
uniformHolder.externallyManagedUniform("heavyFog", UniformType.BOOL);
}
public static void addExternallyManagedUniforms116(UniformHolder uniformHolder) {
@@ -1,16 +1,28 @@
package net.coderbot.iris.uniforms;
import com.gtnewhorizons.angelica.compat.mojang.Camera;
import com.gtnewhorizons.angelica.compat.mojang.GameModeUtil;
import net.coderbot.iris.gl.uniform.UniformHolder;
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.effect.EntityLightningBolt;
import org.joml.Math;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.Vector4f;
import java.util.List;
public class IrisExclusiveUniforms {
// Reusable vectors to avoid allocations every frame
private static final Vector3d eyePositionCache = new Vector3d();
private static final Vector3d relativeEyePositionCache = new Vector3d();
private static final Vector4f lightningBoltPositionCache = new Vector4f();
private static final Vector4f ZERO_VECTOR_4f = new Vector4f(0, 0, 0, 0);
public static void addIrisExclusiveUniforms(UniformHolder uniforms) {
WorldInfoUniforms.addWorldInfoUniforms(uniforms);
@@ -24,20 +36,10 @@ public class IrisExclusiveUniforms {
uniforms.uniform1f(UniformUpdateFrequency.PER_TICK, "maxPlayerAir", IrisExclusiveUniforms::getMaxAir);
uniforms.uniform1b(UniformUpdateFrequency.PER_FRAME, "firstPersonCamera", IrisExclusiveUniforms::isFirstPersonCamera);
uniforms.uniform1b(UniformUpdateFrequency.PER_TICK, "isSpectator", IrisExclusiveUniforms::isSpectator);
uniforms.uniform1b(UniformUpdateFrequency.PER_TICK, "isRightHanded", () -> true); // 1.7.10 doesn't support left-handed mode
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "eyePosition", IrisExclusiveUniforms::getEyePosition);
// TODO: Iris Shaders
// Vector4f zero = new Vector4f(0, 0, 0, 0);
// uniforms.uniform4f(UniformUpdateFrequency.PER_TICK, "lightningBoltPosition", () -> {
// if (Minecraft.getMinecraft().theWorld != null) {
// return StreamSupport.stream(Minecraft.getMinecraft().theWorld.entitiesForRendering().spliterator(), false).filter(bolt -> bolt instanceof LightningBolt).findAny().map(bolt -> {
// Vector3d unshiftedCameraPosition = CameraUniforms.getUnshiftedCameraPosition();
// Vec3 vec3 = bolt.getPosition(Minecraft.getMinecraft().getDeltaFrameTime());
// return new Vector4f((float) (vec3.x - unshiftedCameraPosition.x), (float) (vec3.y - unshiftedCameraPosition.y), (float) (vec3.z - unshiftedCameraPosition.z), 1);
// }).orElse(zero);
// } else {
// return zero;
// }
// });
uniforms.uniform3d(UniformUpdateFrequency.PER_FRAME, "relativeEyePosition", IrisExclusiveUniforms::getRelativeEyePosition);
uniforms.uniform4f(UniformUpdateFrequency.PER_TICK, "lightningBoltPosition", IrisExclusiveUniforms::getLightningBoltPosition);
}
private static float getThunderStrength() {
@@ -88,21 +90,40 @@ public class IrisExclusiveUniforms {
private static boolean isFirstPersonCamera() {
// If camera type is not explicitly third-person, assume it's first-person.
return (Minecraft.getMinecraft().gameSettings.thirdPersonView == 1);
return !Camera.INSTANCE.isThirdPerson();
}
private static boolean isSpectator() {
final PlayerControllerMP controller = Minecraft.getMinecraft().playerController;
if(controller == null)
return false;
return controller.currentGameType.getID() == 3;
return GameModeUtil.isSpectator();
}
private static Vector3d getEyePosition() {
// Objects.requireNonNull(Minecraft.getMinecraft().getCameraEntity());
// return new Vector3d(Minecraft.getMinecraft().getCameraEntity().getX(), Minecraft.getMinecraft().getCameraEntity().getEyeY(), Minecraft.getMinecraft().getCameraEntity().getZ());
final EntityLivingBase eye = Minecraft.getMinecraft().renderViewEntity;
return new Vector3d(eye.posX, eye.posY, eye.posZ);
return eyePositionCache.set(eye.posX, eye.posY + eye.getEyeHeight(), eye.posZ);
}
private static Vector3d getRelativeEyePosition() {
final Vector3dc cameraPos = CameraUniforms.getUnshiftedCameraPosition();
final Vector3d eyePos = getEyePosition();
return relativeEyePositionCache.set(eyePos).sub(cameraPos);
}
private static Vector4f getLightningBoltPosition() {
if (Minecraft.getMinecraft().theWorld != null) {
final List<Entity> weatherEffects = Minecraft.getMinecraft().theWorld.weatherEffects;
for (Entity entity : weatherEffects) {
if (entity instanceof EntityLightningBolt bolt) {
final Vector3dc cameraPos = CameraUniforms.getUnshiftedCameraPosition();
return lightningBoltPositionCache.set(
(float)(bolt.posX - cameraPos.x()),
(float)(bolt.posY - cameraPos.y()),
(float)(bolt.posZ - cameraPos.z()),
1.0f
);
}
}
}
return ZERO_VECTOR_4f;
}
public static class WorldInfoUniforms {
@@ -0,0 +1,85 @@
package net.coderbot.iris.uniforms;
import net.minecraft.world.biome.BiomeGenBase;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class VanillaBiomeList {
public static class BiomeEntry {
public final BiomeGenBase biome;
public final String name;
public BiomeEntry(BiomeGenBase biome, String name) {
this.biome = biome;
this.name = name;
}
}
private static final List<BiomeEntry> VANILLA_BIOMES = createVanillaBiomeList();
private static List<BiomeEntry> createVanillaBiomeList() {
final List<BiomeEntry> biomes = new ArrayList<>();
// Vanilla biomes from BiomeGenBase static fields (IDs 0-39)
biomes.add(new BiomeEntry(BiomeGenBase.ocean, "OCEAN"));
biomes.add(new BiomeEntry(BiomeGenBase.plains, "PLAINS"));
biomes.add(new BiomeEntry(BiomeGenBase.desert, "DESERT"));
biomes.add(new BiomeEntry(BiomeGenBase.extremeHills, "EXTREME_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.forest, "FOREST"));
biomes.add(new BiomeEntry(BiomeGenBase.taiga, "TAIGA"));
biomes.add(new BiomeEntry(BiomeGenBase.swampland, "SWAMPLAND"));
biomes.add(new BiomeEntry(BiomeGenBase.river, "RIVER"));
biomes.add(new BiomeEntry(BiomeGenBase.hell, "HELL"));
biomes.add(new BiomeEntry(BiomeGenBase.sky, "SKY"));
biomes.add(new BiomeEntry(BiomeGenBase.frozenOcean, "FROZEN_OCEAN"));
biomes.add(new BiomeEntry(BiomeGenBase.frozenRiver, "FROZEN_RIVER"));
biomes.add(new BiomeEntry(BiomeGenBase.icePlains, "ICE_PLAINS"));
biomes.add(new BiomeEntry(BiomeGenBase.iceMountains, "ICE_MOUNTAINS"));
biomes.add(new BiomeEntry(BiomeGenBase.mushroomIsland, "MUSHROOM_ISLAND"));
biomes.add(new BiomeEntry(BiomeGenBase.mushroomIslandShore, "MUSHROOM_ISLAND_SHORE"));
biomes.add(new BiomeEntry(BiomeGenBase.beach, "BEACH"));
biomes.add(new BiomeEntry(BiomeGenBase.desertHills, "DESERT_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.forestHills, "FOREST_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.taigaHills, "TAIGA_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.extremeHillsEdge, "EXTREME_HILLS_EDGE"));
biomes.add(new BiomeEntry(BiomeGenBase.jungle, "JUNGLE"));
biomes.add(new BiomeEntry(BiomeGenBase.jungleHills, "JUNGLE_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.jungleEdge, "JUNGLE_EDGE"));
biomes.add(new BiomeEntry(BiomeGenBase.deepOcean, "DEEP_OCEAN"));
biomes.add(new BiomeEntry(BiomeGenBase.stoneBeach, "STONE_BEACH"));
biomes.add(new BiomeEntry(BiomeGenBase.coldBeach, "COLD_BEACH"));
biomes.add(new BiomeEntry(BiomeGenBase.birchForest, "BIRCH_FOREST"));
biomes.add(new BiomeEntry(BiomeGenBase.birchForestHills, "BIRCH_FOREST_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.roofedForest, "ROOFED_FOREST"));
biomes.add(new BiomeEntry(BiomeGenBase.coldTaiga, "COLD_TAIGA"));
biomes.add(new BiomeEntry(BiomeGenBase.coldTaigaHills, "COLD_TAIGA_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.megaTaiga, "MEGA_TAIGA"));
biomes.add(new BiomeEntry(BiomeGenBase.megaTaigaHills, "MEGA_TAIGA_HILLS"));
biomes.add(new BiomeEntry(BiomeGenBase.extremeHillsPlus, "EXTREME_HILLS_PLUS"));
biomes.add(new BiomeEntry(BiomeGenBase.savanna, "SAVANNA"));
biomes.add(new BiomeEntry(BiomeGenBase.savannaPlateau, "SAVANNA_PLATEAU"));
biomes.add(new BiomeEntry(BiomeGenBase.mesa, "MESA"));
biomes.add(new BiomeEntry(BiomeGenBase.mesaPlateau_F, "MESA_PLATEAU_F"));
biomes.add(new BiomeEntry(BiomeGenBase.mesaPlateau, "MESA_PLATEAU"));
// Modern End biome variants (1.9+) - all map to the single End biome in 1.7.10
// This allows shaders expecting these constants to work
biomes.add(new BiomeEntry(BiomeGenBase.sky, "THE_END"));
biomes.add(new BiomeEntry(BiomeGenBase.sky, "SMALL_END_ISLANDS"));
biomes.add(new BiomeEntry(BiomeGenBase.sky, "END_MIDLANDS"));
biomes.add(new BiomeEntry(BiomeGenBase.sky, "END_HIGHLANDS"));
biomes.add(new BiomeEntry(BiomeGenBase.sky, "END_BARRENS"));
return Collections.unmodifiableList(biomes);
}
/**
* Returns the cached list of all vanilla biomes with their shader-friendly names.
* The list is immutable and created once during class initialization.
*/
public static List<BiomeEntry> getVanillaBiomes() {
return VANILLA_BIOMES;
}
}