Skip to content

Commit

Permalink
compatible with sodium:mc1.20.1-0.5.1, only for fabric, rubidium is n…
Browse files Browse the repository at this point in the history
…ot supported at this commit
  • Loading branch information
zomb-676 committed Aug 14, 2023
1 parent dbafef4 commit 58aea1a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ public static String RbVVSHInjection(String s) {
""").toString();
s = new StringBuffer(s).insert(s.lastIndexOf("void main()"), getLightShader()).toString();
s = new StringBuffer(s).insert(s.lastIndexOf('}'), Services.PLATFORM.useLightMap() ? """
v_Color = color_light_uv(position, v_Color, _vert_tex_light_coord);
v_ColorModulator = color_light_uv(position, vec4(v_ColorModulator, 1.0), ivec2(_vert_light) * 16 ).rgb;
""" : """
v_Color = color_light(position, v_Color);
v_ColorModulator = color_light(position, vec4(v_ColorModulator,1.0) * 16).rgb;
""").toString();
s = new StringBuffer(s).insert(s.lastIndexOf("}"), """
isBloom = float(_vert_tex_light_coord.x);
isBloom = ((_vert_material >> 4u) & 0x01u) > 0u ? 256.0 : 0.0;
""").toString();
return s;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ private static String BloomMRTFSHInjection(String s) {
}

public static String RbBloomMRTFSHInjection(String s) {
s = new StringBuffer(s).insert(s.lastIndexOf("in vec4 v_Color;"), """
s = new StringBuffer(s).insert(s.lastIndexOf("in vec3 v_ColorModulator;"), """
in float isBloom;
""").toString();
s = new StringBuffer(s).insert(s.lastIndexOf("void main()"), """
out vec4 bloomColor;
""").toString();
s = new StringBuffer(s).insert(s.lastIndexOf('}'), """
if (isBloom > 255.) {
bloomColor = fragColor * smoothstep(u_FogEnd,u_FogStart,v_FragDistance);
bloomColor = out_FragColor * smoothstep(u_FogEnd,u_FogStart,v_FragDistance);
} else {
bloomColor = vec4(0.);
}
Expand Down
4 changes: 2 additions & 2 deletions Fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ dependencies {
include("me.shedaniel.cloth:cloth-config-fabric:$cloth_config_version")

// Sodium
modImplementation("maven.modrinth:sodium:mc1.20.1-0.5.0") {
modImplementation("maven.modrinth:sodium:mc1.20.1-0.5.1") {
exclude(group = "net.fabricmc.fabric-api")
}

modImplementation("maven.modrinth:iris:1.6.5+1.20.1") {
modImplementation("maven.modrinth:iris:1.6.7+1.20.1") {
exclude(group = "net.fabricmc.fabric-api")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.lowdragmc.shimmer.client.shader.ShaderSSBO;
import com.lowdragmc.shimmer.comp.iris.IrisHandle;
import com.lowdragmc.shimmer.core.mixins.MixinPluginShared;
import com.lowdragmc.shimmer.fabric.core.mixins.iris.ShaderStorageBufferAccessor;
import net.coderbot.iris.gl.buffer.ShaderStorageBuffer;
import net.irisshaders.iris.api.v0.IrisApi;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -56,17 +57,17 @@ public void updateInfo(Object buffers) {
var oldBuffer = suffers[finalLightBufferIndex];
lightBuffer.createBufferData(oldBuffer.getSize(), GL46.GL_DYNAMIC_COPY);
lightBuffer.bindIndex(oldBuffer.getIndex());
oldBuffer.destroy();
suffers[finalLightBufferIndex] = new ShaderStorageBuffer(lightBuffer.id, oldBuffer.getIndex(), oldBuffer.getSize());
((ShaderStorageBufferAccessor)oldBuffer).callDestroy();
suffers[finalLightBufferIndex] = new ShaderStorageBuffer(lightBuffer.id, ((ShaderStorageBufferAccessor)oldBuffer).getInfo());
}
var envBuffer = new ShaderSSBO();
{
var oldBuffer = suffers[finalEnvBufferIndex];
envBuffer.createBufferData(oldBuffer.getSize(), GL46.GL_DYNAMIC_COPY);
envBuffer.bufferSubData(0,new int[8]);
envBuffer.bindIndex(oldBuffer.getIndex());
oldBuffer.destroy();
suffers[finalEnvBufferIndex] = new ShaderStorageBuffer(envBuffer.id, oldBuffer.getIndex(), oldBuffer.getSize());
((ShaderStorageBufferAccessor)oldBuffer).callDestroy();
suffers[finalEnvBufferIndex] = new ShaderStorageBuffer(envBuffer.id, ((ShaderStorageBufferAccessor)oldBuffer).getInfo());
}
suffers[finalLightBufferIndex].bind();
suffers[finalEnvBufferIndex].bind();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lowdragmc.shimmer.fabric.core.mixins.iris;

import net.coderbot.iris.gl.buffer.ShaderStorageBuffer;
import net.coderbot.iris.gl.buffer.ShaderStorageInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(ShaderStorageBuffer.class)
public interface ShaderStorageBufferAccessor {
@Invoker void callDestroy();
@Accessor ShaderStorageInfo getInfo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lowdragmc.shimmer.fabric.core.mixins.sodium;

import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.impl.CompactChunkVertex;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = CompactChunkVertex.class, remap = false)
public abstract class CompactChunkVertexMixin {
@Shadow
private static int encodeDrawParameters(Material par1, int par2) {
throw new RuntimeException();
}

@Redirect(method = "lambda$getEncoder$0", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/impl/CompactChunkVertex;encodeDrawParameters(Lme/jellysquid/mods/sodium/client/render/chunk/terrain/material/Material;I)I"))
private static int injectMaterialForBloom(Material material, int i, long ptr, Material material1, ChunkVertexEncoder.Vertex vertex, int sectionIndex) {
var origin = encodeDrawParameters(material,i);
if ((vertex.light & 0x100) != 0) {
origin |= (0x01 << 4);
}
return origin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ private void injectCompilePre(Camera camera, Viewport viewport, int frame, boole
int left = LightManager.INSTANCE.leftBlockLightCount();
FloatBuffer buffer = LightManager.INSTANCE.getBuffer();
buffer.clear();
var chunkrenderListIterator = ((RenderSectionManagerAccessor) renderSectionManager).getRenderLists().sorted();
var chunkrenderListIterator = ((RenderSectionManagerAccessor) renderSectionManager).getRenderLists().iterator();
while (chunkrenderListIterator.hasNext()) {
if (left <= blockLightSize) break;
var chunkRenderList = chunkrenderListIterator.next();
var region = chunkRenderList.getRegion();
var sectionIterator = chunkRenderList.sectionsWithGeometryIterator(false);
if (sectionIterator == null) continue;
while (sectionIterator.hasNext()) {
var section = region.getSection(ChunkRenderList.unpackIndex(sectionIterator.next()));
var section = region.getSection(sectionIterator.nextByteAsInt());
if (section == null) continue;
if (left <= blockLightSize) break;
if (section instanceof IRenderChunk shimmerRenderChunk) {
Expand Down
2 changes: 2 additions & 0 deletions Fabric/src/main/resources/shimmer.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"ShaderInstanceMixin",
"sodium.BlockRendererMixin",
"sodium.ChunkBuilderMeshingTaskMixin",
"sodium.CompactChunkVertexMixin",
"sodium.FluidRendererMixin",
"sodium.RenderSectionManagerAccessor",
"sodium.RenderSectionMixin",
"sodium.ShaderChunkRendererMixin",
"sodium.ShaderLoaderMixin",
"sodium.SodiumWorldRendererMixin",
"iris.ShaderPropertiesMixin",
"iris.ShaderStorageBufferAccessor",
"iris.HeldItemSupplierMixin",
"iris.ShaderStorageBufferHolderMixin",
"iris.StandardMacrosMixin"
Expand Down

0 comments on commit 58aea1a

Please sign in to comment.