From a8067d388d7e43392efc7971e9e9e6db8de72252 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 22 Nov 2023 12:49:06 -0800 Subject: [PATCH] Discard discard - Do not guard discard predicate on a compile definition because it doesn't matter for ubershaders. --- .../backend/compile/component/MaterialAdapterComponent.java | 3 +-- .../resources/assets/flywheel/flywheel/api/fragment.glsl | 5 +---- .../assets/flywheel/flywheel/context/crumbling.frag | 2 -- .../resources/assets/flywheel/flywheel/context/world.frag | 4 +--- .../resources/assets/flywheel/flywheel/material/cutout.frag | 1 - .../resources/assets/flywheel/flywheel/material/default.frag | 4 ++++ 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java b/src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java index 84f6d9f9d..9b8ced419 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java +++ b/src/main/java/com/jozufozu/flywheel/backend/compile/component/MaterialAdapterComponent.java @@ -21,13 +21,12 @@ import com.jozufozu.flywheel.glsl.generate.GlslSwitch; import net.minecraft.resources.ResourceLocation; public class MaterialAdapterComponent implements SourceComponent { - // TODO: material id handling in pipeline shader private final ResourceLocation name; private final GlslExpr switchArg; private final List functionsToAdapt; private final List adaptedComponents; - public MaterialAdapterComponent(ResourceLocation name, GlslExpr switchArg, List functionsToAdapt, List adaptedComponents) { + private MaterialAdapterComponent(ResourceLocation name, GlslExpr switchArg, List functionsToAdapt, List adaptedComponents) { this.name = name; this.switchArg = switchArg; this.functionsToAdapt = functionsToAdapt; diff --git a/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl b/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl index 4aabc253e..e6a8d008a 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl @@ -29,10 +29,7 @@ vec2 flw_fragLight; vec4 flw_fogFilter(vec4 color); /* - * May be implemented by materials. - * If implemented, a material must define FLW_DISCARD - * - * Guard calls with FLW_DISCARD + * Must be implemented by materials. */ bool flw_discardPredicate(vec4 finalColor); #endif diff --git a/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag b/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag index a8647b8b7..233fb6676 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag +++ b/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag @@ -34,11 +34,9 @@ void flw_initFragment() { void flw_contextFragment() { vec4 color = flw_fragColor; - #ifdef FLW_DISCARD if (flw_discardPredicate(color)) { discard; } - #endif fragColor = flw_fogFilter(color); } diff --git a/src/main/resources/assets/flywheel/flywheel/context/world.frag b/src/main/resources/assets/flywheel/flywheel/context/world.frag index 245835d6d..951ad85b0 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/world.frag +++ b/src/main/resources/assets/flywheel/flywheel/context/world.frag @@ -28,11 +28,9 @@ void flw_contextFragment() { color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); color *= lightColor; - #ifdef FLW_DISCARD - if (flw_discardPredicate(color)) { + if (flw_discardPredicate(color)) { discard; } - #endif fragColor = flw_fogFilter(color); } diff --git a/src/main/resources/assets/flywheel/flywheel/material/cutout.frag b/src/main/resources/assets/flywheel/flywheel/material/cutout.frag index bee51d582..6ff475fc3 100644 --- a/src/main/resources/assets/flywheel/flywheel/material/cutout.frag +++ b/src/main/resources/assets/flywheel/flywheel/material/cutout.frag @@ -4,7 +4,6 @@ void flw_materialFragment() { } -#define FLW_DISCARD bool flw_discardPredicate(vec4 finalColor) { return finalColor.a < 0.1; } diff --git a/src/main/resources/assets/flywheel/flywheel/material/default.frag b/src/main/resources/assets/flywheel/flywheel/material/default.frag index ba5d33d42..dade58083 100644 --- a/src/main/resources/assets/flywheel/flywheel/material/default.frag +++ b/src/main/resources/assets/flywheel/flywheel/material/default.frag @@ -4,6 +4,10 @@ void flw_materialFragment() { } +bool flw_discardPredicate(vec4 finalColor) { + return false; +} + vec4 flw_fogFilter(vec4 color) { return linear_fog(color, flw_distance, flywheel.fogRange.x, flywheel.fogRange.y, flywheel.fogColor); }