diff --git a/src/main/java/com/gtnewhorizons/angelica/glsm/RenderSystem.java b/src/main/java/com/gtnewhorizons/angelica/glsm/RenderSystem.java index 925b8f70e..f089acff9 100644 --- a/src/main/java/com/gtnewhorizons/angelica/glsm/RenderSystem.java +++ b/src/main/java/com/gtnewhorizons/angelica/glsm/RenderSystem.java @@ -44,6 +44,7 @@ public class RenderSystem { private static boolean supportsSSBO; private static boolean supportsBufferStorage; private static boolean supportsClearTexture; + private static boolean supportsTesselation; private static boolean supportsSamplerObjects; private static int maxImageUnits; private static int maxSSBOBindings; @@ -73,6 +74,7 @@ public class RenderSystem { } supportsCompute = supportsCompute(); + supportsTesselation = GLStateManager.capabilities.GL_ARB_tessellation_shader || GLStateManager.capabilities.OpenGL40; supportsImageLoadStore = GLStateManager.capabilities.OpenGL42 || GLStateManager.capabilities.GL_ARB_shader_image_load_store || GLStateManager.capabilities.GL_EXT_shader_image_load_store; supportsSSBO = GLStateManager.capabilities.OpenGL43 || GLStateManager.capabilities.GL_ARB_shader_storage_buffer_object; @@ -447,6 +449,10 @@ public class RenderSystem { dsaState.textureStorage3D(texture, target, levels, internalFormat, width, height, depth); } + public static boolean supportsTesselation() { + return supportsTesselation; + } + public static boolean supportsSamplerObjects() { return supportsSamplerObjects; } diff --git a/src/main/java/net/coderbot/iris/features/FeatureFlags.java b/src/main/java/net/coderbot/iris/features/FeatureFlags.java index ee13d27bf..b461de997 100644 --- a/src/main/java/net/coderbot/iris/features/FeatureFlags.java +++ b/src/main/java/net/coderbot/iris/features/FeatureFlags.java @@ -15,6 +15,10 @@ public enum FeatureFlags { BLOCK_EMISSION_ATTRIBUTE(() -> true, () -> true), CUSTOM_IMAGES(() -> true, RenderSystem::supportsImageLoadStore), SSBO(() -> true, RenderSystem::supportsSSBO), + HIGHER_SHADOWCOLOR(() -> true, () -> true), + TESSELLATION_SHADERS(() -> true, RenderSystem::supportsTesselation), + REVERSED_CULLING(() -> true, () -> true), + CAN_DISABLE_WEATHER(() -> true, () -> true), UNKNOWN(() -> false, () -> false); private final BooleanSupplier irisRequirement; @@ -55,16 +59,16 @@ public enum FeatureFlags { } public static boolean isInvalid(String name) { - try { - return !FeatureFlags.valueOf(name).isUsable(); - } catch (IllegalArgumentException e) { - return true; - } + FeatureFlags flag = getValue(name); + return flag == UNKNOWN || !flag.isUsable(); } public static FeatureFlags getValue(String value) { + if (value.equalsIgnoreCase("TESSELATION_SHADERS")) { + value = "TESSELLATION_SHADERS"; + } try { - return FeatureFlags.valueOf(value); + return FeatureFlags.valueOf(value.toUpperCase(java.util.Locale.US)); } catch (IllegalArgumentException e) { return FeatureFlags.UNKNOWN; } diff --git a/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java b/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java index 60bb437ae..31c15e456 100644 --- a/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java +++ b/src/main/java/net/coderbot/iris/gl/program/ProgramBuilder.java @@ -34,36 +34,31 @@ public class ProgramBuilder extends ProgramUniforms.Builder implements SamplerHo public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource, @Nullable String fragmentSource, ImmutableSet reservedTextureUnits) { - GlShader vertex; - GlShader geometry; - GlShader fragment; + return begin(name, vertexSource, geometrySource, null, null, fragmentSource, reservedTextureUnits); + } - vertex = buildShader(ShaderType.VERTEX, name + ".vsh", vertexSource); + public static ProgramBuilder begin(String name, @Nullable String vertexSource, @Nullable String geometrySource, + @Nullable String tessControlSource, @Nullable String tessEvalSource, + @Nullable String fragmentSource, ImmutableSet reservedTextureUnits) { + GlShader vertex = buildShader(ShaderType.VERTEX, name + ".vsh", vertexSource); + GlShader geometry = geometrySource != null ? buildShader(ShaderType.GEOMETRY, name + ".gsh", geometrySource) : null; + GlShader tessControl = tessControlSource != null ? buildShader(ShaderType.TESSELATION_CONTROL, name + ".tcs", tessControlSource) : null; + GlShader tessEval = tessEvalSource != null ? buildShader(ShaderType.TESSELATION_EVAL, name + ".tes", tessEvalSource) : null; + GlShader fragment = buildShader(ShaderType.FRAGMENT, name + ".fsh", fragmentSource); - if (geometrySource != null) { - geometry = buildShader(ShaderType.GEOMETRY, name + ".gsh", geometrySource); - } else { - geometry = null; + java.util.List shaders = new java.util.ArrayList<>(); + shaders.add(vertex); + if (geometry != null) shaders.add(geometry); + if (tessControl != null) shaders.add(tessControl); + if (tessEval != null) shaders.add(tessEval); + shaders.add(fragment); + + int programId = ProgramCreator.create(name, shaders.toArray(new GlShader[0])); + + for (GlShader shader : shaders) { + shader.destroy(); } - fragment = buildShader(ShaderType.FRAGMENT, name + ".fsh", fragmentSource); - - int programId; - - if (geometry != null) { - programId = ProgramCreator.create(name, vertex, geometry, fragment); - } else { - programId = ProgramCreator.create(name, vertex, fragment); - } - - vertex.destroy(); - - if (geometry != null) { - geometry.destroy(); - } - - fragment.destroy(); - return new ProgramBuilder(name, programId, reservedTextureUnits); } diff --git a/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java b/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java index 49d621f11..3342617a8 100644 --- a/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java +++ b/src/main/java/net/coderbot/iris/gl/shader/ShaderType.java @@ -4,6 +4,7 @@ package net.coderbot.iris.gl.shader; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL32; +import org.lwjgl.opengl.GL40; import org.lwjgl.opengl.GL43; /** @@ -12,6 +13,8 @@ import org.lwjgl.opengl.GL43; public enum ShaderType { VERTEX(GL20.GL_VERTEX_SHADER), GEOMETRY(GL32.GL_GEOMETRY_SHADER), + TESSELATION_CONTROL(GL40.GL_TESS_CONTROL_SHADER), + TESSELATION_EVAL(GL40.GL_TESS_EVALUATION_SHADER), FRAGMENT(GL20.GL_FRAGMENT_SHADER), COMPUTE(GL43.GL_COMPUTE_SHADER); diff --git a/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java b/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java index a8c175703..8a49d4e84 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java +++ b/src/main/java/net/coderbot/iris/pipeline/ClearPassCreator.java @@ -86,7 +86,7 @@ public class ClearPassCreator { // Sort buffers by their clear color so we can group up glClear calls. Map clearByColor = new HashMap<>(); - for (int i = 0; i < renderTargetDirectives.getColorSamplingSettings().size(); i++) { + for (int i = 0; i < Math.min(renderTargetDirectives.getColorSamplingSettings().size(), renderTargets.getNumColorTextures()); i++) { // unboxed PackShadowDirectives.SamplingSettings settings = renderTargetDirectives.getColorSamplingSettings().get(i); diff --git a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java index 86acb9aaa..444e6c494 100644 --- a/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/DeferredWorldRenderingPipeline.java @@ -165,6 +165,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R private final boolean shouldRenderVignette; private final boolean shouldRenderSun; private final boolean shouldRenderMoon; + private final boolean shouldRenderStars; + private final boolean shouldRenderSkyDisc; + private final boolean shouldRenderWeather; + private final boolean shouldRenderWeatherParticles; private final boolean shouldWriteRainAndSnowToDepthBuffer; private final boolean shouldRenderParticlesBeforeDeferred; private final boolean shouldRenderPrepareBeforeShadow; @@ -217,6 +221,10 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R this.shouldRenderVignette = programs.getPackDirectives().vignette(); this.shouldRenderSun = programs.getPackDirectives().shouldRenderSun(); this.shouldRenderMoon = programs.getPackDirectives().shouldRenderMoon(); + this.shouldRenderStars = programs.getPackDirectives().shouldRenderStars(); + this.shouldRenderSkyDisc = programs.getPackDirectives().shouldRenderSkyDisc(); + this.shouldRenderWeather = programs.getPackDirectives().shouldRenderWeather(); + this.shouldRenderWeatherParticles = programs.getPackDirectives().shouldRenderWeatherParticles(); this.shouldWriteRainAndSnowToDepthBuffer = programs.getPackDirectives().rainDepth(); this.shouldRenderParticlesBeforeDeferred = programs.getPackDirectives().getParticleRenderingSettings() .map(s -> s == net.coderbot.iris.shaderpack.ParticleRenderingSettings.BEFORE || s == net.coderbot.iris.shaderpack.ParticleRenderingSettings.MIXED) @@ -323,7 +331,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R this.shadowTargetsSupplier = () -> { if (shadowRenderTargets == null) { - this.shadowRenderTargets = new ShadowRenderTargets(shadowMapResolution, shadowDirectives); + this.shadowRenderTargets = new ShadowRenderTargets(this, shadowMapResolution, shadowDirectives); } return shadowRenderTargets; @@ -440,7 +448,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R }); }); if (shadowRenderTargets == null && shadowDirectives.isShadowEnabled() == OptionalBoolean.TRUE) { - shadowRenderTargets = new ShadowRenderTargets(shadowMapResolution, shadowDirectives); + shadowRenderTargets = new ShadowRenderTargets(this, shadowMapResolution, shadowDirectives); } if (shadowRenderTargets != null) { @@ -631,6 +639,26 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R return shouldRenderMoon; } + @Override + public boolean shouldRenderStars() { + return shouldRenderStars; + } + + @Override + public boolean shouldRenderSkyDisc() { + return shouldRenderSkyDisc; + } + + @Override + public boolean shouldRenderWeather() { + return shouldRenderWeather; + } + + @Override + public boolean shouldRenderWeatherParticles() { + return shouldRenderWeatherParticles; + } + @Override public boolean shouldWriteRainAndSnowToDepthBuffer() { return shouldWriteRainAndSnowToDepthBuffer; @@ -759,17 +787,21 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R transformed = TransformPatcher.patchAttributes( source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), + source.getTessControlSource().orElse(null), + source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new), availability); } String vertex = transformed.get(PatchShaderType.VERTEX); String geometry = transformed.get(PatchShaderType.GEOMETRY); + String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); + String tessEval = transformed.get(PatchShaderType.TESS_EVAL); String fragment = transformed.get(PatchShaderType.FRAGMENT); - PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment); + PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment); - ProgramBuilder builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment, + ProgramBuilder builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment, IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS); return createPassInner(builder, source.getDirectives(), availability, shadow, id); @@ -1559,7 +1591,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R private static final InputAvailability[] INPUT_AVAILABILITIES = { INPUT_NONE, INPUT_TEXTURE, INPUT_TEXTURE_LIGHTMAP }; private static CompletableFuture> submitCompositeTransform(ProgramSource source) { - return Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchComposite(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getFragmentSource().orElse(null))); + return Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchComposite(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null))); } private static Map>> submitCompositeTransforms(ProgramSource[] sources) { @@ -1587,7 +1619,7 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R processedSourceNames.add(source.getName()); for (InputAvailability avail : INPUT_AVAILABILITIES) { Pair key = Pair.of(source.getName(), avail); - futures.put(key, Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchAttributes(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getFragmentSource().orElse(null), avail))); + futures.put(key, Iris.ShaderTransformExecutor.submitTracked(() -> TransformPatcher.patchAttributes(source.getVertexSource().orElse(null), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null), avail))); } } } diff --git a/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java index 008b27b76..3dece81cf 100644 --- a/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/FixedFunctionWorldRenderingPipeline.java @@ -172,6 +172,26 @@ public class FixedFunctionWorldRenderingPipeline implements WorldRenderingPipeli return true; } + @Override + public boolean shouldRenderStars() { + return true; + } + + @Override + public boolean shouldRenderSkyDisc() { + return true; + } + + @Override + public boolean shouldRenderWeather() { + return true; + } + + @Override + public boolean shouldRenderWeatherParticles() { + return true; + } + @Override public boolean shouldWriteRainAndSnowToDepthBuffer() { return false; diff --git a/src/main/java/net/coderbot/iris/pipeline/PatchedShaderPrinter.java b/src/main/java/net/coderbot/iris/pipeline/PatchedShaderPrinter.java index cae503e8e..c6c8ffc1f 100644 --- a/src/main/java/net/coderbot/iris/pipeline/PatchedShaderPrinter.java +++ b/src/main/java/net/coderbot/iris/pipeline/PatchedShaderPrinter.java @@ -27,10 +27,18 @@ public class PatchedShaderPrinter { } public static void debugPatchedShaders(String name, String vertex, String geometry, String fragment) { - debugPatchedShaders(name, vertex, geometry, fragment, null); + debugPatchedShaders(name, vertex, geometry, null, null, fragment, null); + } + + public static void debugPatchedShaders(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment) { + debugPatchedShaders(name, vertex, geometry, tessControl, tessEval, fragment, null); } public static void debugPatchedShaders(String name, String vertex, String geometry, String fragment, String compute) { + debugPatchedShaders(name, vertex, geometry, null, null, fragment, compute); + } + + public static void debugPatchedShaders(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, String compute) { if (prettyPrintShaders) { final Path debugOutDir = Minecraft.getMinecraft().mcDataDir.toPath().resolve("patched_shaders"); if (!outputLocationCleared) { @@ -63,6 +71,12 @@ public class PatchedShaderPrinter { if (geometry != null) { Files.write(debugOutDir.resolve(prefix + name + ".gsh"), geometry.getBytes(StandardCharsets.UTF_8)); } + if (tessControl != null) { + Files.write(debugOutDir.resolve(prefix + name + ".tcs"), tessControl.getBytes(StandardCharsets.UTF_8)); + } + if (tessEval != null) { + Files.write(debugOutDir.resolve(prefix + name + ".tes"), tessEval.getBytes(StandardCharsets.UTF_8)); + } if (fragment != null) { Files.write(debugOutDir.resolve(prefix + name + ".fsh"), fragment.getBytes(StandardCharsets.UTF_8)); } diff --git a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java index 4c6c6b72d..c270a1172 100644 --- a/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java +++ b/src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java @@ -29,6 +29,7 @@ import net.coderbot.iris.shadows.frustum.BoxCuller; import net.coderbot.iris.shadows.frustum.CullEverythingFrustum; import net.coderbot.iris.shadows.frustum.FrustumHolder; import net.coderbot.iris.shadows.frustum.advanced.AdvancedShadowCullingFrustum; +import net.coderbot.iris.shadows.frustum.advanced.SafeZoneCullingFrustum; import net.coderbot.iris.shadows.frustum.fallback.BoxCullingFrustum; import net.coderbot.iris.shadows.frustum.fallback.NonCullingFrustum; import net.coderbot.iris.uniforms.CameraUniforms; @@ -73,6 +74,7 @@ public class ShadowRenderer { public static ShadowRenderTargets CURRENT_TARGETS = null; private final float halfPlaneLength; + private final float voxelDistance; private final float renderDistanceMultiplier; private final float entityShadowDistanceMultiplier; private final int resolution; @@ -117,6 +119,7 @@ public class ShadowRenderer { final PackShadowDirectives shadowDirectives = directives.getShadowDirectives(); this.halfPlaneLength = shadowDirectives.getDistance(); + this.voxelDistance = shadowDirectives.getVoxelDistance(); this.renderDistanceMultiplier = shadowDirectives.getDistanceRenderMul(); this.entityShadowDistanceMultiplier = shadowDirectives.getEntityShadowDistanceMul(); this.resolution = shadowDirectives.getResolution(); @@ -225,7 +228,8 @@ public class ShadowRenderer { configureDepthSampler(targets.getDepthTextureNoTranslucents().getTextureId(), depthSamplingSettings.get(1)); - for (int i = 0; i < colorSamplingSettings.size(); i++) { + for (int i = 0; i < Math.min(colorSamplingSettings.size(), targets.getNumColorTextures()); i++) { + if (targets.get(i) == null) continue; int glTextureId = targets.get(i).getMainTexture(); configureSampler(glTextureId, colorSamplingSettings.get(i)); @@ -286,7 +290,7 @@ public class ShadowRenderer { // TODO: Cull entities / block entities with Advanced Frustum Culling even if voxelization is detected. String distanceInfo; String cullingInfo; - if ((packCullingState == ShadowCullState.DISTANCE || packHasVoxelization) && packCullingState != ShadowCullState.ADVANCED) { + if ((packCullingState == ShadowCullState.DISTANCE || packHasVoxelization) && packCullingState != ShadowCullState.ADVANCED && packCullingState != ShadowCullState.SAFE_ZONE) { double distance = halfPlaneLength * renderMultiplier; String reason; @@ -308,26 +312,29 @@ public class ShadowRenderer { holder.setInfo(getOrCreateBoxCullingFrustum(distance), distanceInfo, cullingInfo); } } else { - final BoxCuller boxCuller; + BoxCuller boxCuller; - double distance = halfPlaneLength * renderMultiplier; + boolean hasSafeZone = packCullingState == ShadowCullState.SAFE_ZONE; + + if (hasSafeZone && renderMultiplier < 0) renderMultiplier = 1.0f; + + double distance = (hasSafeZone ? voxelDistance : halfPlaneLength) * renderMultiplier; String setter = "(set by shader pack)"; if (renderMultiplier < 0) { // TODO: GUI distance = IrisVideoSettings.shadowDistance * 16; // can be zero :( - //distance = 32 * 16; setter = "(set by user)"; } - if (distance >= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) { + if (distance >= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 && !hasSafeZone) { distanceInfo = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 + " blocks (capped by normal render distance)"; boxCuller = null; } else { distanceInfo = distance + " blocks " + setter; - if (distance == 0.0) { + if (distance == 0.0 && !hasSafeZone) { cullingInfo = "no shadows rendered"; return holder.setInfo(CULL_EVERYTHING_FRUSTUM, distanceInfo, cullingInfo); } @@ -335,15 +342,22 @@ public class ShadowRenderer { boxCuller = getOrCreateAdvancedBoxCuller(distance); } - cullingInfo = "Advanced Frustum Culling enabled"; + cullingInfo = (hasSafeZone ? "Safe Zone" : "Advanced") + " Frustum Culling enabled"; final Vector4f shadowLightPosition = celestialUniforms.getShadowLightPositionInWorldSpace(); shadowLightVectorCache.set(shadowLightPosition.x(), shadowLightPosition.y(), shadowLightPosition.z()); shadowLightVectorCache.normalize(); - cachedAdvancedFrustum.init(RenderingState.INSTANCE.getModelViewMatrix(), RenderingState.INSTANCE.getProjectionMatrix(), shadowLightVectorCache, boxCuller); - return holder.setInfo(cachedAdvancedFrustum, distanceInfo, cullingInfo); - + if (hasSafeZone) { + BoxCuller distanceCuller = new BoxCuller(halfPlaneLength * renderMultiplier); + SafeZoneCullingFrustum safeZoneFrustum = new SafeZoneCullingFrustum( + RenderingState.INSTANCE.getModelViewMatrix(), RenderingState.INSTANCE.getProjectionMatrix(), + shadowLightVectorCache, boxCuller, distanceCuller); + return holder.setInfo(safeZoneFrustum, distanceInfo, cullingInfo); + } else { + cachedAdvancedFrustum.init(RenderingState.INSTANCE.getModelViewMatrix(), RenderingState.INSTANCE.getProjectionMatrix(), shadowLightVectorCache, boxCuller); + return holder.setInfo(cachedAdvancedFrustum, distanceInfo, cullingInfo); + } } return holder; diff --git a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java index 6957d9214..61f544c84 100644 --- a/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/WorldRenderingPipeline.java @@ -54,6 +54,10 @@ public interface WorldRenderingPipeline { boolean shouldRenderVignette(); boolean shouldRenderSun(); boolean shouldRenderMoon(); + boolean shouldRenderStars(); + boolean shouldRenderSkyDisc(); + boolean shouldRenderWeather(); + boolean shouldRenderWeatherParticles(); boolean shouldWriteRainAndSnowToDepthBuffer(); boolean shouldRenderParticlesBeforeDeferred(); boolean allowConcurrentCompute(); diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java b/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java index 7137192fe..e2af97691 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/PatchShaderType.java @@ -5,6 +5,8 @@ import net.coderbot.iris.gl.shader.ShaderType; public enum PatchShaderType { VERTEX(ShaderType.VERTEX), GEOMETRY(ShaderType.GEOMETRY), + TESS_CONTROL(ShaderType.TESSELATION_CONTROL), + TESS_EVAL(ShaderType.TESSELATION_EVAL), FRAGMENT(ShaderType.FRAGMENT), COMPUTE(ShaderType.COMPUTE); @@ -20,6 +22,8 @@ public enum PatchShaderType { return switch (glShaderType) { case VERTEX -> new PatchShaderType[] { VERTEX }; case GEOMETRY -> new PatchShaderType[] { GEOMETRY }; + case TESSELATION_CONTROL -> new PatchShaderType[] { TESS_CONTROL }; + case TESSELATION_EVAL -> new PatchShaderType[] { TESS_EVAL }; case FRAGMENT -> new PatchShaderType[] { FRAGMENT }; case COMPUTE -> new PatchShaderType[] { COMPUTE }; }; diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java index f3b999116..855212ec4 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java @@ -160,8 +160,8 @@ public class ShaderTransformer { } } - public static

Map transform(String vertex, String geometry, String fragment, P parameters) { - if (vertex == null && geometry == null && fragment == null) { + public static

Map transform(String vertex, String geometry, String tessControl, String tessEval, String fragment, P parameters) { + if (vertex == null && geometry == null && tessControl == null && tessEval == null && fragment == null) { return null; } else { Map result; @@ -171,6 +171,8 @@ public class ShaderTransformer { EnumMap inputs = new EnumMap<>(PatchShaderType.class); inputs.put(PatchShaderType.VERTEX, vertex); inputs.put(PatchShaderType.GEOMETRY, geometry); + inputs.put(PatchShaderType.TESS_CONTROL, tessControl); + inputs.put(PatchShaderType.TESS_EVAL, tessEval); inputs.put(PatchShaderType.FRAGMENT, fragment); var key = new TransformKey<>(patchType, inputs, parameters); diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java index 1e3005d4c..5b8446c5f 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java @@ -30,12 +30,16 @@ public class TransformPatcher { final Parameters parameters; final String vertex; final String geometry; + final String tessControl; + final String tessEval; final String fragment; - public CacheKey(Parameters parameters, String vertex, String geometry, String fragment) { + public CacheKey(Parameters parameters, String vertex, String geometry, String tessControl, String tessEval, String fragment) { this.parameters = parameters; this.vertex = vertex; this.geometry = geometry; + this.tessControl = tessControl; + this.tessEval = tessEval; this.fragment = fragment; } @@ -45,6 +49,8 @@ public class TransformPatcher { int result = 1; result = prime * result + ((fragment == null) ? 0 : fragment.hashCode()); result = prime * result + ((geometry == null) ? 0 : geometry.hashCode()); + result = prime * result + ((tessControl == null) ? 0 : tessControl.hashCode()); + result = prime * result + ((tessEval == null) ? 0 : tessEval.hashCode()); result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); result = prime * result + ((vertex == null) ? 0 : vertex.hashCode()); return result; @@ -52,39 +58,20 @@ public class TransformPatcher { @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; final TransformPatcher.CacheKey other = (TransformPatcher.CacheKey) obj; - if (fragment == null) { - if (other.fragment != null) - return false; - } else if (!fragment.equals(other.fragment)) - return false; - if (geometry == null) { - if (other.geometry != null) - return false; - } else if (!geometry.equals(other.geometry)) - return false; - if (parameters == null) { - if (other.parameters != null) - return false; - } else if (!parameters.equals(other.parameters)) - return false; - if (vertex == null) { - if (other.vertex != null) - return false; - } else if (!vertex.equals(other.vertex)) - return false; - return true; + return java.util.Objects.equals(fragment, other.fragment) + && java.util.Objects.equals(geometry, other.geometry) + && java.util.Objects.equals(tessControl, other.tessControl) + && java.util.Objects.equals(tessEval, other.tessEval) + && java.util.Objects.equals(parameters, other.parameters) + && java.util.Objects.equals(vertex, other.vertex); } } - private static Map transform(String vertex, String geometry, String fragment, Parameters parameters) { - if (vertex == null && geometry == null && fragment == null) { + private static Map transform(String vertex, String geometry, String tessControl, String tessEval, String fragment, Parameters parameters) { + if (vertex == null && geometry == null && tessControl == null && tessEval == null && fragment == null) { return null; } @@ -92,7 +79,7 @@ public class TransformPatcher { TransformPatcher.CacheKey key = null; Map result = null; if (useCache) { - key = new TransformPatcher.CacheKey(parameters, vertex, geometry, fragment); + key = new TransformPatcher.CacheKey(parameters, vertex, geometry, tessControl, tessEval, fragment); synchronized (cache) { result = cache.get(key); } @@ -100,7 +87,7 @@ public class TransformPatcher { // if there is no cache result, transform the shaders if (result == null) { - result = ShaderTransformer.transform(vertex, geometry, fragment, parameters); + result = ShaderTransformer.transform(vertex, geometry, tessControl, tessEval, fragment, parameters); if (useCache) { synchronized (cache) { // Double-check in case another thread added it while we were transforming @@ -116,20 +103,32 @@ public class TransformPatcher { return result; } + public static Map patchAttributes(String vertex, String geometry, String tessControl, String tessEval, String fragment, InputAvailability inputs) { + return transform(vertex, geometry, tessControl, tessEval, fragment, new AttributeParameters(Patch.ATTRIBUTES, geometry != null, inputs)); + } + public static Map patchAttributes(String vertex, String geometry, String fragment, InputAvailability inputs) { - return transform(vertex, geometry, fragment, new AttributeParameters(Patch.ATTRIBUTES, geometry != null, inputs)); + return patchAttributes(vertex, geometry, null, null, fragment, inputs); } public static Map patchCeleritasTerrain(String vertex, String geometry, String fragment) { - return transform(vertex, geometry, fragment, new CeleritasTerrainParameters(Patch.CELERITAS_TERRAIN)); + return transform(vertex, geometry, null, null, fragment, new CeleritasTerrainParameters(Patch.CELERITAS_TERRAIN)); } public static Map patchComposite(String vertex, String geometry, String fragment) { - return patchComposite(vertex, geometry, fragment, TextureStage.COMPOSITE_AND_FINAL, null); + return patchComposite(vertex, geometry, null, null, fragment, TextureStage.COMPOSITE_AND_FINAL, null); + } + + public static Map patchComposite(String vertex, String geometry, String tessControl, String tessEval, String fragment) { + return patchComposite(vertex, geometry, tessControl, tessEval, fragment, TextureStage.COMPOSITE_AND_FINAL, null); + } + + public static Map patchComposite(String vertex, String geometry, String tessControl, String tessEval, String fragment, TextureStage stage, Object2ObjectMap, String> textureMap) { + return transform(vertex, geometry, tessControl, tessEval, fragment, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap)); } public static Map patchComposite(String vertex, String geometry, String fragment, TextureStage stage, Object2ObjectMap, String> textureMap) { - return transform(vertex, geometry, fragment, new TextureStageParameters(Patch.COMPOSITE, stage, textureMap)); + return patchComposite(vertex, geometry, null, null, fragment, stage, textureMap); } public static String patchCompute(String name, String compute, TextureStage stage, Object2ObjectMap, String> textureMap) { diff --git a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java index 096ff48ea..06f8fbb72 100644 --- a/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/CompositeRenderer.java @@ -189,7 +189,7 @@ public class CompositeRenderer { } // Fallback: transform synchronously - return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new), this.textureStage, pipeline != null ? pipeline.getTextureMap() : null); + return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new), this.textureStage, pipeline != null ? pipeline.getTextureMap() : null); } public void recalculateSizes() { @@ -345,14 +345,16 @@ public class CompositeRenderer { Supplier shadowTargetsSupplier) { String vertex = transformed.get(PatchShaderType.VERTEX); String geometry = transformed.get(PatchShaderType.GEOMETRY); + String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); + String tessEval = transformed.get(PatchShaderType.TESS_EVAL); String fragment = transformed.get(PatchShaderType.FRAGMENT); - PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment); + PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment); Objects.requireNonNull(flipped); ProgramBuilder builder; try { - builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment, + builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS); } catch (RuntimeException e) { // TODO: Better error handling diff --git a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java index 2d4ab044d..5ef6f1463 100644 --- a/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java +++ b/src/main/java/net/coderbot/iris/postprocess/FinalPassRenderer.java @@ -159,7 +159,7 @@ public class FinalPassRenderer { throw new RuntimeException("Shader transformation failed for '" + source.getName() + "' in stage '" + stageName + "'", e.getCause() != null ? e.getCause() : e); } } - return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new)); + return TransformPatcher.patchComposite(source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new)); } private static final class Pass { @@ -353,14 +353,16 @@ public class FinalPassRenderer { Supplier shadowTargetsSupplier) { final String vertex = transformed.get(PatchShaderType.VERTEX); final String geometry = transformed.get(PatchShaderType.GEOMETRY); + final String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); + final String tessEval = transformed.get(PatchShaderType.TESS_EVAL); final String fragment = transformed.get(PatchShaderType.FRAGMENT); - PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment); + PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment); Objects.requireNonNull(flipped); final ProgramBuilder builder; try { - builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment, + builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS); } catch (RuntimeException e) { // TODO: Better error handling diff --git a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java index ff1909037..d990fb794 100644 --- a/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java +++ b/src/main/java/net/coderbot/iris/samplers/IrisSamplers.java @@ -106,7 +106,7 @@ public class IrisSamplers { final ImmutableList.Builder shadowSamplers = ImmutableList.builder() .add("shadowtex0", "shadowtex0HW", "shadowtex0DH", "shadowtex1", "shadowtex1HW", "shadowtex1DH", "shadow", "watershadow", "shadowcolor"); - for (int i = 0; i < PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS; i++) { + for (int i = 0; i < PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS_IRIS; i++) { shadowSamplers.add("shadowcolor" + i); shadowSamplers.add("shadowcolorimg" + i); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java b/src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java index c86f59572..763f27d93 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java +++ b/src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java @@ -33,6 +33,10 @@ public class PackDirectives { private boolean vignette; private boolean sun; private boolean moon; + private boolean stars; + private boolean sky; + private boolean weather; + private boolean weatherParticles; private boolean rainDepth; private boolean separateAo; private boolean voxelizeLightBlocks; @@ -76,6 +80,10 @@ public class PackDirectives { vignette = properties.getVignette().orElse(false); sun = properties.getSun().orElse(true); moon = properties.getMoon().orElse(true); + stars = properties.getStars().orElse(true); + sky = properties.getSky().orElse(true); + weather = properties.getWeather().orElse(true); + weatherParticles = properties.getWeatherParticles().orElse(true); rainDepth = properties.getRainDepth().orElse(false); separateAo = properties.getSeparateAo().orElse(false); voxelizeLightBlocks = properties.getVoxelizeLightBlocks().orElse(false); @@ -129,6 +137,22 @@ public class PackDirectives { return moon; } + public boolean shouldRenderStars() { + return stars; + } + + public boolean shouldRenderSkyDisc() { + return sky; + } + + public boolean shouldRenderWeather() { + return weather; + } + + public boolean shouldRenderWeatherParticles() { + return weatherParticles; + } + public boolean rainDepth() { return rainDepth; } diff --git a/src/main/java/net/coderbot/iris/shaderpack/PackShadowDirectives.java b/src/main/java/net/coderbot/iris/shaderpack/PackShadowDirectives.java index c77f290ba..4d32029a3 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/PackShadowDirectives.java +++ b/src/main/java/net/coderbot/iris/shaderpack/PackShadowDirectives.java @@ -9,10 +9,8 @@ import org.joml.Vector4f; import java.util.Optional; public class PackShadowDirectives { - // Bump this up if you want more shadow color buffers! - // This is currently set at 2 for ShadersMod / OptiFine parity but can theoretically be bumped up to 8. - // TODO: Make this configurable? - public static final int MAX_SHADOW_COLOR_BUFFERS = 2; + public static final int MAX_SHADOW_COLOR_BUFFERS_IRIS = 8; + public static final int MAX_SHADOW_COLOR_BUFFERS_OF = 2; private final OptionalBoolean shadowEnabled; @@ -20,6 +18,7 @@ public class PackShadowDirectives { // Use a boxed form so we can use null to indicate that there is not an FOV specified. private Float fov; private float distance; + private float voxelDistance; private float distanceRenderMul; private float entityShadowDistanceMul; private boolean explicitRenderDistance; @@ -54,6 +53,7 @@ public class PackShadowDirectives { // shadowRenderDistanceMul to a nonzero value, since having a high shadow render distance will impact // performance quite heavily on most systems. this.distance = 160.0f; + this.voxelDistance = 0.0f; // By default, shadows are not culled based on distance from the player. However, pack authors may // enable this by setting shadowRenderDistanceMul to a nonzero value. @@ -86,7 +86,7 @@ public class PackShadowDirectives { ImmutableList.Builder colorSamplingSettings = ImmutableList.builder(); - for (int i = 0; i < MAX_SHADOW_COLOR_BUFFERS; i++) { + for (int i = 0; i < MAX_SHADOW_COLOR_BUFFERS_IRIS; i++) { colorSamplingSettings.add(new SamplingSettings()); } @@ -97,6 +97,7 @@ public class PackShadowDirectives { this.resolution = shadowDirectives.resolution; this.fov = shadowDirectives.fov; this.distance = shadowDirectives.distance; + this.voxelDistance = shadowDirectives.voxelDistance; this.distanceRenderMul = shadowDirectives.distanceRenderMul; this.entityShadowDistanceMul = shadowDirectives.entityShadowDistanceMul; this.explicitRenderDistance = shadowDirectives.explicitRenderDistance; @@ -124,6 +125,10 @@ public class PackShadowDirectives { return distance; } + public float getVoxelDistance() { + return voxelDistance; + } + public float getDistanceRenderMul() { return distanceRenderMul; } @@ -192,6 +197,8 @@ public class PackShadowDirectives { directives.acceptConstFloatDirective("shadowIntervalSize", intervalSize -> this.intervalSize = intervalSize); + directives.acceptConstFloatDirective("voxelDistance", distance -> this.voxelDistance = distance); + acceptHardwareFilteringSettings(directives, depthSamplingSettings); acceptDepthMipmapSettings(directives, depthSamplingSettings); acceptColorMipmapSettings(directives, colorSamplingSettings); diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java index cf1c6e8c2..5313faf1e 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramSet.java @@ -477,11 +477,21 @@ public class ProgramSet { AbsolutePackPath geometryPath = directory.resolve(program + ".gsh"); String geometrySource = sourceProvider.apply(geometryPath); + String tessControlSource = null; + String tessEvalSource = null; + if (programSet.pack.hasFeature(net.coderbot.iris.features.FeatureFlags.TESSELLATION_SHADERS)) { + 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); - return new ProgramSource(program, vertexSource, geometrySource, fragmentSource, programSet, properties, - defaultBlendModeOverride); + return new ProgramSource(program, vertexSource, geometrySource, tessControlSource, tessEvalSource, + fragmentSource, programSet, properties, defaultBlendModeOverride); } private static ComputeSource readComputeSource(AbsolutePackPath directory, diff --git a/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java b/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java index 9ef8500a7..cdf3f3999 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ProgramSource.java @@ -8,25 +8,33 @@ 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 ProgramDirectives directives; private final ProgramSet parent; - private ProgramSource(String name, String vertexSource, String geometrySource, String fragmentSource, + 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 fragmentSource, + public ProgramSource(String name, String vertexSource, String geometrySource, String tessControlSource, + String tessEvalSource, String fragmentSource, ProgramSet parent, ShaderProperties properties, BlendModeOverride defaultBlendModeOverride) { this.name = name; this.vertexSource = vertexSource; this.geometrySource = geometrySource; + this.tessControlSource = tessControlSource; + this.tessEvalSource = tessEvalSource; this.fragmentSource = fragmentSource; this.parent = parent; this.directives = new ProgramDirectives(this, properties, @@ -34,7 +42,7 @@ public class ProgramSource { } public ProgramSource withDirectiveOverride(ProgramDirectives overrideDirectives) { - return new ProgramSource(name, vertexSource, geometrySource, fragmentSource, overrideDirectives, parent); + return new ProgramSource(name, vertexSource, geometrySource, tessControlSource, tessEvalSource, fragmentSource, overrideDirectives, parent); } public String getName() { @@ -49,6 +57,14 @@ public class ProgramSource { return Optional.ofNullable(geometrySource); } + public Optional getTessControlSource() { + return Optional.ofNullable(tessControlSource); + } + + public Optional getTessEvalSource() { + return Optional.ofNullable(tessEvalSource); + } + public Optional getFragmentSource() { return Optional.ofNullable(fragmentSource); } diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java index 53cbf0c6a..0011ffcdf 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java @@ -216,6 +216,9 @@ public class ShaderPack { Iris.logger.info("FeatureFlag {} usable: {}", flag.name(), usable); if (usable) { finalEnvironmentDefines.add(new StringPair("IRIS_FEATURE_" + flag.name(), "")); + if (flag == FeatureFlags.TESSELLATION_SHADERS) { + finalEnvironmentDefines.add(new StringPair("IRIS_FEATURE_TESSELATION_SHADERS", "")); + } } } Iris.logger.info("Environment defines: {}", finalEnvironmentDefines.stream() diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java index 45c43fd08..995838ebe 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShaderProperties.java @@ -73,6 +73,10 @@ public class ShaderProperties { @Getter private OptionalBoolean underwaterOverlay = OptionalBoolean.DEFAULT; @Getter private OptionalBoolean sun = OptionalBoolean.DEFAULT; @Getter private OptionalBoolean moon = OptionalBoolean.DEFAULT; + @Getter private OptionalBoolean stars = OptionalBoolean.DEFAULT; + @Getter private OptionalBoolean sky = OptionalBoolean.DEFAULT; + @Getter private OptionalBoolean weather = OptionalBoolean.DEFAULT; + @Getter private OptionalBoolean weatherParticles = OptionalBoolean.DEFAULT; @Getter private OptionalBoolean vignette = OptionalBoolean.DEFAULT; @Getter private OptionalBoolean backFaceSolid = OptionalBoolean.DEFAULT; @Getter private OptionalBoolean backFaceCutout = OptionalBoolean.DEFAULT; @@ -184,8 +188,8 @@ public class ShaderProperties { shadowCulling = ShadowCullState.DISTANCE; } else if ("true".equals(value)) { shadowCulling = ShadowCullState.ADVANCED; - } else if ("reversed".equals(value)) { - shadowCulling = ShadowCullState.REVERSED; + } else if ("reversed".equals(value) || "safe_zone".equals(value)) { + shadowCulling = ShadowCullState.SAFE_ZONE; } else { Iris.logger.error("Unrecognized shadow culling setting: " + value); } @@ -203,6 +207,8 @@ public class ShaderProperties { handleBooleanDirective(key, value, "underwaterOverlay", bool -> underwaterOverlay = bool); handleBooleanDirective(key, value, "sun", bool -> sun = bool); handleBooleanDirective(key, value, "moon", bool -> moon = bool); + handleBooleanDirective(key, value, "stars", bool -> stars = bool); + handleBooleanDirective(key, value, "sky", bool -> sky = bool); handleBooleanDirective(key, value, "vignette", bool -> vignette = bool); handleBooleanDirective(key, value, "backFace.solid", bool -> backFaceSolid = bool); handleBooleanDirective(key, value, "backFace.cutout", bool -> backFaceCutout = bool); @@ -227,6 +233,14 @@ public class ShaderProperties { handleBooleanDirective(key, value, "supportsColorCorrection", bool -> supportsColorCorrection = bool); handleIntDirective(key, value, "fallbackTex", val -> fallbackTex = val); + if ("weather".equals(key)) { + String[] parts = value.split(" "); + weather = parts[0].equals("true") ? OptionalBoolean.TRUE : OptionalBoolean.FALSE; + if (parts.length > 1) { + weatherParticles = parts[1].equals("true") ? OptionalBoolean.TRUE : OptionalBoolean.FALSE; + } + } + if (key.startsWith("particles.ordering")) { Optional settings = ParticleRenderingSettings.fromString(value.trim().toUpperCase(Locale.ROOT)); if (settings.isPresent()) { diff --git a/src/main/java/net/coderbot/iris/shaderpack/ShadowCullState.java b/src/main/java/net/coderbot/iris/shaderpack/ShadowCullState.java index d407e1c62..80607b34b 100644 --- a/src/main/java/net/coderbot/iris/shaderpack/ShadowCullState.java +++ b/src/main/java/net/coderbot/iris/shaderpack/ShadowCullState.java @@ -3,6 +3,6 @@ package net.coderbot.iris.shaderpack; public enum ShadowCullState { DEFAULT, ADVANCED, - REVERSED, + SAFE_ZONE, DISTANCE } diff --git a/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java b/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java index 2a299e6df..42ab8fa80 100644 --- a/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java +++ b/src/main/java/net/coderbot/iris/shadows/ShadowCompositeRenderer.java @@ -261,17 +261,21 @@ public class ShadowCompositeRenderer { Map transformed = TransformPatcher.patchComposite( source.getVertexSource().orElseThrow(NullPointerException::new), source.getGeometrySource().orElse(null), + source.getTessControlSource().orElse(null), + source.getTessEvalSource().orElse(null), source.getFragmentSource().orElseThrow(NullPointerException::new)); String vertex = transformed.get(PatchShaderType.VERTEX); String geometry = transformed.get(PatchShaderType.GEOMETRY); + String tessControl = transformed.get(PatchShaderType.TESS_CONTROL); + String tessEval = transformed.get(PatchShaderType.TESS_EVAL); String fragment = transformed.get(PatchShaderType.FRAGMENT); - PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, fragment); + PatchedShaderPrinter.debugPatchedShaders(source.getName(), vertex, geometry, tessControl, tessEval, fragment); Objects.requireNonNull(flipped); ProgramBuilder builder; try { - builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS); + builder = ProgramBuilder.begin(source.getName(), vertex, geometry, tessControl, tessEval, fragment, IrisSamplers.COMPOSITE_RESERVED_TEXTURE_UNITS); } catch (RuntimeException e) { // TODO: Better error handling throw new RuntimeException("Shader compilation failed for shadow composite " + source.getName() + "!", e); diff --git a/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java b/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java index 6cbee5048..005b0bf16 100644 --- a/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java +++ b/src/main/java/net/coderbot/iris/shadows/ShadowRenderTargets.java @@ -9,6 +9,8 @@ import net.coderbot.iris.gl.texture.DepthBufferFormat; import net.coderbot.iris.gl.texture.DepthCopyStrategy; import net.coderbot.iris.gl.texture.InternalTextureFormat; import net.coderbot.iris.rendertarget.DepthTexture; +import net.coderbot.iris.features.FeatureFlags; +import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.rendertarget.RenderTarget; import net.coderbot.iris.shaderpack.PackShadowDirectives; import org.lwjgl.opengl.GL11; @@ -35,11 +37,11 @@ public class ShadowRenderTargets { private final InternalTextureFormat[] formats; private final IntList buffersToBeCleared; - public ShadowRenderTargets(int resolution, PackShadowDirectives shadowDirectives) { + public ShadowRenderTargets(WorldRenderingPipeline pipeline, int resolution, PackShadowDirectives shadowDirectives) { this.shadowDirectives = shadowDirectives; this.resolution = resolution; - final int size = shadowDirectives.getColorSamplingSettings().size(); + final int size = pipeline.hasFeature(FeatureFlags.HIGHER_SHADOWCOLOR) ? PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS_IRIS : PackShadowDirectives.MAX_SHADOW_COLOR_BUFFERS_OF; targets = new RenderTarget[size]; formats = new InternalTextureFormat[size]; flipped = new boolean[size]; diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java b/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java index 47344100a..9f2b27aeb 100644 --- a/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java +++ b/src/main/java/net/coderbot/iris/shadows/frustum/advanced/AdvancedShadowCullingFrustum.java @@ -74,7 +74,7 @@ public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportPr private int planeCount = 0; private final Vector3f shadowLightVectorFromOrigin = new Vector3f(); - private BoxCuller boxCuller; + protected BoxCuller boxCuller; private final Vector3d position = new Vector3d(); private final BaseClippingPlanes baseClippingPlanes = new BaseClippingPlanes(); @@ -277,13 +277,13 @@ public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportPr return new Viewport(this, position.set(xPosition, yPosition, zPosition)); } - private boolean isVisible(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + protected boolean isVisible(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { return this.checkCornerVisibility((float)(minX - xPosition), (float)(minY - yPosition), (float)(minZ - zPosition), (float)(maxX - xPosition), (float)(maxY - yPosition), (float)(maxZ - zPosition)); } // view-relative coordinates. - private boolean checkCornerVisibility(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { + protected boolean checkCornerVisibility(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { for (int i = 0; i < planeCount; ++i) { final Vector4f plane = this.planes[i]; diff --git a/src/main/java/net/coderbot/iris/shadows/frustum/advanced/SafeZoneCullingFrustum.java b/src/main/java/net/coderbot/iris/shadows/frustum/advanced/SafeZoneCullingFrustum.java new file mode 100644 index 000000000..849166df3 --- /dev/null +++ b/src/main/java/net/coderbot/iris/shadows/frustum/advanced/SafeZoneCullingFrustum.java @@ -0,0 +1,55 @@ +package net.coderbot.iris.shadows.frustum.advanced; + +import net.coderbot.iris.shadows.frustum.BoxCuller; +import net.minecraft.util.AxisAlignedBB; +import org.joml.Matrix4f; +import org.joml.Vector3f; + +public class SafeZoneCullingFrustum extends AdvancedShadowCullingFrustum { + private final BoxCuller distanceCuller; + + public SafeZoneCullingFrustum(Matrix4f playerView, Matrix4f playerProjection, Vector3f shadowLightVector, BoxCuller voxelCuller, BoxCuller distanceCuller) { + super(); + init(playerView, playerProjection, shadowLightVector, voxelCuller); + this.distanceCuller = distanceCuller; + } + + @Override + public void setPosition(double cameraX, double cameraY, double cameraZ) { + if (this.distanceCuller != null) { + this.distanceCuller.setPosition(cameraX, cameraY, cameraZ); + } + super.setPosition(cameraX, cameraY, cameraZ); + } + + @Override + public boolean isBoundingBoxInFrustum(AxisAlignedBB aabb) { + // Cull if outside the overall distance limit + if (distanceCuller != null && distanceCuller.isCulled(aabb)) { + return false; + } + + // If within the voxel safe zone, always render + if (boxCuller != null && !boxCuller.isCulled(aabb)) { + return true; + } + + // Otherwise fall through to advanced frustum culling + return isVisible(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ); + } + + @Override + public boolean testAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { + // Cull if outside the overall distance limit + if (distanceCuller != null && distanceCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) { + return false; + } + + // If within the voxel safe zone, always render + if (boxCuller != null && !boxCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) { + return true; + } + + return checkCornerVisibility(minX, minY, minZ, maxX, maxY, maxZ); + } +} diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinEntityRenderer.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinEntityRenderer.java index 4c2ba419b..28abbf20d 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinEntityRenderer.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinEntityRenderer.java @@ -95,17 +95,24 @@ public abstract class MixinEntityRenderer implements IResourceManagerReloadListe } - @Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V")) - private void iris$beginWeatherAndwriteRainAndSnowToDepthBuffer(float partialTicks, long startTime, CallbackInfo ci, @Share("pipeline") LocalRef pipeline) { + @WrapOperation(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V")) + private void iris$wrapWeather(EntityRenderer instance, float partialTicks, Operation original, @Share("pipeline") LocalRef pipeline) { pipeline.get().setPhase(WorldRenderingPhase.RAIN_SNOW); if (pipeline.get().shouldWriteRainAndSnowToDepthBuffer()) { GLStateManager.glDepthMask(true); } + if (pipeline.get().shouldRenderWeather()) { + original.call(instance, partialTicks); + } + pipeline.get().setPhase(WorldRenderingPhase.NONE); } - @Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;renderRainSnow(F)V", shift = At.Shift.AFTER)) - private void iris$endWeather(float partialTicks, long startTime, CallbackInfo ci, @Share("pipeline") LocalRef pipeline) { - pipeline.get().setPhase(WorldRenderingPhase.NONE); + @WrapOperation(method = "updateRenderer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/EntityRenderer;addRainParticles()V")) + private void iris$wrapRainParticles(EntityRenderer instance, Operation original) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline == null || pipeline.shouldRenderWeatherParticles()) { + original.call(instance); + } } @WrapOperation(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V", remap = false)) diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderGlobal.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderGlobal.java index a80821744..c9012c777 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderGlobal.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/shaders/MixinRenderGlobal.java @@ -4,6 +4,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Share; import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import com.gtnewhorizon.gtnhlib.client.renderer.ITessellatorInstance; import net.coderbot.iris.Iris; import net.coderbot.iris.layer.GbufferPrograms; import net.coderbot.iris.pipeline.WorldRenderingPhase; @@ -11,6 +12,7 @@ import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.uniforms.CapturedRenderingState; import net.coderbot.iris.uniforms.EntityIdHelper; import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -63,6 +65,58 @@ public class MixinRenderGlobal { GL11.glRotatef(pipeline.get().getSunPathRotation(), 0.0F, 0.0F, 1.0F); } + // Sky disc: wrap the glCallList(glSkyList) call — the first glCallList in the surface world branch + @WrapOperation(method = "renderSky", + at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", ordinal = 0, remap = false), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getSkyColor(Lnet/minecraft/entity/Entity;F)Lnet/minecraft/util/Vec3;"))) + private void iris$skipSkyDisc(int list, Operation original) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline == null || pipeline.shouldRenderSkyDisc()) { + original.call(list); + } + } + + // Sun: wrap Tessellator.draw() after sun texture bind, before moon texture bind + @WrapOperation(method = "renderSky", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 0), + slice = @Slice( + from = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;locationSunPng:Lnet/minecraft/util/ResourceLocation;"), + to = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;locationMoonPhasesPng:Lnet/minecraft/util/ResourceLocation;"))) + private int iris$skipSun(Tessellator instance, Operation original) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline == null || pipeline.shouldRenderSun()) { + return original.call(instance); + } + ((ITessellatorInstance) instance).discard(); + return 0; + } + + // Moon: wrap Tessellator.draw() after moon texture bind, before getStarBrightness + @WrapOperation(method = "renderSky", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 0), + slice = @Slice( + from = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;locationMoonPhasesPng:Lnet/minecraft/util/ResourceLocation;"), + to = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getStarBrightness(F)F"))) + private int iris$skipMoon(Tessellator instance, Operation original) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline == null || pipeline.shouldRenderMoon()) { + return original.call(instance); + } + ((ITessellatorInstance) instance).discard(); + return 0; + } + + // Stars: wrap glCallList(starGLCallList) — the glCallList after getStarBrightness + @WrapOperation(method = "renderSky", + at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", ordinal = 0, remap = false), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getStarBrightness(F)F"))) + private void iris$skipStars(int list, Operation original) { + WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); + if (pipeline == null || pipeline.shouldRenderStars()) { + original.call(list); + } + } + @Inject(method="drawSelectionBox", at=@At(value="HEAD")) private void iris$startOutline(EntityPlayer player, MovingObjectPosition pos, int p_72731_3_, float p_72731_4_, CallbackInfo ci) { GbufferPrograms.beginOutline();