-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert particle shader resource override to Veil GLSL shader transfo…
…rmer
- Loading branch information
Showing
3 changed files
with
72 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...org/ladysnake/effective/core/render/transformer/EffectiveTransparencyFixPreProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
src/client/resources/assets/minecraft/shaders/core/particle.fsh
This file was deleted.
Oops, something went wrong.