forked from IrisShaders/Iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add External Shaderpack support and add cloud/block outline shaders (I…
…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
1 parent
43bab15
commit 81cd1d4
Showing
6 changed files
with
139 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters