Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.20.2' into 1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Nov 16, 2023
2 parents e2a0d7d + 249ee71 commit 56043d2
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.pipeline.newshader.NewWorldRenderingPipeline;
import net.coderbot.iris.shaderpack.DimensionId;
import net.coderbot.iris.shaderpack.IrisDefines;
import net.coderbot.iris.shaderpack.OptionalBoolean;
import net.coderbot.iris.shaderpack.ProgramSet;
import net.coderbot.iris.shaderpack.ShaderPack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static void define(List<StringPair> defines, String key, String value) {
defines.add(new StringPair(key, value));
}

public static Iterable<StringPair> createStandardEnvironmentDefines() {
public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
ArrayList<StringPair> standardDefines = new ArrayList<>();

define(standardDefines, "MC_VERSION", getMcVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,10 @@ public int getCurrentWidth() {
public int getCurrentHeight() {
return cachedHeight;
}

public void createIfUnsure(int index) {
if (targets[index] == null) {
create(index);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/net/coderbot/iris/samplers/IrisImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static void addRenderTargetImages(ImageHolder images, Supplier<ImmutableS

if (!images.hasImage(name)) continue;

renderTargets.createIfUnsure(index);

// Note: image bindings *are* impacted by buffer flips.
IntSupplier textureID = () -> {
ImmutableSet<Integer> flippedBuffers = flipped.get();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/coderbot/iris/samplers/IrisSamplers.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ public static void addRenderTargetSamplers(SamplerHolder samplers, Supplier<Immu
if (i < PackRenderTargetDirectives.LEGACY_RENDER_TARGETS.size()) {
String legacyName = PackRenderTargetDirectives.LEGACY_RENDER_TARGETS.get(i);

if (samplers.hasSampler(legacyName) || samplers.hasSampler(name)) {
renderTargets.createIfUnsure(index);
}

// colortex0 is the default sampler in fullscreen passes
if (i == 0 && isFullscreenPass) {
samplers.addDefaultSampler(TextureType.TEXTURE_2D, texture, null, null, name, legacyName);
} else {
samplers.addDynamicSampler(TextureType.TEXTURE_2D, texture, null, name, legacyName);
}
} else {
if (samplers.hasSampler(name)) {
renderTargets.createIfUnsure(index);
}

samplers.addDynamicSampler(texture, name);
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/net/coderbot/iris/shaderpack/IrisDefines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.coderbot.iris.shaderpack;

import com.google.common.collect.ImmutableList;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.shader.StandardMacros;
import net.coderbot.iris.parsing.BiomeCategories;
import net.coderbot.iris.uniforms.BiomeParameters;
import net.minecraft.world.level.biome.Biome;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

public class IrisDefines {
private static final Pattern SEMVER_PATTERN = Pattern.compile("(?<major>\\d+)\\.(?<minor>\\d+)\\.*(?<bugfix>\\d*)(.*)");

private static void define(List<StringPair> defines, String key) {
defines.add(new StringPair(key, ""));
}

private static void define(List<StringPair> defines, String key, String value) {
defines.add(new StringPair(key, value));
}

public static ImmutableList<StringPair> createIrisReplacements() {
ArrayList<StringPair> s = new ArrayList<>(StandardMacros.createStandardEnvironmentDefines());
define(s, "PPT_NONE", "0");
define(s, "PPT_RAIN", "1");
define(s, "PPT_SNOW", "2");
define(s, "BIOME_SWAMP_HILLS", "-1");

BiomeParameters.getBiomeMap().forEach((biome, id) -> define(s, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), String.valueOf(id)));

BiomeCategories[] categories = BiomeCategories.values();
for (int i = 0; i < categories.length; i++) {
define(s, "CAT_" + categories[i].name().toUpperCase(Locale.ROOT), String.valueOf(i));
}

return ImmutableList.copyOf(s);
}
}
18 changes: 5 additions & 13 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,7 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -161,9 +151,10 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, Iterable<String
this.shaderPackOptions = new ShaderPackOptions(graph, changedConfigs);
graph = this.shaderPackOptions.getIncludes();

Iterable<StringPair> replacements = IrisDefines.createIrisReplacements();
Iterable<StringPair> finalEnvironmentDefines = environmentDefines;
this.shaderProperties = loadProperties(root, "shaders.properties")
.map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines))
.map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines, replacements))
.orElseGet(ShaderProperties::empty);

activeFeatures = new HashSet<>();
Expand Down Expand Up @@ -248,7 +239,8 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, Iterable<String
IncludeProcessor includeProcessor = new IncludeProcessor(graph);

// Set up our source provider for creating ProgramSets
Iterable<StringPair> finalEnvironmentDefines1 = environmentDefines;
ArrayList<StringPair> finalEnvironmentDefines1 = new ArrayList<>((Collection) finalEnvironmentDefines);
finalEnvironmentDefines1.addAll(IrisDefines.createIrisReplacements());
this.sourceProvider = (path) -> {
String pathString = path.getPathString();
// Removes the first "/" in the path if present, and the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ private ShaderProperties() {
}

// TODO: Is there a better solution than having ShaderPack pass a root path to ShaderProperties to be able to read textures?
public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable<StringPair> environmentDefines) {
public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable<StringPair> environmentDefines, Iterable<StringPair> replacements) {
for (StringPair pair : replacements) {
contents = contents.replace(pair.getKey(), pair.getValue());
}

String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines);

Properties preprocessed = new OrderBackedProperties();
Expand Down
29 changes: 1 addition & 28 deletions src/main/java/net/coderbot/iris/uniforms/BiomeParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public static Object2IntMap<ResourceKey<Biome>> getBiomeMap() {
}

public static void addBiomeUniforms(UniformHolder uniforms) {

uniforms
.uniform1i(PER_TICK, "biome", playerI(player ->
biomeMap.getInt(player.level().getBiome(player.blockPosition()).unwrapKey().orElse(null))))
Expand All @@ -56,21 +55,7 @@ public static void addBiomeUniforms(UniformHolder uniforms) {
.uniform1f(PER_TICK, "rainfall", playerF(player ->
((ExtendedBiome) (Object) player.level().getBiome(player.blockPosition()).value()).getDownfall()))
.uniform1f(PER_TICK, "temperature", playerF(player ->
player.level().getBiome(player.blockPosition()).value().getBaseTemperature()))


.uniform1i(ONCE, "PPT_NONE", () -> 0)
.uniform1i(ONCE, "PPT_RAIN", () -> 1)
.uniform1i(ONCE, "PPT_SNOW", () -> 2)
// Temporary fix for Sildur's Vibrant
.uniform1i(ONCE, "BIOME_SWAMP_HILLS", () -> -1);




addBiomes(uniforms);
addCategories(uniforms);

player.level().getBiome(player.blockPosition()).value().getBaseTemperature()));
}

private static BiomeCategories getBiomeCategory(Holder<Biome> holder) {
Expand Down Expand Up @@ -114,18 +99,6 @@ private static BiomeCategories getBiomeCategory(Holder<Biome> holder) {
}
}

private static void addBiomes(UniformHolder uniforms) {
biomeMap.forEach((biome, id) -> uniforms.uniform1i(ONCE, "BIOME_" + biome.location().getPath().toUpperCase(Locale.ROOT), () -> id));
}

public static void addCategories(UniformHolder uniforms) {
BiomeCategories[] categories = BiomeCategories.values();
for (int i = 0; i < categories.length; i++) {
int finalI = i;
uniforms.uniform1i(ONCE, "CAT_" + categories[i].name().toUpperCase(Locale.ROOT), () -> finalI);
}
}

static IntSupplier playerI(ToIntFunction<LocalPlayer> function) {
return () -> {
LocalPlayer player = Minecraft.getInstance().player;
Expand Down

0 comments on commit 56043d2

Please sign in to comment.