Oculus

Oculus

67M Downloads

Bug + Fix: Emissive layers on items do not render

Marco6789 opened this issue ยท 1 comments

commented

What happened?

Items which make use of emissive layers or fullbright light textures do not render those layers. This includes various modded items such as the the spears and zeal lighter from Blue Skies, or the 'Fiery' items from Twilight Forest (and likely many more from other mods). See also #215 and #485. This happens because these items use a shader from forge, 'EntityTranslucentUnlitShader', which is not overwritten by oculus. This causes everything normally rendered by that shader to become invisible when oculus' shaders are enabled.
I have managed to fix it by adding a new mixin. I would submit a pull request for this, but that redirects me to the iris repository for some reason. Since this is a forge specific fix, it would be useless there. So instead i will submit the fix this way.

The code is mostly copied from MixinGameRenderer.java, which redirects all other shaders. I have placed to code in the 'Additional Context' field below. Of course, the mixin must also be registered in mixins.oculus.json for it to work.

Some before and after screenshots are also added

Screenshots

2024-05-14_15 38 47
2024-05-14_15 34 17
2024-05-14_15 39 19
2024-05-14_15 36 17

Relevant log output

No response

Minecraft Version

1.18.2, 1.19.2, 1.20.1

Oculus Version

1.19.2-1.6.9

Rubidium / Embeddium Version

No response

Operating System

Windows 10

What is your GPU?

AMD RX 6950 XT

Java Version

Java 17

Additional context

package net.coderbot.iris.mixin;

import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.ShadowRenderer;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.pipeline.newshader.CoreWorldRenderingPipeline;
import net.coderbot.iris.pipeline.newshader.ShaderKey;

import net.minecraftforge.client.ForgeHooksClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;

import net.minecraft.client.renderer.ShaderInstance;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@mixin(ForgeHooksClient.ClientEvents.class)
public class MixinForgeTranslucentShader {

@Inject(method = {"getEntityTranslucentUnlitShader"}, at = @At("HEAD"), cancellable = true, remap = false)
private static void iris$overrideForgeTranslucentShader(CallbackInfoReturnable<ShaderInstance> cir) {
    if (ShadowRenderer.ACTIVE) {
        override(ShaderKey.SHADOW_ENTITIES_CUTOUT, cir);
    }
    else if (shouldOverrideShaders()) {
        override(ShaderKey.ENTITIES_TRANSLUCENT, cir);
    }
}

private static boolean shouldOverrideShaders() {
    WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

    if (pipeline instanceof CoreWorldRenderingPipeline) {
        return ((CoreWorldRenderingPipeline) pipeline).shouldOverrideShaders();
    } else {
        return false;
    }
}

private static void override(ShaderKey key, CallbackInfoReturnable<ShaderInstance> cir) {
    WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();

    if (pipeline instanceof CoreWorldRenderingPipeline) {
        ShaderInstance override = ((CoreWorldRenderingPipeline) pipeline).getShaderMap().getShader(key);

        if (override != null) {
            cir.setReturnValue(override);
        }
    }
}

}

commented

Everything seems to be working now.