#Enchanted handheld item silhouette effect rendering

8 messages · Page 1 of 1 (latest)

sly lintel
#

I am looking to create the Minecraft Bedrock's Actions and Stuff enchantment outline (photo for reference) as a mod. I was wondering how I can set up the code to
use a shader when it detects a handheld item. I was attempting to create a framebuffer for it, but I am not really sure what I am doing (esp for 1.21.5). Here is what I got so far if anyone can help (questions in code below, but any help is greatly appreciated)!

    @Shadow @Final private MinecraftClient client;
    @Unique
    private static int
            width = MinecraftClient.getInstance().getWindow().getFramebufferWidth(),
            height = MinecraftClient.getInstance().getWindow().getFramebufferHeight();

    @Unique
    private static final SimpleFramebuffer enchantedItemFBO = new SimpleFramebuffer("enchanted_fbo", width, height, true);

    @Inject(method = "renderItem(" +
            "FLnet/minecraft/client/util/math/MatrixStack;" +
            "Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;" +
            "Lnet/minecraft/client/network/ClientPlayerEntity;I)V",
            at = @At("HEAD"))
    private void beforeRender(
        float tickProgress,
        MatrixStack matrices,
        VertexConsumerProvider.Immediate vertexConsumers,
        ClientPlayerEntity player, int light,
        CallbackInfo ci
    ) {

        ItemStack MainHand = player.getMainHandStack();
        ItemStack OffHand = player.getOffHandStack();
        if ((MainHand != null && MainHand.hasGlint()) ||
            (OffHand != null && OffHand.hasGlint())) {

            enchantedItemFBO.initFbo(width, height);

            RenderSystem.getDevice().createCommandEncoder().createRenderPass(colorAttachment, OptionalInt.empty());

            //TODO: HOW DO I MAKE IT READ .vsh / .fsh / .glsl file (in the correct order) here. 
            // 1. Is this the right method to inject? Will this work while the item is swinging?
            // 2. Is at = @At("HEAD") the right one?
            // 3. I read somewhere that  WorldRenderEvents.AFTER_ENTITIES.register to be used but I am not sure. 
        }
    }

halcyon sedge
#

did you get this working? I didn't know someone else was trying to do this

halcyon sedge
#

I got the outline but have not touched shaders yet so it's a bit of a mess

sly lintel
#

how were u able to outline the items without core shaders? Esp items that have a lot of edges like the sword where its visible if you would use the default face culling that can be improved with texture pack?

halcyon sedge
#

I mixed into minecraft rendering method, and as it draws a quad, I draw an inverted quad scaled up at that location

#

The problem with doing it this way is now I need to make sure it runs with something like sodium, which it doesn't at the moment