-
-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
407 additions
and
32 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
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
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
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
113 changes: 113 additions & 0 deletions
113
.../src/main/java/net/irisshaders/iris/pipeline/transform/transformer/FutureTransformer.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,113 @@ | ||
package net.irisshaders.iris.pipeline.transform.transformer; | ||
|
||
import io.github.douira.glsl_transformer.ast.node.TranslationUnit; | ||
import io.github.douira.glsl_transformer.ast.query.Root; | ||
import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint; | ||
import io.github.douira.glsl_transformer.ast.transform.ASTParser; | ||
import net.irisshaders.iris.gl.blending.AlphaTest; | ||
import net.irisshaders.iris.pipeline.transform.PatchShaderType; | ||
|
||
public class FutureTransformer { | ||
public static void addBasicFunctions(ASTParser t, | ||
TranslationUnit tree, | ||
Root root, PatchShaderType shaderType, AlphaTest alphaTest, String vertexColorA) { | ||
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform sampler2D mainTexture;"); | ||
tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS, """ | ||
vec4 iris_sampleMainTexture(vec2 coord) { | ||
return texture(mainTexture, coord); | ||
} | ||
""", | ||
|
||
""" | ||
vec4 iris_sampleMainTextureOffset(vec2 coord, ivec2 offset) { | ||
return textureOffset(mainTexture, coord, offset); | ||
} | ||
""", | ||
|
||
""" | ||
vec4 iris_sampleMainTextureLod(vec2 coord, float lod) { | ||
return textureLod(mainTexture, coord, lod); | ||
} | ||
""", | ||
|
||
""" | ||
vec4 iris_sampleMainTextureGather(vec2 coord, int comp) { | ||
return textureGather(mainTexture, coord, comp); | ||
} | ||
""", | ||
|
||
""" | ||
vec4 iris_sampleMainTextureGrad(vec2 coord, vec2 dtdx, vec2 dtdy) { | ||
return textureGrad(mainTexture, coord, dtdx, dtdy); | ||
} | ||
""", | ||
|
||
""" | ||
vec4 iris_sampleMainTexture(vec2 coord, float bias) { | ||
return texture(mainTexture, coord, bias); | ||
} | ||
""", | ||
|
||
""" | ||
vec4 iris_fetchMainTexture(ivec2 coord, int lod) { | ||
return texelFetch(mainTexture, coord, lod); | ||
} | ||
"""); | ||
|
||
if (root.identifierIndex.has("iris_sampleLightmap")) { | ||
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform sampler2D lightmapTexture;"); | ||
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, """ | ||
vec4 iris_sampleLightmap(vec2 coord) { | ||
return texture(lightmapTexture, coord); | ||
} | ||
"""); | ||
} | ||
|
||
if (shaderType == PatchShaderType.FRAGMENT) { | ||
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform float iris_currentAlphaTest;"); | ||
|
||
tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS, """ | ||
void iris_modifyBase(inout vec2 texCoord, inout vec2 light, inout vec4 color) { | ||
} | ||
""", | ||
// Optional | ||
""" | ||
void iris_modifyNormals(inout vec3 normal, inout vec3 tangent) { | ||
} | ||
""", | ||
"bool iris_discardFragment(vec4 color) {\n" + | ||
"return !(" + alphaTest.toBoolean("color.a", "iris_currentAlphaTest", vertexColorA) + ");\n" + | ||
This comment has been minimized.
Sorry, something went wrong. |
||
"}", | ||
""" | ||
vec4 iris_modifyOverlay(vec4 color) { | ||
return color; | ||
} | ||
"""); | ||
} else if (shaderType == PatchShaderType.VERTEX) { | ||
tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS, """ | ||
vec4 iris_getModelPosition() { | ||
return irisInt_modelPosition; | ||
} | ||
""", | ||
""" | ||
vec4 iris_getViewPosition() { | ||
return irisInt_viewPosition; | ||
} | ||
""", | ||
""" | ||
vec4 iris_getClipPosition() { | ||
return irisInt_clipPosition; | ||
} | ||
"""); | ||
} | ||
} | ||
|
||
public static void replaceAndAdd(Root root, TranslationUnit tree, ASTParser t, String reference, String replacement, String injection) { | ||
if (root.identifierIndex.has(reference)) { | ||
root.replaceReferenceExpressions(t, reference, replacement); | ||
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, injection); | ||
} | ||
} | ||
} |
Oops, something went wrong.
this should be a
Template
, inserting variable strings is slow.