Skip to content

Commit

Permalink
bit shifting into the next universe
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Nov 7, 2024
1 parent 9e87a8e commit 6c3f273
Show file tree
Hide file tree
Showing 41 changed files with 418 additions and 347 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

val MINECRAFT_VERSION by extra { "1.21.1" }
val NEOFORGE_VERSION by extra { "21.1.46" }
val NEOFORGE_VERSION by extra { "21.1.74" }
val FABRIC_LOADER_VERSION by extra { "0.16.4" }
val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ private IrisGenericRenderProgram(String name, boolean isShadowPass, boolean tran
GL32.glVertexAttribPointer(0, 3, GL32.GL_FLOAT, false, 0, 0);
GL32.glEnableVertexAttribArray(0);

projectionUniform = tryGetUniformLocation2("iris_ProjectionMatrix");
projectionInverseUniform = tryGetUniformLocation2("iris_ProjectionMatrixInverse");
modelViewUniform = tryGetUniformLocation2("iris_ModelViewMatrix");
modelViewInverseUniform = tryGetUniformLocation2("iris_ModelViewMatrixInverse");
normalMatrix3fUniform = tryGetUniformLocation2("iris_NormalMatrix");
projectionUniform = tryGetUniformLocation2("irisInt_ProjectionMatrix");
projectionInverseUniform = tryGetUniformLocation2("irisInt_ProjectionMatrixInverse");
modelViewUniform = tryGetUniformLocation2("irisInt_ModelViewMatrix");
modelViewInverseUniform = tryGetUniformLocation2("irisInt_ModelViewMatrixInverse");
normalMatrix3fUniform = tryGetUniformLocation2("irisInt_NormalMatrix");

this.instancedShaderOffsetChunkUniform = this.tryGetUniformLocation2("uOffsetChunk");
this.instancedShaderOffsetSubChunkUniform = this.tryGetUniformLocation2("uOffsetSubChunk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private IrisLodRenderProgram(String name, boolean isShadowPass, boolean transluc
id = GL43C.glCreateProgram();

GL32.glBindAttribLocation(this.id, 0, "vPosition");
GL32.glBindAttribLocation(this.id, 1, "iris_color");
GL32.glBindAttribLocation(this.id, 1, "irisInt_color");
GL32.glBindAttribLocation(this.id, 2, "irisExtra");

this.bufferBlendOverrides = bufferBlendOverrides;
Expand Down Expand Up @@ -124,11 +124,11 @@ private IrisLodRenderProgram(String name, boolean isShadowPass, boolean transluc
modelOffsetUniform = tryGetUniformLocation2("modelOffset");
worldYOffsetUniform = tryGetUniformLocation2("worldYOffset");
mircoOffsetUniform = tryGetUniformLocation2("mircoOffset");
projectionUniform = tryGetUniformLocation2("iris_ProjectionMatrix");
projectionInverseUniform = tryGetUniformLocation2("iris_ProjectionMatrixInverse");
modelViewUniform = tryGetUniformLocation2("iris_ModelViewMatrix");
modelViewInverseUniform = tryGetUniformLocation2("iris_ModelViewMatrixInverse");
normalMatrix3fUniform = tryGetUniformLocation2("iris_NormalMatrix");
projectionUniform = tryGetUniformLocation2("irisInt_ProjectionMatrix");
projectionInverseUniform = tryGetUniformLocation2("irisInt_ProjectionMatrixInverse");
modelViewUniform = tryGetUniformLocation2("irisInt_ModelViewMatrix");
modelViewInverseUniform = tryGetUniformLocation2("irisInt_ModelViewMatrixInverse");
normalMatrix3fUniform = tryGetUniformLocation2("irisInt_NormalMatrix");

// Fog/Clip Uniforms
clipDistanceUniform = tryGetUniformLocation2("clipDistance");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.Material;
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder;
import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MutableQuadViewImpl;
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings;
import net.irisshaders.iris.vertices.sodium.terrain.VertexEncoderInterface;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -32,6 +37,11 @@ public class MixinBlockRenderer {
hasOverride = false;
}

@Inject(remap = false, method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/builder/ChunkMeshBufferBuilder;push([Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexEncoder$Vertex;I)V"))
private void iris$setShade(MutableQuadViewImpl quad, float[] brightnesses, Material material, CallbackInfo ci, @Local ChunkMeshBufferBuilder vertexBuffer) {
((VertexEncoderInterface) vertexBuffer).iris$setShade(quad.hasShade());
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public class MixinChunkMeshBufferBuilder implements VertexEncoderInterface {
((VertexEncoderInterface) encoder).iris$setContextHolder(contextHolder);
}
}

@Override
public void iris$setShade(boolean shade) {
if (encoder instanceof VertexEncoderInterface) {
((VertexEncoderInterface) encoder).iris$setShade(shade);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum FeatureFlags {
BLOCK_EMISSION_ATTRIBUTE(() -> true, () -> true),
CAN_DISABLE_WEATHER(() -> true, () -> true),
SSBO(() -> true, IrisRenderSystem::supportsSSBO),
SEPARATE_AO(() -> true, () -> true),
UNKNOWN(() -> false, () -> false);

private final BooleanSupplier irisRequirement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public record AlphaTest(AlphaTestFunction function, float reference) {
// WARNING: adding new fields requires updating hashCode and equals methods!

public String toExpression(String indentation) {
return toExpression("gl_FragData[0].a", "iris_currentAlphaTest", indentation);
return toExpression("gl_FragData[0].a", "irisInt_currentAlphaTest", indentation);
}

public String toExpression(String alphaAccessor, String alphaThreshold, String indentation) {
Expand All @@ -15,7 +15,7 @@ public String toExpression(String alphaAccessor, String alphaThreshold, String i
if (function == AlphaTestFunction.ALWAYS) {
return "// alpha test disabled\n";
} else if (this == AlphaTests.VERTEX_ALPHA) {
return indentation + "if (!(" + alphaAccessor + " > iris_vertexColorAlpha)) {\n" +
return indentation + "if (!(" + alphaAccessor + " > irisInt_vertexColorAlpha)) {\n" +
indentation + " discard;\n" +
indentation + "}\n";
} else if (function == AlphaTestFunction.NEVER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ProgramCreator {
public static int create(String name, GlShader... shaders) {
int program = GlStateManager.glCreateProgram();

GlStateManager._glBindAttribLocation(program, 11, "iris_Entity");
GlStateManager._glBindAttribLocation(program, 11, "irisInt_Entity");
GlStateManager._glBindAttribLocation(program, 11, "mc_Entity");
GlStateManager._glBindAttribLocation(program, 12, "mc_midTexCoord");
GlStateManager._glBindAttribLocation(program, 13, "at_tangent");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static boolean shouldOverrideShaders() {
@Redirect(method = "<init>*", require = 1, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/shaders/Uniform;glBindAttribLocation(IILjava/lang/CharSequence;)V"))
public void iris$redirectBindAttributeLocation(int i, int j, CharSequence charSequence) {
if (((Object) this) instanceof ExtendedShader && ATTRIBUTE_LIST.contains(charSequence)) {
Uniform.glBindAttribLocation(i, j, "iris_" + charSequence);
Uniform.glBindAttribLocation(i, j, "irisInt_" + charSequence);
} else {
Uniform.glBindAttribLocation(i, j, charSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private Program createProgram(ProgramSource source, ImmutableSet<Integer> flippe
}

// TODO: Don't duplicate this with FinalPassRenderer
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth"));
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "irisInt_centerDepthSmooth"));

Program build = builder.build();

Expand Down Expand Up @@ -442,7 +442,7 @@ private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet<In
}

// TODO: Don't duplicate this with FinalPassRenderer
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth"));
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "irisInt_centerDepthSmooth"));

programs[i] = builder.buildCompute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private Program createProgram(ProgramSource source, ImmutableSet<Integer> flippe
}

// TODO: Don't duplicate this with CompositeRenderer
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth"));
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "irisInt_centerDepthSmooth"));

Program build = builder.build();

Expand Down Expand Up @@ -426,7 +426,7 @@ private ComputeProgram[] createComputes(ComputeSource[] compute, ImmutableSet<In
}

// TODO: Don't duplicate this with FinalPassRenderer
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "iris_centerDepthSmooth"));
centerDepthSampler.setUsage(builder.addDynamicSampler(centerDepthSampler::getCenterDepthTexture, "irisInt_centerDepthSmooth"));

programs[i] = builder.buildCompute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ public IrisRenderingPipeline(ProgramSet programSet) {
WorldRenderingSettings.INSTANCE.setUseSeparateAo(programSet.getPackDirectives().shouldUseSeparateAo());
WorldRenderingSettings.INSTANCE.setVoxelizeLightBlocks(programSet.getPackDirectives().shouldVoxelizeLightBlocks());
WorldRenderingSettings.INSTANCE.setSeparateEntityDraws(programSet.getPackDirectives().shouldUseSeparateEntityDraws());
WorldRenderingSettings.INSTANCE.setPutInAlpha(!pack.hasFeature(FeatureFlags.SEPARATE_AO));

if (shadowRenderTargets != null) {
ShaderInstance shader = shaderMap.getShader(ShaderKey.SHADOW_TERRAIN_CUTOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public VanillaRenderingPipeline() {
WorldRenderingSettings.INSTANCE.setDisableDirectionalShading(shouldDisableDirectionalShading());
WorldRenderingSettings.INSTANCE.setUseSeparateAo(false);
WorldRenderingSettings.INSTANCE.setSeparateEntityDraws(false);
WorldRenderingSettings.INSTANCE.setPutInAlpha(false);
WorldRenderingSettings.INSTANCE.setAmbientOcclusionLevel(1.0f);
WorldRenderingSettings.INSTANCE.setVertexFormat(ChunkMeshFormats.COMPACT);
WorldRenderingSettings.INSTANCE.setVoxelizeLightBlocks(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String vsh(boolean hasChunkOffset, ShaderAttributeInputs inputs, F
if (isLeash) {
shader.append("flat ");
}
shader.append("out vec4 iris_vertexColor;\n");
shader.append("out vec4 irisInt_vertexColor;\n");
shader.append("uniform vec4 ColorModulator;\n");

// Vertex Normal
Expand All @@ -93,19 +93,19 @@ public static String vsh(boolean hasChunkOffset, ShaderAttributeInputs inputs, F
shader.append("in vec3 Normal;\n");

// minecraft_mix_light just passes through the original alpha value, so it's safe here.
main.append(" iris_vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, Normal, Color * ColorModulator);\n");
main.append(" irisInt_vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, Normal, Color * ColorModulator);\n");
} else if (inputs.isNewLines()) {
shader.append("in vec3 Normal;\n");
main.append(" iris_vertexColor = Color * ColorModulator;\n");
main.append(" irisInt_vertexColor = Color * ColorModulator;\n");
} else {
main.append(" iris_vertexColor = Color * ColorModulator;\n");
main.append(" irisInt_vertexColor = Color * ColorModulator;\n");
}
} else if (inputs.hasColor()) {
shader.append("in vec4 Color;\n");

main.append(" iris_vertexColor = Color * ColorModulator;\n");
main.append(" irisInt_vertexColor = Color * ColorModulator;\n");
} else {
main.append(" iris_vertexColor = ColorModulator;\n");
main.append(" irisInt_vertexColor = ColorModulator;\n");
}

// Overlay Color
Expand Down Expand Up @@ -162,9 +162,9 @@ public static String fsh(ShaderAttributeInputs inputs, FogMode fogMode, AlphaTes
if (isLeash) {
shader.append("flat ");
}
shader.append("in vec4 iris_vertexColor;\n");
shader.append("in vec4 irisInt_vertexColor;\n");

main.append("float iris_vertexColorAlpha = iris_vertexColor.a;");
main.append("float irisInt_vertexColorAlpha = irisInt_vertexColor.a;");

if (inputs.hasTex()) {
shader.append("uniform sampler2D gtexture;\n");
Expand All @@ -177,15 +177,15 @@ public static String fsh(ShaderAttributeInputs inputs, FogMode fogMode, AlphaTes
}

if (alphaTest == AlphaTests.VERTEX_ALPHA) {
main.append(" * vec4(iris_vertexColor.rgb, 1);\n");
main.append(" * vec4(irisInt_vertexColor.rgb, 1);\n");
} else {
main.append(" * iris_vertexColor;\n");
main.append(" * irisInt_vertexColor;\n");
}
} else {
if (alphaTest == AlphaTests.VERTEX_ALPHA) {
main.append("vec4 color = vec4(iris_vertexColor.rgb, 1);\n");
main.append("vec4 color = vec4(irisInt_vertexColor.rgb, 1);\n");
} else {
main.append("vec4 color = iris_vertexColor;\n");
main.append("vec4 color = irisInt_vertexColor;\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void bindFramebuffer() {
@Override
public Uniform getUniform(@NotNull String name) {
// Prefix all uniforms with Iris to help avoid conflicts with existing names within the shader.
Uniform uniform = super.getUniform("iris_" + name);
Uniform uniform = super.getUniform("irisInt_" + name);

if (uniform == null && (name.equalsIgnoreCase("OverlayUV") || name.equalsIgnoreCase("LightUV"))) {
return FAKE_UNIFORM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.primitives.Ints;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.irisshaders.iris.features.FeatureFlags;
import net.irisshaders.iris.gl.blending.AlphaTest;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
import net.irisshaders.iris.gl.blending.BufferBlendOverride;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static ExtendedShader create(WorldRenderingPipeline pipeline, String name
source.getTessControlSource().orElse(null),
source.getTessEvalSource().orElse(null),
source.getFragmentSource().orElseThrow(RuntimeException::new),
alpha, isLines, true, inputs, pipeline.getTextureMap());
alpha, isLines, true, pipeline.hasFeature(FeatureFlags.SEPARATE_AO), inputs, pipeline.getTextureMap());
String vertex = transformed.get(PatchShaderType.VERTEX);
String geometry = transformed.get(PatchShaderType.GEOMETRY);
String tessControl = transformed.get(PatchShaderType.TESS_CONTROL);
Expand All @@ -85,20 +86,20 @@ public static ExtendedShader create(WorldRenderingPipeline pipeline, String name
"Normal"
],
"uniforms": [
{ "name": "iris_TextureMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "iris_ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "iris_ModelViewMatInverse", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "iris_ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "iris_ProjMatInverse", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "iris_NormalMat", "type": "matrix3x3", "count": 9, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "iris_ChunkOffset", "type": "float", "count": 3, "values": [ 0.0, 0.0, 0.0 ] },
{ "name": "iris_ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] },
{ "name": "iris_GlintAlpha", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "iris_FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "iris_FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "iris_FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "irisInt_TextureMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "irisInt_ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "irisInt_ModelViewMatInverse", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "irisInt_ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "irisInt_ProjMatInverse", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "irisInt_NormalMat", "type": "matrix3x3", "count": 9, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "irisInt_ChunkOffset", "type": "float", "count": 3, "values": [ 0.0, 0.0, 0.0 ] },
{ "name": "irisInt_ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] },
{ "name": "irisInt_GlintAlpha", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "irisInt_FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "irisInt_FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "irisInt_FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{
"name": "iris_OverlayUV",
"name": "irisInt_OverlayUV",
"type": "int",
"count": 2,
"values": [
Expand All @@ -107,7 +108,7 @@ public static ExtendedShader create(WorldRenderingPipeline pipeline, String name
]
},
{
"name": "iris_LightUV",
"name": "irisInt_LightUV",
"type": "int",
"count": 2,
"values": [
Expand Down
Loading

0 comments on commit 6c3f273

Please sign in to comment.