ModernGL / GLSL shader programming plugin

Introducing KritaModernGL, a plugin for Krita that allows programming vertex, fragment, and compute shaders and rendering the result to a new layer. The current selected layer can be used as an input to apply effects too!

Instructions and code
Download

The interface includes a box that will display any errors with the shaders for easy correction and iteration.

This is powered by the ModernGL python package, and uses your computer’s graphics rendering power to run!

Please let me know what you think, I will try to check this community more often, but GitHub might be better for reporting issues. I plan on using this as a base for recreating my old VFX plugin that’s been rather neglected


8 Likes

Hey, this is probably the ultimate gimmick, but something we definitely needed in Krita :smiley: TBH I always wanted to implement something like this, but never had the time. Such an addon could enable a lot of cool techniques, especially if it can read the colors of layers or projections, it would be like SeExpr on steroids!

Alas, it does not work on my system with Krita 5.3 :frowning:

In OpenGL mode I get a black screen (whole Krita window turns black) as soon as I run the pipeline.

In ANGLE (DX11) mode, I get the output layer, but in case of vs/fs example it’s pure black and in case of cs example it’s pure transparent.

I think this plugin has a tremendous potential (Shadertoy in Krita? Why yes please!) but needs much more testing and development to be robust enough. But I’m on board and have many improvement ideas :smiley:

BTW, here are my system specs:
Windows 11 24H2, AMD RX 7900 XTX 24GB, 25.5.1 driver

Yes, GLSL or WGSL would be more common languages than SeExpr. But getting the OpenGL working on all platforms is tricky thing. Thats why I have toyed with WebGPU as it is modern and has good backend support + supports GLSL & WGSL. One more alternative is SDL3.0 as it offers Vulcan context, without need to write 3k+ lines of code for management.

/AkiR

Yeah, your addon worked rather well, AkiR. To me this really gets interesting when it can interact with the layers, so that you can incorporate the shaders into your painting. It could be a neat way to do GPU accelerated filters, but there’s also a lot of hack value to play around with crazy ideas.

Thanks for the report, I’ve been testing with Krita 5.2.2 using D3D 11 via ANGLE on my Windows 11 machine with an Nvidia RTX 4090. I’d hate if this was a driver anomaly with AMD GPUs but its something I will need to investigate.

I had no idea about AkiR’s extension, though glad to see others find these things useful :slight_smile:

EDIT: I can confirm that using OpenGL as the preferred renderer for Krita will cause the whole window to become black… which is VERY not intentional. As for the example code it’s not clear if you tested it on a layer with some content or if you tried on an empty layer or a layer with only a single color. The results are most apparent on an existing image, and the compute shader example will only run on the first 1024x1024 pixels of the image. Will test on an AMD GPU (laptop with integrated graphics) later

Pushed an update to fix the black screen issue when using OpenGL as Krita’s rendering backend Release KritaModernGL - 1.0.1 · SockHungryClutz/KritaModernGL
Turns out Krita may be using some shared OpenGL context in this case and the ModernGL package will try to use any OpenGL context that already exists which can cause issues. Setting up a kind of fence fixed it :slight_smile:

2 Likes

Ah, couple other things I need to update in the documentation, you need to set the vertex shader to render 6 vertices for the render shader example and use 64 as workgroup X and Y sizes for the compute shader.

That said, I was unable to reproduce other reported issues on my laptop with AMD Radeon 760M graphics. I’ll update the documentation but let me know if there’s any other issues :slight_smile:

1 Like

Thanks for an update. It now works well for me in ANGLE (DX11) mode.

OpenGL still has a problem if the image is sufficiently large. For example, with A4 300 dpi (3508 x 2480 pixels), the Krita Window becomes black again (with a smaller white rectangle now) when the shaders are run.

I also tried running it on Ubuntu 24.04, but it failed probably because a binary was missing:

kritamoderngl.kritamoderngl:No valid GLContext build found, attempted: glcontext-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64

Maybe someone else can check if they can get OpenGL to work on their end. I didn’t debug it further to see what specifically may be wrong.

NB: I think Krita will eventually settle on ANGLE as the only supported GL implementation, which perhaps will make it easier to ensure compatibility.

Thank you for being a(n) (in)voluntary tester, I need to set up a Linux test environment for more testing…

  • Fixed Linux not finding the GLContext binary, the platform string is different between GLContext and ModernGL
  • Fixed issues with large images when using OpenGL renderer backend (probably). I was seeing hard crashes when reproducing this, it’s related to OpenGL context sharing. Toggling the framebuffer option in display settings seemed to affect this as well but should be fixed
1 Like

Excellent, thanks a ton for yet another update! :blush: Now I don’t see any issues on OpenGL on Windows and Linux, and even OpenGL ES on Linux is working fine!

I’m curious what are your plans for this addon going forward? Even in this barebones state this is really useful, as at the very least it can help implement a GPU-accelerated filter, such as chromatic aberration, or similar, which I think this is really neat!

If I were to suggest improvements, those would be around the ease of use and feature enhancements. Some examples:

  • related to reusability:
    • save shaders in the document (not sure if possible?), or
    • make it possible to load shaders from disk (maybe drag and drop?), or
    • add program presets that user can define, like a library of reusable filters; make it possible to export/import presets (lot of UI work, however)
  • multi layer inputs (btw, I see it can work on groups already, which is great!)
  • auto-detect the number of compute workgroups (dispatch size) from the layer/image size.

There’s probably a lot of other cool goofy stuff that could be done, but keeping it simple and focused also has merit, so I’m not going too wild with the suggestions :smiley:

Again, nice work, thanks!

Thank you again!

I don’t have many plans for future updates for this plugin, though usability improvements are good suggestions, like being able to save and load shaders from files. I had considered adding animation support by having a user-defined start and end time and either how large or how many steps in between, and render each frame to a new layer. But mostly my plans are to remake my old VFX plugin which has some easily configurable post processing filters like chromatic aberration and lens flares :slight_smile:

For now I’m fine with keeping this barebones, it does the job of being a little sandbox for shaders

1 Like