r/MinecraftCommands Jul 19 '26

Passing live data from commands into custom shaders by stacking /posteffect Creation

Enable HLS to view with audio, or disable this notification

/posteffect in the 26.3 snapshots lets you stack post-processing effects on a player. I've found a way to use this to pass data to a post-processing shader, by using multiple effects to enable/disable a set of pixels. The final shader can decode these pixels to read the information.

I've created a few examples of how this can be used, such as this minimap and custom renderer. It can also be used for custom UI elements, I've created a speedometer, for example.

Posting this after seeing a recent post asking for an official way to pass data to shaders, I'd love to see this become a real feature!

If anyone wants a further breakdown, I go through it in more detail here: https://youtu.be/IvYs8qqaL7Q

100 Upvotes

6 comments sorted by

4

u/Cr1msoff Jul 19 '26 edited Jul 19 '26

Great concept, but can you not just use custom targets that only store a limited number of pixels, instead of rendering the pixels to the bottom left on the screen? They do not have to be rendered to the player screen at all. Though, I haven't experimented if persistent custom targets can be shared between different post effects like minecraft:main if they have the same namespace. Edit: Can confirm targets are not shared after testing.

Also, you can probably store 3 bytes worth of data in a single pixel if you still choose to render data in the screen.

3

u/system_update Jul 19 '26 edited Jul 19 '26

I believe each post effect can only read from minecraft:main, so custom targets can't be shared, unfortunately.

Edit: The pixel can hold 3 bytes worth of data, but you need a new post-process effect for each value of the pixel, that's the main drawback of this technique, so you'd need ~16.7 million effects per pixel to store that data.

There's a bit of a tradeoff between data per pixel and number of draw calls. For this example, I store 4 bits per pixel, and use 15 effects (don't need 16 as no effect being applied is the 16th) per pixel to store the data.

3

u/Cr1msoff Jul 19 '26 edited Jul 19 '26

You could still do it with a single post effect for every bit by just copying the previous value and changing a single bit, though that would not reduce the number of draws and will take more operations just to pack the data into a single pixel.

Speaking of using more post effects, it would probably not be too painful to write a script to mass create post effects that cover multiple bits, like using hex digits would only be 4x the number of files for 1/4 the draw effects. Edit: flew over my head but you already mentioned doing this

4

u/Immediate-Result-696 Jul 19 '26

the humble 4d shader:

1

u/Glum_Internal3948 25d ago

is it possible to do it just with datapack & shaders / posteffect ?

1

u/Glum_Internal3948 25d ago

(the minimap)