Skip to content

Commit

Permalink
Convert particle shader resource override to Veil GLSL shader transfo…
Browse files Browse the repository at this point in the history
…rmer
  • Loading branch information
ryanhcode committed Jan 1, 2025
1 parent 62efbb3 commit d86fe93
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 25 deletions.
7 changes: 7 additions & 0 deletions src/client/java/org/ladysnake/effective/core/Effective.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ladysnake.effective.core;

import foundry.veil.platform.VeilEventPlatform;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
Expand Down Expand Up @@ -32,6 +33,7 @@
import org.ladysnake.effective.core.render.entity.model.SplashModel;
import org.ladysnake.effective.core.render.entity.model.SplashRimModel;
import org.ladysnake.effective.core.render.particle.SoftParticleRenderType;
import org.ladysnake.effective.core.render.transformer.EffectiveTransparencyFixPreProcessor;
import org.ladysnake.effective.core.world.RenderedHypnotizingEntities;
import org.ladysnake.effective.core.world.WaterfallCloudGenerators;
import org.ladysnake.satin.api.event.EntitiesPreRenderCallback;
Expand Down Expand Up @@ -247,5 +249,10 @@ public void onInitializeClient() {
freezeFrames = -1;
}
});


VeilEventPlatform.INSTANCE.onVeilAddShaderProcessors((provider, registry) -> {
registry.addPreprocessor(new EffectiveTransparencyFixPreProcessor(), false);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.ladysnake.effective.core.render.transformer;

import foundry.veil.api.client.render.shader.processor.ShaderPreProcessor;
import foundry.veil.api.glsl.GlslSyntaxException;
import foundry.veil.api.glsl.node.GlslNode;
import foundry.veil.api.glsl.node.GlslNodeList;
import foundry.veil.api.glsl.node.GlslTree;
import foundry.veil.api.glsl.node.branch.GlslSelectionNode;
import foundry.veil.api.glsl.node.expression.GlslCompareNode;
import foundry.veil.api.glsl.node.primary.GlslFloatConstantNode;
import foundry.veil.lib.anarres.cpp.LexerException;
import net.minecraft.util.Identifier;

import java.io.IOException;

/**
* A pre-processor intended to verify the Minecraft particle transparency check isn't active.
* <p>
* Intended to transform:
* <pre>{@code
* if (color.a < 0.1) {
* discard;
* }
* }
*
* Into the following:
* <pre>{@code
* if (color.a < 0.0000001) {
* discard;
* }
*
* Inside of any fragment shader named <code>particle</code>.
*/
public class EffectiveTransparencyFixPreProcessor implements ShaderPreProcessor {

public static final float NEW_TRANSPARENCY_THRESHOLD = 0.0000001f;

@Override
public void modify(final Context ctx, final GlslTree tree) {
final Identifier name = ctx.name();
assert name != null;

if (!ctx.isSourceFile()) return;
if (!name.getNamespace().equals("minecraft") || !name.getPath().equals("shaders/core/particle.fsh")) return;

final GlslNodeList mainFunctionBody = tree.mainFunction().orElseThrow().getBody();
assert mainFunctionBody != null : "Main function body is null";

for (final GlslNode node : mainFunctionBody) {

if (node instanceof GlslSelectionNode selectionNode && selectionNode.getExpression() instanceof GlslCompareNode compareNode) {

// We know there's an if statement (selectionNode) with a comparison inside it
// If the second part of the comparison is 0.1, and the comparison type is "less than", we can assume it's the transparency check

if (compareNode.getOperand() == GlslCompareNode.Operand.LESS &&
compareNode.getSecond() instanceof GlslFloatConstantNode floatConstant &&
Math.abs(floatConstant.floatValue() - 0.1) < 0.0001) { // Arbitrary epsilon
compareNode.setSecond(new GlslFloatConstantNode(NEW_TRANSPARENCY_THRESHOLD));
}
}
}
}

}
25 changes: 0 additions & 25 deletions src/client/resources/assets/minecraft/shaders/core/particle.fsh

This file was deleted.

0 comments on commit d86fe93

Please sign in to comment.