Skip to content

Commit

Permalink
Merge branch '1.18.2' into 1.19.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
IMS212 committed Dec 5, 2023
2 parents 23edd63 + 8a6cdbb commit 7a24ded
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

## Links

* **Visit [our website](https://irisshaders.net) for downloads and pretty screenshots!**\
* **Visit [Modrinth](https://modrinth.com/shaders) to find shader packs!**
* **Visit [our website](https://irisshaders.dev) for downloads and pretty screenshots!**
* * **Visit [Modrinth](https://modrinth.com/shaders) to find shader packs!**
* Visit [our Discord server](https://discord.gg/jQJnav2jPu) to chat about the mod and get support! It's also a great place to get development updates right as they're happening.
* Visit [the developer documentation](https://github.com/IrisShaders/Iris/tree/trunk/docs/development) for information on developing, building, and contributing to Iris!

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class MixinGameRenderer {
itemInHandRenderer.renderHandsWithItems(tickDelta, poseStack, bufferSource, localPlayer, light);
}

@Inject(method = "renderLevel", at = @At("TAIL"))
private void iris$runColorSpace(float pGameRenderer0, long pLong1, PoseStack pPoseStack2, CallbackInfo ci) {
Iris.getPipelineManager().getPipeline().ifPresent(WorldRenderingPipeline::finalizeGameRendering);
}

@Redirect(method = "reloadShaders", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Lists;newArrayList()Ljava/util/ArrayList;"))
private ArrayList<Program> iris$reloadGeometryShaders() {
ArrayList<Program> programs = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,11 @@ public void finalizeLevelRendering() {
isRenderingFullScreenPass = false;
}

@Override
public void finalizeGameRendering() {

}

@Override
public SodiumTerrainPipeline getSodiumTerrainPipeline() {
return sodiumTerrainPipeline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void finalizeLevelRendering() {
// stub: nothing to do here
}

@Override
public void finalizeGameRendering() {
// stub: nothing to do here
}

@Override
public void destroy() {
// stub: nothing to do here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public interface WorldRenderingPipeline {

void beginTranslucents();
void finalizeLevelRendering();
void finalizeGameRendering();
void destroy();

SodiumTerrainPipeline getSodiumTerrainPipeline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,10 @@ public void finalizeLevelRendering() {
isRenderingWorld = false;
compositeRenderer.renderAll();
finalPassRenderer.renderFinalPass();
}

@Override
public void finalizeGameRendering() {
colorSpaceConverter.process(Minecraft.getInstance().getMainRenderTarget().getColorTextureId());
}

Expand Down
28 changes: 19 additions & 9 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.*;
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.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -73,7 +83,7 @@ public class ShaderPack {
private List<String> dimensionIds;
private Map<NamespacedId, String> dimensionMap;

public ShaderPack(Path root, Iterable<StringPair> environmentDefines) throws IOException, IllegalStateException {
public ShaderPack(Path root, ImmutableList<StringPair> environmentDefines) throws IOException, IllegalStateException {
this(root, Collections.emptyMap(), environmentDefines);
}

Expand All @@ -87,11 +97,13 @@ public ShaderPack(Path root, Iterable<StringPair> environmentDefines) throws IOE
* have completed, and there is no need to hold on to the path for that reason.
* @throws IOException if there are any IO errors during shader pack loading.
*/
public ShaderPack(Path root, Map<String, String> changedConfigs, Iterable<StringPair> environmentDefines) throws IOException, IllegalStateException {
public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<StringPair> environmentDefines) throws IOException, IllegalStateException {
// A null path is not allowed.
Objects.requireNonNull(root);


ArrayList<StringPair> envDefines1 = new ArrayList<>(environmentDefines);
envDefines1.addAll(IrisDefines.createIrisReplacements());
environmentDefines = ImmutableList.copyOf(envDefines1);
ImmutableList.Builder<AbsolutePackPath> starts = ImmutableList.builder();
ImmutableList<String> potentialFileNames = ShaderPackSourceNames.POTENTIAL_STARTS;

Expand Down Expand Up @@ -151,10 +163,9 @@ 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, replacements))
.map(source -> new ShaderProperties(source, shaderPackOptions, finalEnvironmentDefines))
.orElseGet(ShaderProperties::empty);

activeFeatures = new HashSet<>();
Expand Down Expand Up @@ -199,7 +210,7 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, Iterable<String
List<String> optionalFeatureFlags = shaderProperties.getOptionalFeatureFlags().stream().filter(flag -> !FeatureFlags.isInvalid(flag)).collect(Collectors.toList());

if (!optionalFeatureFlags.isEmpty()) {

optionalFeatureFlags.forEach(flag -> Iris.logger.warn("Found flag " + flag));
optionalFeatureFlags.forEach(flag -> newEnvDefines.add(new StringPair("IRIS_FEATURE_" + flag, "")));

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

// Set up our source provider for creating ProgramSets
ArrayList<StringPair> finalEnvironmentDefines1 = new ArrayList<>((Collection) finalEnvironmentDefines);
finalEnvironmentDefines1.addAll(IrisDefines.createIrisReplacements());
Iterable<StringPair> finalEnvironmentDefines1 = environmentDefines;
this.sourceProvider = (path) -> {
String pathString = path.getPathString();
// Removes the first "/" in the path if present, and the file
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import net.coderbot.iris.shaderpack.preprocessor.PropertiesPreprocessor;
import net.coderbot.iris.shaderpack.texture.TextureStage;
import net.coderbot.iris.uniforms.custom.CustomUniforms;
import net.fabricmc.loader.api.FabricLoader;

import java.io.IOException;
import java.io.StringReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
Expand Down Expand Up @@ -111,13 +113,18 @@ 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, Iterable<StringPair> replacements) {
for (StringPair pair : replacements) {
contents = contents.replaceAll("\\b" + pair.getKey() + "\\b", pair.getValue());
}

public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, Iterable<StringPair> environmentDefines) {
String preprocessedContents = PropertiesPreprocessor.preprocessSource(contents, shaderPackOptions, environmentDefines);

if (Iris.getIrisConfig().areDebugOptionsEnabled()) {
try {
Files.writeString(FabricLoader.getInstance().getGameDir().resolve("preprocessed.properties"), preprocessedContents);
Files.writeString(FabricLoader.getInstance().getGameDir().resolve("original.properties"), contents);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Properties preprocessed = new OrderBackedProperties();
Properties original = new OrderBackedProperties();
try {
Expand Down Expand Up @@ -524,10 +531,6 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
customUniforms.addVariable(parts[0], parts[1], value, true);
});


handleWhitespacedListDirective(key, value, "iris.features.required", options -> requiredFeatureFlags = options);
handleWhitespacedListDirective(key, value, "iris.features.optional", options -> optionalFeatureFlags = options);

// TODO: Buffer size directives
// TODO: Conditional program enabling directives
});
Expand All @@ -537,6 +540,9 @@ public ShaderProperties(String contents, ShaderPackOptions shaderPackOptions, It
String key = (String) keyObject;
String value = (String) valueObject;

handleWhitespacedListDirective(key, value, "iris.features.required", options -> requiredFeatureFlags = options);
handleWhitespacedListDirective(key, value, "iris.features.optional", options -> optionalFeatureFlags = options);

// Defining "sliders" multiple times in the properties file will only result in
// the last definition being used, should be tested if behavior matches OptiFine
handleWhitespacedListDirective(key, value, "sliders", sliders -> sliderOptions = sliders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;

Expand All @@ -14,6 +15,7 @@
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;

Expand Down Expand Up @@ -78,19 +80,21 @@ private static String process(Preprocessor preprocessor, String source) {
// 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)
.map(line -> {
if (line.startsWith("#")) {
source = Arrays.stream(source.split("\\R")).map(String::trim)
.map(line -> {
if (line.startsWith("#")) {
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;
} 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;
}
}).collect(Collectors.joining("\n")) + "\n";
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");

Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/colorSpace.csh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ layout(rgba8) uniform image2D readImage;
#else
uniform sampler2D readImage;
in vec2 uv;
out vec3 outColor;
out vec4 outColor;
#endif

// https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
Expand Down Expand Up @@ -107,13 +107,13 @@ void main() {
#if CURRENT_COLOR_SPACE != SRGB
#ifdef COMPUTE
ivec2 PixelIndex = ivec2(gl_GlobalInvocationID.xy);
vec3 SourceColor = imageLoad(readImage, PixelIndex).rgb;
vec4 SourceColor = imageLoad(readImage, PixelIndex);
#else
vec3 SourceColor = texture(readImage, uv).rgb;
vec4 SourceColor = texture(readImage, uv);
#endif
SourceColor = InverseEOTF_IEC61966(SourceColor);
SourceColor.rgb = InverseEOTF_IEC61966(SourceColor.rgb);
vec3 TargetColor = SourceColor;
vec3 TargetColor = SourceColor.rgb;
#if CURRENT_COLOR_SPACE == DCI_P3
// https://en.wikipedia.org/wiki/DCI-P3
Expand All @@ -137,9 +137,9 @@ void main() {
#endif
#ifdef COMPUTE
imageStore(readImage, PixelIndex, vec4(TargetColor, 1.0));
imageStore(readImage, PixelIndex, vec4(TargetColor, SourceColor.a));
#else
outColor = TargetColor;
outColor = vec4(TargetColor, SourceColor.a);
#endif
#endif
}

0 comments on commit 7a24ded

Please sign in to comment.