merge-stonecutter #16

Merged
embeddedt merged 9 commits from mitchej123/celeritas:merge-stonecutter into shader-refactor 2025-07-07 21:28:48 -04:00
12 changed files with 82 additions and 109 deletions
Showing only changes of commit 03081f4a82 - Show all commits

No files matched your search

@@ -47,6 +47,7 @@ import net.irisshaders.iris.targets.RenderTargets;
import net.irisshaders.iris.uniforms.CommonUniforms;
import net.irisshaders.iris.uniforms.FrameUpdateNotifier;
import net.irisshaders.iris.uniforms.custom.CustomUniforms;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.lwjgl.opengl.GL15C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
@@ -307,9 +308,9 @@ public class CompositeRenderer {
// TODO: Properly handle empty shaders
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchComposite(
source.getName(),
source.getVertexSource().orElseThrow(NullPointerException::new),
source.getGeometrySource().orElse(null),
source.getFragmentSource().orElseThrow(NullPointerException::new), textureStage, pipeline.getTextureMap());
source.getSource(ShaderType.VERTEX).orElseThrow(NullPointerException::new),
source.getSource(ShaderType.GEOM).orElse(null),
source.getSource(ShaderType.FRAGMENT).orElseThrow(NullPointerException::new), textureStage, pipeline.getTextureMap());
String vertex = transformed.get(PatchShaderType.VERTEX);
String geometry = transformed.get(PatchShaderType.GEOMETRY);
String fragment = transformed.get(PatchShaderType.FRAGMENT);
@@ -44,6 +44,7 @@ import net.irisshaders.iris.uniforms.CommonUniforms;
import net.irisshaders.iris.uniforms.FrameUpdateNotifier;
import net.irisshaders.iris.uniforms.custom.CustomUniforms;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.*;
@@ -317,11 +318,11 @@ public class FinalPassRenderer {
private Program createProgram(ProgramSource source, ImmutableSet<Integer> flipped, ImmutableSet<Integer> flippedAtLeastOnceSnapshot,
Supplier<ShadowRenderTargets> shadowTargetsSupplier) {
// TODO: Properly handle empty shaders
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchComposite(
source.getName(),
source.getVertexSource().orElseThrow(NullPointerException::new),
source.getGeometrySource().orElse(null),
source.getFragmentSource().orElseThrow(NullPointerException::new), TextureStage.COMPOSITE_AND_FINAL, pipeline.getTextureMap());
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchComposite(
source.getName(),
source.getSource(ShaderType.VERTEX).orElseThrow(NullPointerException::new),
source.getSource(ShaderType.GEOM).orElse(null),
source.getSource(ShaderType.FRAGMENT).orElseThrow(NullPointerException::new), TextureStage.COMPOSITE_AND_FINAL, pipeline.getTextureMap());
String vertex = transformed.get(PatchShaderType.VERTEX);
String geometry = transformed.get(PatchShaderType.GEOMETRY);
String fragment = transformed.get(PatchShaderType.FRAGMENT);
@@ -314,11 +314,11 @@ public class SodiumTerrainPipeline {
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchSodium(
sources.getName(),
sources.getVertexSource().orElse(null),
sources.getGeometrySource().orElse(null),
sources.getTessControlSource().orElse(null),
sources.getTessEvalSource().orElse(null),
sources.getFragmentSource().orElse(null),
sources.getSourceNullable(ShaderType.VERTEX),
sources.getSourceNullable(ShaderType.GEOM),
sources.getSourceNullable(ShaderType.TESS_CTRL),
sources.getSourceNullable(ShaderType.TESS_EVALUATE),
sources.getSourceNullable(ShaderType.FRAGMENT),
passInfo.alphaTest.orElseThrow(), inputs, parent.getTextureMap());
for (var type : PatchShaderType.values()) {
@@ -11,12 +11,9 @@ import net.irisshaders.iris.shaderpack.parsing.DispatchingDirectiveHolder;
import net.irisshaders.iris.shaderpack.properties.PackDirectives;
import net.irisshaders.iris.shaderpack.properties.PackRenderTargetDirectives;
import net.irisshaders.iris.shaderpack.properties.ShaderProperties;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.function.Function;
import static net.irisshaders.iris.IrisLogging.IRIS_LOGGER;
@@ -181,30 +178,27 @@ public class ProgramSet implements ProgramSetInterface {
Function<AbsolutePackPath, String> sourceProvider, String program,
ProgramSet programSet, ShaderProperties properties,
BlendModeOverride defaultBlendModeOverride, boolean readTesselation) {
AbsolutePackPath vertexPath = directory.resolve(program + ".vsh");
String vertexSource = sourceProvider.apply(vertexPath);
Map<ShaderType, String> sources = new EnumMap<>(ShaderType.class);
AbsolutePackPath geometryPath = directory.resolve(program + ".gsh");
String geometrySource = sourceProvider.apply(geometryPath);
for (var shaderType : ShaderType.values()) {
if (shaderType == ShaderType.COMPUTE) {
continue;
}
if (!readTesselation && (shaderType == ShaderType.TESS_CTRL || shaderType == ShaderType.TESS_EVALUATE)) {
continue;
}
String tessControlSource = null;
String tessEvalSource = null;
AbsolutePackPath vertexPath = directory.resolve(program + "." + shaderType.fileExtension);
String source = sourceProvider.apply(vertexPath);
if (source != null) {
sources.put(shaderType, source);
}
}
if (readTesselation) {
AbsolutePackPath tessControlPath = directory.resolve(program + ".tcs");
tessControlSource = sourceProvider.apply(tessControlPath);
AbsolutePackPath tessEvalPath = directory.resolve(program + ".tes");
tessEvalSource = sourceProvider.apply(tessEvalPath);
}
AbsolutePackPath fragmentPath = directory.resolve(program + ".fsh");
String fragmentSource = sourceProvider.apply(fragmentPath);
if (vertexSource == null && fragmentSource != null) {
if (!sources.containsKey(ShaderType.VERTEX) && sources.containsKey(ShaderType.FRAGMENT)) {
// This is for really old packs that do not use a vertex shader.
IRIS_LOGGER.warn("Found a program (" + program + ") that has a fragment shader but no vertex shader? This is very legacy behavior and might not work right.");
vertexSource = """
IRIS_LOGGER.warn("Found a program (" + program + ") that has a fragment shader but no vertex shader? This is very legacy behavior and might not work right.");
sources.put(ShaderType.VERTEX, """
#version 120
varying vec4 irs_texCoords[3];
@@ -217,10 +211,10 @@ public class ProgramSet implements ProgramSetInterface {
irs_texCoords[2] = gl_TextureMatrix[1] * gl_MultiTexCoord2;
irs_Color = gl_Color;
}
""";
""");
}
return new ProgramSource(program, vertexSource, geometrySource, tessControlSource, tessEvalSource, fragmentSource, programSet, properties,
return new ProgramSource(program, sources, programSet, properties,
defaultBlendModeOverride);
}
@@ -357,7 +351,7 @@ public class ProgramSet implements ProgramSetInterface {
continue;
}
source.getFragmentSource().map(ConstDirectiveParser::findDirectives).ifPresent(directives -> {
source.getSource(ShaderType.FRAGMENT).map(ConstDirectiveParser::findDirectives).ifPresent(directives -> {
for (ConstDirectiveParser.ConstDirective directive : directives) {
packDirectiveHolder.processDirective(directive);
}
@@ -4,71 +4,42 @@ import net.irisshaders.iris.gl.blending.BlendModeOverride;
import net.irisshaders.iris.shaderpack.properties.PackRenderTargetDirectives;
import net.irisshaders.iris.shaderpack.properties.ProgramDirectives;
import net.irisshaders.iris.shaderpack.properties.ShaderProperties;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
public class ProgramSource {
private final String name;
private final String vertexSource;
private final String geometrySource;
private final String tessControlSource;
private final String tessEvalSource;
private final String fragmentSource;
private final Map<ShaderType, String> sources = new EnumMap<>(ShaderType.class);
private final ProgramDirectives directives;
private final ProgramSet parent;
private ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource, String tessEvalSource, String fragmentSource,
ProgramDirectives directives, ProgramSet parent) {
this.name = name;
this.vertexSource = vertexSource;
this.geometrySource = geometrySource;
this.tessControlSource = tessControlSource;
this.tessEvalSource = tessEvalSource;
this.fragmentSource = fragmentSource;
this.directives = directives;
this.parent = parent;
}
public ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource, String tessEvalSource, String fragmentSource,
public ProgramSource(String name, Map<ShaderType, String> sources,
ProgramSet parent, ShaderProperties properties, BlendModeOverride defaultBlendModeOverride) {
this.name = name;
this.vertexSource = vertexSource;
this.geometrySource = geometrySource;
this.tessControlSource = tessControlSource;
this.tessEvalSource = tessEvalSource;
this.fragmentSource = fragmentSource;
for (var entry : sources.entrySet()) {
if (entry.getValue() != null) {
this.sources.put(entry.getKey(), entry.getValue());
}
}
this.parent = parent;
this.directives = new ProgramDirectives(this, properties,
PackRenderTargetDirectives.BASELINE_SUPPORTED_RENDER_TARGETS, defaultBlendModeOverride);
}
public ProgramSource withDirectiveOverride(ProgramDirectives overrideDirectives) {
return new ProgramSource(name, vertexSource, geometrySource, tessControlSource, tessEvalSource, fragmentSource, overrideDirectives, parent);
}
public String getName() {
return name;
}
public Optional<String> getVertexSource() {
return Optional.ofNullable(vertexSource);
}
public Optional<String> getSource(ShaderType type) {
return Optional.ofNullable(getSourceNullable(type));
}
public Optional<String> getGeometrySource() {
return Optional.ofNullable(geometrySource);
}
public Optional<String> getTessControlSource() {
return Optional.ofNullable(tessControlSource);
}
public Optional<String> getTessEvalSource() {
return Optional.ofNullable(tessEvalSource);
}
public Optional<String> getFragmentSource() {
return Optional.ofNullable(fragmentSource);
}
public String getSourceNullable(ShaderType type) {
return sources.get(type);
}
public ProgramDirectives getDirectives() {
return this.directives;
@@ -79,7 +50,7 @@ public class ProgramSource {
}
public boolean isValid() {
return vertexSource != null && fragmentSource != null;
return sources.containsKey(ShaderType.VERTEX) && sources.containsKey(ShaderType.FRAGMENT);
}
public Optional<ProgramSource> requireValid() {
@@ -13,6 +13,7 @@ import net.irisshaders.iris.shaderpack.parsing.CommentDirectiveParser;
import net.irisshaders.iris.shaderpack.parsing.ConstDirectiveParser;
import net.irisshaders.iris.shaderpack.parsing.DispatchingDirectiveHolder;
import net.irisshaders.iris.shaderpack.programs.ProgramSource;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -58,8 +59,8 @@ public class ProgramDirectives {
// undefined data to be written to colortex7.
//
// TODO: Figure out how to infer the DRAWBUFFERS directive when it is missing.
Optional<CommentDirective> optionalDrawbuffersDirective = findDrawbuffersDirective(source.getFragmentSource());
Optional<CommentDirective> optionalRendertargetsDirective = findRendertargetsDirective(source.getFragmentSource());
Optional<CommentDirective> optionalDrawbuffersDirective = findDrawbuffersDirective(source.getSource(ShaderType.FRAGMENT));
Optional<CommentDirective> optionalRendertargetsDirective = findRendertargetsDirective(source.getSource(ShaderType.FRAGMENT));
Optional<CommentDirective> optionalCommentDirective = getAppliedDirective(optionalDrawbuffersDirective, optionalRendertargetsDirective);
drawBuffers = optionalCommentDirective.map(commentDirective -> {
@@ -112,7 +113,7 @@ public class ProgramDirectives {
}
});
source.getFragmentSource().map(ConstDirectiveParser::findDirectives).ifPresent(directives -> {
source.getSource(ShaderType.FRAGMENT).map(ConstDirectiveParser::findDirectives).ifPresent(directives -> {
for (ConstDirectiveParser.ConstDirective directive : directives) {
directiveHolder.processDirective(directive);
}
@@ -87,7 +87,7 @@ public abstract class CommonShadowRenderer {
if (shadow != null) {
// Assume that the shader pack is doing voxelization if a geometry shader is detected.
// Also assume voxelization if image load / store is detected.
this.packHasVoxelization = shadow.getGeometrySource().isPresent();
this.packHasVoxelization = shadow.getSource(ShaderType.GEOM).isPresent();
this.packCullingState = shadowDirectives.getCullingState();
} else {
this.packHasVoxelization = false;
@@ -39,6 +39,7 @@ import net.irisshaders.iris.targets.RenderTarget;
import net.irisshaders.iris.uniforms.CommonUniforms;
import net.irisshaders.iris.uniforms.FrameUpdateNotifier;
import net.irisshaders.iris.uniforms.custom.CustomUniforms;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.lwjgl.opengl.GL15C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
@@ -247,9 +248,9 @@ public class ShadowCompositeRenderer {
// TODO: Properly handle empty shaders
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchComposite(
source.getName(),
source.getVertexSource().orElseThrow(NullPointerException::new),
source.getGeometrySource().orElse(null),
source.getFragmentSource().orElseThrow(NullPointerException::new), TextureStage.SHADOWCOMP, pipeline.getTextureMap());
source.getSource(ShaderType.VERTEX).orElseThrow(NullPointerException::new),
source.getSourceNullable(ShaderType.GEOM),
source.getSource(ShaderType.FRAGMENT).orElseThrow(NullPointerException::new), TextureStage.SHADOWCOMP, pipeline.getTextureMap());
String vertex = transformed.get(PatchShaderType.VERTEX);
String geometry = transformed.get(PatchShaderType.GEOMETRY);
String fragment = transformed.get(PatchShaderType.FRAGMENT);
@@ -158,11 +158,11 @@ public class IrisGenericRenderProgram implements IDhApiGenericObjectShaderProgra
public static IrisGenericRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, ModernIrisRenderingPipeline pipeline) {
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchDHGeneric(
name,
source.getVertexSource().orElseThrow(RuntimeException::new),
source.getTessControlSource().orElse(null),
source.getTessEvalSource().orElse(null),
source.getGeometrySource().orElse(null),
source.getFragmentSource().orElseThrow(RuntimeException::new),
source.getSource(ShaderType.VERTEX).orElseThrow(RuntimeException::new),
source.getSource(ShaderType.TESS_CTRL).orElse(null),
source.getSource(ShaderType.TESS_EVALUATE).orElse(null),
source.getSource(ShaderType.GEOM).orElse(null),
source.getSource(ShaderType.FRAGMENT).orElseThrow(RuntimeException::new),
pipeline.getTextureMap());
String vertex = transformed.get(PatchShaderType.VERTEX);
String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
@@ -138,11 +138,11 @@ public class IrisLodRenderProgram {
public static IrisLodRenderProgram createProgram(String name, boolean isShadowPass, boolean translucent, ProgramSource source, CustomUniforms uniforms, ModernIrisRenderingPipeline pipeline) {
Map<PatchShaderType, String> transformed = TransformPatcherBridge.patchDHTerrain(
name,
source.getVertexSource().orElseThrow(RuntimeException::new),
source.getTessControlSource().orElse(null),
source.getTessEvalSource().orElse(null),
source.getGeometrySource().orElse(null),
source.getFragmentSource().orElseThrow(RuntimeException::new),
source.getSource(ShaderType.VERTEX).orElseThrow(RuntimeException::new),
source.getSource(ShaderType.TESS_CTRL).orElse(null),
source.getSource(ShaderType.TESS_EVALUATE).orElse(null),
source.getSource(ShaderType.GEOM).orElse(null),
source.getSource(ShaderType.FRAGMENT).orElseThrow(RuntimeException::new),
pipeline.getTextureMap());
String vertex = transformed.get(PatchShaderType.VERTEX);
String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
@@ -36,6 +36,8 @@ import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceProvider;
import org.apache.commons.io.IOUtils;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.embeddedt.embeddium.impl.util.PlatformUtil;
import org.embeddedt.embeddium.compat.mc.MCVertexFormat;
import org.embeddedt.embeddium.impl.util.ComponentUtil;
@@ -65,11 +67,11 @@ public class ShaderCreator {
return CompletableFuture.supplyAsync(() -> {
return TransformPatcherBridge.patchVanilla(
name,
source.getVertexSource().orElseThrow(RuntimeException::new),
source.getGeometrySource().orElse(null),
source.getTessControlSource().orElse(null),
source.getTessEvalSource().orElse(null),
source.getFragmentSource().orElseThrow(RuntimeException::new),
source.getSource(ShaderType.VERTEX).orElseThrow(RuntimeException::new),
source.getSource(ShaderType.GEOM).orElse(null),
source.getSource(ShaderType.TESS_CTRL).orElse(null),
source.getSource(ShaderType.TESS_EVALUATE).orElse(null),
source.getSource(ShaderType.FRAGMENT).orElseThrow(RuntimeException::new),
alpha, isLines, true, inputs, pipeline.getTextureMap());
}, Util.backgroundExecutor()).thenApplyAsync(transformed -> {
@@ -48,6 +48,8 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import org.embeddedt.embeddium.compat.mc.MCCamera;
import org.embeddedt.embeddium.compat.mc.MCLevelRenderer;
import org.embeddedt.embeddium.impl.gl.debug.GLDebug;
import org.embeddedt.embeddium.impl.gl.shader.ShaderType;
import org.embeddedt.embeddium.impl.render.viewport.ViewportProvider;
import org.embeddedt.embeddium.impl.util.WorldUtil;
import org.embeddedt.embeddium.impl.world.WorldRendererExtended;