Skip to content

Commit

Permalink
More testing...
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 5, 2024
1 parent f60a6e3 commit 39edd36
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 120
#version 330 compatibility

const float ambientOcclusionLevel = 2.0f;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 120
#version 330 compatibility

void main() {
// we're not really doing anything in particular
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 120
#version 330 compatibility

const float ambientOcclusionLevel = 2.0f;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 120
#version 330 compatibility

void main() {
// we're not really doing anything in particular
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 120
#version 330 compatibility

// these shouldn't be recognized as options, conflicts with vsh values
// #define VSH
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 120
#version 330 compatibility

#define GODRAYS 32 // [16 32 64 128] Number of godrays
#define SHADOWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class MixinBlockRenderer {
hasOverride = false;
}

@WrapOperation(method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;attemptPassDowngrade(Lnet/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;)Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;"))
private TerrainRenderPass iris$skipPassDowngrade(BlockRenderer instance, MutableQuadViewImpl mutableQuadView, TextureAtlasSprite quad, TerrainRenderPass sprite, Operation<TerrainRenderPass> original) {
@WrapOperation(method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;attemptPassDowngrade(Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;)Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;"))
private TerrainRenderPass iris$skipPassDowngrade(BlockRenderer instance, TextureAtlasSprite textureAtlasSprite, TerrainRenderPass sprite, Operation<TerrainRenderPass> original) {
if (hasOverride) return null;

return original.call(instance, mutableQuadView, quad, sprite);
return original.call(instance, textureAtlasSprite, sprite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ private GlProgram<ChunkShaderInterface> buildProgram(GlProgram.Builder builder,
.bindAttribute("a_Color", ChunkShaderBindingPoints.ATTRIBUTE_COLOR)
.bindAttribute("a_TexCoord", ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE)
.bindAttribute("a_LightAndData", ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX)
.bindAttribute("mc_Entity", 11)
.bindAttribute("mc_midTexCoord", 12)
.bindAttribute("irisInt_BlockInfo", 11)
.bindAttribute("irisInt_MidTexCoord", 12)
.bindAttribute("at_tangent", 13)
.bindAttribute("iris_Normal", 10)
.bindAttribute("at_midBlock", 14)
.link((shader) -> {
int handle = ((GlObject) shader).handle();
GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT));

if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "iris_Normal") != -1;
if (!hasMidBlock) hasMidBlock = GL43C.glGetAttribLocation(handle, "at_midBlock") != -1;
if (!hasBlockId) hasBlockId = GL43C.glGetAttribLocation(handle, "mc_Entity") != -1;
if (!hasMidUv) hasMidUv = GL43C.glGetAttribLocation(handle, "mc_midTexCoord") != -1;
if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "irisInt_Normal") != -1;
if (!hasMidBlock) hasMidBlock = GL43C.glGetAttribLocation(handle, "irisInt_midBlock") != -1;
if (!hasBlockId) hasBlockId = GL43C.glGetAttribLocation(handle, "irisInt_BlockInfo") != -1;
if (!hasMidUv) hasMidUv = GL43C.glGetAttribLocation(handle, "irisInt_MidTexCoord") != -1;
if (!hasTangent) hasTangent = GL43C.glGetAttribLocation(handle, "at_tangent") != -1;

return new SodiumShader(pipeline, pass, shader, handle, source.getDirectives().getBlendModeOverride(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public static void transform(
"irisInt_modelPosition = vec4(_vert_position + u_RegionOffset + _get_draw_translation(irisInt_LightAndData[3]), 1.0);" +
viewPositionSetup +
clipPositionSetup +
"iris_overlayColor = vec4(0.0, 0.0, 0.0, 1.0);" +
"iris_overlayColor = vec4(0.0, 0.0, 0.0, 0.0);" +
"}");

addIfNotExists(root, t, tree, "irisInt_Normal", Type.F32VEC4, StorageQualifier.StorageType.IN, 10);
addIfNotExists(root, t, tree, "irisInt_Tangent", Type.F32VEC4, StorageQualifier.StorageType.IN, 13);
addIfNotExists(root, t, tree, "irisInt_MidTexCoord", Type.F32VEC2, StorageQualifier.StorageType.IN, 12);
addIfNotExists(root, t, tree, "irisInt_midBlock", Type.F32VEC4, StorageQualifier.StorageType.IN, 14);
addIfNotExists(root, t, tree, "irisInt_BlockInfo", Type.F32VEC2, StorageQualifier.StorageType.IN, 11);
addIfNotExists(root, t, tree, "irisInt_BlockInfo", Type.I32VEC2, StorageQualifier.StorageType.IN, 11);
addIfNotExists(root, t, tree, "irisInt_PositionHi", Type.UINT32, StorageQualifier.StorageType.IN, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_HI);
addIfNotExists(root, t, tree, "irisInt_PositionLo", Type.UINT32, StorageQualifier.StorageType.IN, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_LO);
addIfNotExists(root, t, tree, "irisInt_TexCoord", Type.U32VEC2, StorageQualifier.StorageType.IN, ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE);
Expand Down Expand Up @@ -121,7 +121,7 @@ uvec3 _deinterleave_u20x3(uint packed_hi, uint packed_lo) {
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 irisInt_clipPosition;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 irisInt_viewPosition;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 iris_overlayColor;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "float iris_blockId;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "int iris_blockId;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "float iris_ambientOcclusion;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "int iris_blockEmission;");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public static void transform(
root.replaceReferenceExpressions(t, "iris_modelViewMatrix", "iris_ModelViewMat");
root.replaceReferenceExpressions(t, "iris_modelViewMatrixInverse", "iris_ModelViewMatInverse");
root.replaceReferenceExpressions(t, "iris_normalMatrix", "iris_NormalMat");

tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_DECLARATIONS,
"vec3 iris_vertex_offset = vec3(0.0);");
if (parameters.type == PatchShaderType.VERTEX) {
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "uniform sampler2D iris_overlay;");

Expand All @@ -53,12 +54,13 @@ public static void transform(
addIfNotExists(root, t, tree, "irisInt_Tangent", Type.F32VEC4, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "irisInt_UV0", Type.F32VEC2, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "mc_Entity", Type.FLOAT32, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "irisInt_Entity", Type.I32VEC3, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "mc_midTexCoord", Type.F32VEC2, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "at_midBlock", Type.F32VEC4, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "irisInt_UV1", Type.I32VEC2, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "irisInt_UV2", Type.I32VEC2, StorageQualifier.StorageType.IN);

tree.prependMainFunctionBody(t, "vanilla_init();");
if (!parameters.inputs.isNewLines()) tree.prependMainFunctionBody(t, "vanilla_init();");

tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "void vanilla_init() {\n" +
"iris_midTexCoord = mc_midTexCoord;" +
Expand All @@ -67,18 +69,20 @@ public static void transform(
(parameters.inputs.hasNormal() ?
"iris_Normal = irisInt_Normal.rgb;" : "iris_Normal = vec3(0, 1, 0);") +
"iris_ambientOcclusion = irisInt_Color.a;" +
"iris_blockId = mc_Entity;" +
"iris_blockId = int(mc_Entity + 0.5);" +
"iris_entityId = int(irisInt_Entity.x + 0.5);" +
"iris_blockEntityId = int(irisInt_Entity.y + 0.5);" +
"iris_blockEmission = int(at_midBlock.w);" +
(parameters.inputs.hasColor() ?
"iris_vertexColor = irisInt_Color * iris_ColorModulator;" : "iris_vertexColor = iris_ColorModulator;") +
(parameters.inputs.hasLight() ?
"iris_lightCoord = (iris_LightmapTextureMatrix * vec4(irisInt_UV2, 0.0, 1.0)).xy;" :
"iris_lightCoord = vec2(240.0, 240.0) ;" )+
"irisInt_modelPosition = vec4(irisInt_Position + iris_ChunkOffset, 1.0);" +
"irisInt_modelPosition = vec4(irisInt_Position + iris_ChunkOffset + iris_vertex_offset, 1.0);" +
viewPositionSetup +
clipPositionSetup +
(parameters.inputs.hasOverlay() ?
"iris_overlayColor = texelFetch(iris_overlay, irisInt_UV1, 0); iris_overlayColor.a = 1.0 - iris_overlayColor.a;" : "iris_overlayColor = vec4(0.0, 0.0, 0.0, 1.0);") +
"iris_overlayColor = texelFetch(iris_overlay, irisInt_UV1, 0); iris_overlayColor.a = 1.0 - iris_overlayColor.a;" : "iris_overlayColor = vec4(0.0, 0.0, 0.0, 0.0);") +
"}");

addIfNotExists(root, t, tree, "iris_ChunkOffset", Type.F32VEC3, StorageQualifier.StorageType.UNIFORM);
Expand All @@ -94,9 +98,51 @@ public static void transform(
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 irisInt_viewPosition;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 irisInt_clipPosition;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "vec4 iris_overlayColor;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "float iris_blockId;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "int iris_blockId;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "int iris_entityId;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "int iris_blockEntityId;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "int iris_blockEmission;");
tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_FUNCTIONS, "float iris_ambientOcclusion;");

if (parameters.inputs.isNewLines()) {
// Create our own main function to wrap the existing main function, so that we
// can do our line shenanigans.
// TRANSFORM: this is fine since the AttributeTransformer has a different name
// in the vertex shader

tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS,
"uniform vec2 iris_ScreenSize;",
"uniform float iris_LineWidth;",
"""
void iris_widen_lines(vec4 linePosStart, vec4 linePosEnd) {
vec3 ndc1 = linePosStart.xyz / linePosStart.w;
vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;
vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * iris_ScreenSize);
vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * iris_LineWidth / iris_ScreenSize;
if (lineOffset.x < 0.0) {
lineOffset *= -1.0;
}
if (gl_VertexID % 2 == 0) {
gl_Position = vec4((ndc1 + vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
} else {
gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
}}""");

root.rename("main", "irisMain");

tree.parseAndInjectNode(t, ASTInjectionPoint.END, "void main() {" +
"iris_vertex_offset = irisInt_Normal.rgb;" +
"vanilla_init();" +
"irisMain();" +
"vec4 linePosEnd = gl_Position;" +
"gl_Position = vec4(0.0);" +
"iris_vertex_offset = vec3(0.0);" +
"vanilla_init();" +
"irisMain();" +
"vec4 linePosStart = gl_Position;" +
"iris_widen_lines(linePosStart, linePosEnd);}");

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.irisshaders.iris.pipeline.transform.PatchShaderType;
import net.irisshaders.iris.pipeline.transform.parameter.VanillaParameters;

public class VanillaTransformer {
public class VanillaTransformer {
public static void transform(
ASTParser t,
TranslationUnit tree,
Expand Down Expand Up @@ -155,20 +155,20 @@ public static void transform(
tree.parseAndInjectNodes(t, ASTInjectionPoint.END,
"uniform vec2 iris_ScreenSize;",
"uniform float iris_LineWidth;",
"void iris_widen_lines(vec4 linePosStart, vec4 linePosEnd) {" +
"vec3 ndc1 = linePosStart.xyz / linePosStart.w;" +
"vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;" +
"vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * iris_ScreenSize);" +
"vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * iris_LineWidth / iris_ScreenSize;"
+
"if (lineOffset.x < 0.0) {" +
" lineOffset *= -1.0;" +
"}" +
"if (gl_VertexID % 2 == 0) {" +
" gl_Position = vec4((ndc1 + vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);" +
"} else {" +
" gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);" +
"}}",
"""
void iris_widen_lines(vec4 linePosStart, vec4 linePosEnd) {
vec3 ndc1 = linePosStart.xyz / linePosStart.w;
vec3 ndc2 = linePosEnd.xyz / linePosEnd.w;
vec2 lineScreenDirection = normalize((ndc2.xy - ndc1.xy) * iris_ScreenSize);
vec2 lineOffset = vec2(-lineScreenDirection.y, lineScreenDirection.x) * iris_LineWidth / iris_ScreenSize;
if (lineOffset.x < 0.0) {
lineOffset *= -1.0;
}
if (gl_VertexID % 2 == 0) {
gl_Position = vec4((ndc1 + vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
} else {
gl_Position = vec4((ndc1 - vec3(lineOffset, 0.0)) * linePosStart.w, linePosStart.w);
}}""",
"void main() {" +
"iris_vertex_offset = iris_Normal;" +
"irisMain();" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static ProgramSource readProgramSource(AbsolutePackPath directory,
// This is for really old packs that do not use a vertex shader.
Iris.logger.warn("Found a program (" + program + ") that has a fragment shader but no vertex shader? This is very legacy behavior and might not work right.");
vertexSource = """
#version 120
#version 330 compatibility
varying vec4 irs_texCoords[3];
varying vec4 irs_Color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class IrisVertexFormats {
.add("UV2", VertexFormatElement.UV2)
.add("Normal", VertexFormatElement.NORMAL)
.padding(1)
.add("iris_Entity", ENTITY_ID_ELEMENT)
.add("irisInt_Entity", ENTITY_ID_ELEMENT)
.add("mc_midTexCoord", MID_TEXTURE_ELEMENT)
.add("at_tangent", TANGENT_ELEMENT)
.build();
Expand Down

0 comments on commit 39edd36

Please sign in to comment.