Skip to content

Commit

Permalink
Add External Shaderpack support and add cloud/block outline shaders (I…
Browse files Browse the repository at this point in the history
…risShaders#8)

* Initial Commit on Fork

* Add FrameTimeCounter Uniform

* Add a system to define shaders + and add more shader parsing types. Update to 1.16.4

* Fix Perf issues

* Revert to the upstream uniform format

* Revert to upstream terrain shaders

* pull upstream

* Create shader properties and update shaders to use the new program system

* Finish shader loading

* update javadoc and update shaders to use the shaderpack instance

* make sure that crashes dont occur when given a shader that does not exist

* Get rid of old shader system and switch to ShaderPipeline

* Fix most of the pr changes

* Fix most of the pr changes

* restore trailing newline

* restore terrain shaders

* Update ShaderPipeline

* revert to fields

* Update src/main/java/net/coderbot/iris/pipeline/ShaderPipeline.java

Co-authored-by: Walker Knapp <[email protected]>

* Update src/main/java/net/coderbot/iris/pipeline/ShaderPipeline.java

Co-authored-by: Walker Knapp <[email protected]>

* Update src/main/java/net/coderbot/iris/pipeline/ShaderPipeline.java

Co-authored-by: Walker Knapp <[email protected]>

* Update WorldRenderer

* Add blockOutline Shaders

* Update WorldRenderer

* Fix suggested changes

* Fix suggested changes

* Fix suggested changes

Co-authored-by: OverlordsIII <[email protected]>
Co-authored-by: Walker Knapp <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2020
1 parent 43bab15 commit 81cd1d4
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 18 deletions.
35 changes: 21 additions & 14 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
package net.coderbot.iris;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects;

import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.pipeline.ShaderPipeline;
import net.coderbot.iris.shaderpack.ShaderPack;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;

import java.io.IOException;
import java.util.Objects;

@Environment(EnvType.CLIENT)
public class Iris implements ClientModInitializer {
private static ShaderPack internal;
private static ShaderPack currentPack;
private static ShaderPipeline pipeline;

private static IrisConfig irisConfig;
@Override
public void onInitializeClient() {
Path internalShaderpackPath = FabricLoader.getInstance().getModContainer("iris")
.orElseThrow(() -> new RuntimeException("Iris doesn't exist???")).getRootPath();

irisConfig = new IrisConfig();
try {
internal = new ShaderPack(internalShaderpackPath);
irisConfig.createAndLoadProperties();
} catch (IOException e) {
throw new RuntimeException("Failed to load internal shaderpack!", e);
e.printStackTrace();
}
System.out.println("Using shaderpack " + irisConfig.getShaderPackName());
try {
//optifine shaderpacks have all files in the shaders dir while internal iris shaders do not.
currentPack = new ShaderPack(irisConfig.isInternal() ? irisConfig.getShaderPackPath() : irisConfig.getShaderPackPath().resolve("shaders"));
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to load shaderpack \"%s\"!", irisConfig.getShaderPackName()), e);
}
}

public static ShaderPipeline getPipeline() {
if (pipeline == null) {
pipeline = new ShaderPipeline(Objects.requireNonNull(internal));
pipeline = new ShaderPipeline(Objects.requireNonNull(currentPack));
}

return pipeline;
}

public static IrisConfig getIrisConfig() {
return irisConfig;
}
}
111 changes: 111 additions & 0 deletions src/main/java/net/coderbot/iris/config/IrisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package net.coderbot.iris.config;

import net.fabricmc.loader.api.FabricLoader;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

/**
* A class dedicated to storing the config values of shaderpacks. Right now it only stores the path to the current shaderpack
*/
public class IrisConfig {
private Path shaderpath;
private Path propertiesPath;
/**
* Represents if the current loaded shaderpack is in internal one or not
*/
private boolean isInternal = false;

public IrisConfig() {
propertiesPath = FabricLoader.getInstance().getConfigDir().resolve("iris.properties");
try {
Files.createDirectories(FabricLoader.getInstance().getGameDir().resolve("shaderpacks"));
} catch (IOException e) {
e.printStackTrace();
}
this.shaderpath = FabricLoader.getInstance().getGameDir().resolve("shaderpacks").resolve("internal");
}

/**
* Deserializes and serializes the config
* @throws IOException file exceptions
*/
public void createAndLoadProperties() throws IOException {
deserialize();
serialize();
}

/**
* returns the path of the current shaderpack
* @return the path of the shaderpack
*/
public Path getShaderPackPath(){
return shaderpath;
}

/**
* The path of the config file
* @return the path to config file
*/
public Path getPropertiesPath(){
return propertiesPath;
}

/**
* returns whether or not the current shaderpack is internal
* @return if the shaderpack is internal
*/

public boolean isInternal(){
return isInternal;
}

/**
* Returns the name of the shaderpack
* @return shaderpack name. If internal it returns "internal"
*/

public String getShaderPackName(){
if (isInternal){
return "internal";
}
return shaderpath.getFileName().toString();
}

/**
* loads the config file and then populates the string, int, and boolean entries with the parsed entries
* @throws IOException if the file cannot be loaded
*/

public void deserialize() throws IOException {
if (!Files.exists(propertiesPath)){
return;
}
Properties properties = new Properties();
properties.load(Files.newInputStream(propertiesPath));
this.shaderpath = Paths.get(properties.getProperty("shaderpack"));
}

/**
* Serializes the config into a file. Should be called after refreshing the values of entries
* @throws IOException file exceptions
*/

public void serialize() throws IOException {
Properties properties = new Properties();
if (!Files.exists(shaderpath)){
if (!shaderpath.endsWith("internal")) {
System.err.println(String.format("The specified shaderpack \"%s\" was not found! Change the value in iris.properties in your config directory! The system path should be \"%s\"", shaderpath.getFileName(), shaderpath));
System.out.println("falling back to internal shaders...");
}
shaderpath = FabricLoader.getInstance().getModContainer("iris")
.orElseThrow(() -> new RuntimeException("Failed to get the mod container for Iris!")).getRootPath();
isInternal = true;
}
properties.setProperty("shaderpack", shaderpath.toString());
properties.store(Files.newOutputStream(propertiesPath), "This file stores configuration options for Iris, such as the currently active shaderpack");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class MixinImmediateVertexConsumerProvider {
@Inject(method = "draw(Lnet/minecraft/client/render/RenderLayer;)V", at = @At("HEAD"))
private void iris$beginDraw(RenderLayer layer, CallbackInfo callback) {
Iris.getPipeline().beginImmediateDrawing();
Iris.getPipeline().beginImmediateDrawing(layer);
}

@Inject(method = "draw(Lnet/minecraft/client/render/RenderLayer;)V", at = @At("RETURN"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package net.coderbot.iris.mixin;

import net.coderbot.iris.HorizonRenderer;
Expand Down Expand Up @@ -27,8 +28,6 @@ public class MixinWorldRenderer {
private static final String RENDER_SKY = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;F)V";
private static final String RENDER_LAYER = "renderLayer(Lnet/minecraft/client/render/RenderLayer;Lnet/minecraft/client/util/math/MatrixStack;DDD)V";
private static final String RENDER_CLOUDS = "renderClouds(Lnet/minecraft/client/util/math/MatrixStack;FDDD)V";
private static final String POSITIVE_Y = "Lnet/minecraft/client/util/math/Vector3f;POSITIVE_Y:Lnet/minecraft/client/util/math/Vector3f;";
private static final String PEEK = "Lnet/minecraft/client/util/math/MatrixStack;peek()Lnet/minecraft/client/util/math/MatrixStack$Entry;";

@Inject(method = RENDER, at = @At("HEAD"))
private void iris$beginWorldRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo callback) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/coderbot/iris/pipeline/ShaderPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void endWorldBorder() {
GlProgramManager.useProgram(0);
}

public void beginImmediateDrawing() {
public void beginImmediateDrawing(RenderLayer layer) {
if (!isRenderingWorld) {
// don't mess with non-world rendering
return;
Expand All @@ -178,6 +178,9 @@ public void beginImmediateDrawing() {
}

texturedLit.use();
if ((layer.isOutline() || layer == RenderLayer.getLines()) && basic != null){
basic.use();
}
}

public void endImmediateDrawing() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public Optional<ProgramSource> getGbuffersClouds() {
return gbuffersClouds.requireValid();
}


private static ProgramSource readProgramSource(Path root, String program) throws IOException {
String vertexSource = null;
String fragmentSource = null;
Expand Down

0 comments on commit 81cd1d4

Please sign in to comment.