Discard discard

- Do not guard discard predicate on a compile definition because it
  doesn't matter for ubershaders.
This commit is contained in:
Jozufozu 2023-11-22 12:49:06 -08:00
parent 78975e8cad
commit a8067d388d
6 changed files with 7 additions and 12 deletions

View file

@ -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<AdaptedFn> functionsToAdapt;
private final List<StringSubstitutionSourceComponent> adaptedComponents;
public MaterialAdapterComponent(ResourceLocation name, GlslExpr switchArg, List<AdaptedFn> functionsToAdapt, List<StringSubstitutionSourceComponent> adaptedComponents) {
private MaterialAdapterComponent(ResourceLocation name, GlslExpr switchArg, List<AdaptedFn> functionsToAdapt, List<StringSubstitutionSourceComponent> adaptedComponents) {
this.name = name;
this.switchArg = switchArg;
this.functionsToAdapt = functionsToAdapt;

View file

@ -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

View file

@ -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);
}

View file

@ -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);
}

View file

@ -4,7 +4,6 @@
void flw_materialFragment() {
}
#define FLW_DISCARD
bool flw_discardPredicate(vec4 finalColor) {
return finalColor.a < 0.1;
}

View file

@ -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);
}