Skip to content

Commit

Permalink
fix embeddium new api compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Yefancy committed Feb 18, 2024
1 parent d513c3d commit 0cd3325
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ public static String RbVVSHInjection(String s) {
return s;
}

public static String embeddiumVVSHInjection(String s) {
s = new StringBuffer(s).insert(s.lastIndexOf("out vec2 v_TexCoord;"), """
out float isBloom;
""").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, ivec2(_vert_tex_light_coord) * 16 ).rgba;
""" : """
v_Color = color_light(position, v_Color * 16).rgba;
""").toString();
s = new StringBuffer(s).insert(s.lastIndexOf("}"), """
isBloom = ((_material_params >> 4u) & 0x01u) > 0u ? 256.0 : 0.0;
""").toString();
return s;
}

public void bindRbProgram(int programID) {
lightUBO.bindToShader(programID, "Lights");
envUBO.bindToShader(programID, "Env");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ public static String RbBloomMRTFSHInjection(String s) {
return s;
}

public static String embeddiumBloomMRTFSHInjection(String s) {
s = new StringBuffer(s).insert(s.lastIndexOf("in vec4 v_Color;"), """
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);
} else {
bloomColor = vec4(0.);
}
""").toString();
return s;
}

public CopyDepthColorTarget getPostTarget(boolean hookColorAttachment) {
if (hookColorAttachment) {
if (postTargetWithColor == null) {
Expand Down
4 changes: 2 additions & 2 deletions Forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ dependencies {
forgeRuntimeLibrary("icyllis.modernui:ModernUI-Core:$modernui_core_version")
modCompileOnly("icyllis.modernui:ModernUI-Forge:${minecraft_version}-${modernui_version}")

modImplementation("maven.modrinth:embeddium:0.2.10+mc1.20.1")
modImplementation("maven.modrinth:oculus:1.20.1-1.6.9")
modImplementation("maven.modrinth:embeddium:0.3.4+mc1.20.1")
modImplementation("maven.modrinth:oculus:1.20.1-1.6.15a")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@
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.lwjgl.system.MemoryUtil;
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();
}

@Shadow
private static int encodeLight(int light) {
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);
@Redirect(method = "lambda$getEncoder$0", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/terrain/material/Material;bits()I"))
private static int injectMaterialForBloom(Material material, long ptr, Material m, ChunkVertexEncoder.Vertex vertex) {
var origin = material.bits();
if ((vertex.light & 0x100) != 0) {
origin |= (0x01 << 4);
}
return origin;
}

@Redirect(method = "lambda$getEncoder$0", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/impl/CompactChunkVertex;encodeLight(I)I"))
private static int injectLightForBloom(int light, long ptr, Material material1, ChunkVertexEncoder.Vertex vertex, int sectionIndex) {
@Redirect(method = "lambda$getEncoder$0", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryUtil;memPutInt(JI)V", ordinal = 1))
private static void injectLightForBloom(long ptr, int light) {
if ((light & 0x100) != 0) {
return 15 | 15 << 4;
light = 15 | 15 << 4;
}
return encodeLight(light);
MemoryUtil.memPutInt(ptr, light);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public abstract class ShaderLoaderMixin {
private static String transformShader(String shader, ShaderType type, ResourceLocation name) {
if (name.getPath().contains("block_layer_opaque")) {
if (type == ShaderType.FRAGMENT) {
shader = PostProcessing.RbBloomMRTFSHInjection(shader);
shader = PostProcessing.embeddiumBloomMRTFSHInjection(shader);
}
if (type == ShaderType.VERTEX) {
shader = LightManager.RbVVSHInjection(shader);
shader = LightManager.embeddiumVVSHInjection(shader);
}
}
return shader;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.lowdragmc.shimmer.forge.core.mixins.rubidium;

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.VanillaLikeChunkVertex;
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 = VanillaLikeChunkVertex.class, remap = false)
public abstract class VanillaLikeChunkVertexMixin {
@Shadow
private static int encodeDrawParameters(Material par1, int par2) {
throw new RuntimeException();
}

@Shadow
private static int encodeLight(int light) {
throw new RuntimeException();
}

@Redirect(method = "lambda$getEncoder$0", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/impl/VanillaLikeChunkVertex;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;
}

@Redirect(method = "lambda$getEncoder$0", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/impl/VanillaLikeChunkVertex;encodeLight(I)I"))
private static int injectLightForBloom(int light, long ptr, Material material1, ChunkVertexEncoder.Vertex vertex, int sectionIndex) {
if ((light & 0x100) != 0) {
return 15 | 15 << 4;
}
return encodeLight(light);
}
}
3 changes: 2 additions & 1 deletion Forge/src/main/resources/shimmer.forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"oculus.ProgramSetMixin",
"rubidium.CompactChunkVertexMixin",
"rubidium.ModelQuadUtilMixin",
"rubidium.ShaderStorageBufferAccessor"
"rubidium.ShaderStorageBufferAccessor",
"rubidium.VanillaLikeChunkVertexMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const val modernui_version = "3.7.1.3"

//Project
const val version_major = 0.2
const val version_patch = 3
const val version_patch = 4
const val semantics_version = "$minecraft_version-$version_major.$version_patch"
const val maven_path = "snapshots"
const val maven_group = "com.lowdragmc.shimmer"
Expand Down

0 comments on commit 0cd3325

Please sign in to comment.