Implementing dct shader in godot

Godot Version

4.7.1.stable

Question

Hi, I’m working on a project where I’ve successfully replicated most of the datamoshing artifacts that come from an error in JPEG compression. It’s really good, but it’s missing the default JPEG compression artifacts that digital media nowadays almost ubiquitously have.

I have found this implementation in glsl that works flawlessly (at least enough to sell the effect), but I’m running into some issues when actually implementing it in engine.

I’m not finding documentation about this anywhere (because it probably doesn’t exist yet, as the compositor is a very niche and recent), but how do I properly work with textures versus images in glsl when it comes to godot?

I know an image is passed differently compared to a texture, as images are image2Ds and textures are sampler2Ds, but what is the texture equivalent of an imageStore? Can I even pass a frame to a compute shader with a binding of type sampler2D?

Again, I would’ve just researched these questions more, but I simply didn’t find the material I’m looking for. Even if I learn more glsl, that wouldn’t answer me on how to properly do this on godot specifically. I tried doing that, and I still don’t know exactly why passing a depth texture needs to be a sampler2D, and a frame needs to be an image2D, or if they actually need to be those formats at all.

Like, I would love to just do this on my own, without this many questions, but I just can’t find material to study on the topic, my google searches don’t yield anything valuable…

If anyone could help me, it’d be much appreciated. I really hate making this many questions, but it’s my last resort, to come here. I hope someone can help me here…

Tried implementing the shader as is, without really understanding it. Didn’t go so well…


There isn’t any. Textures are read-only. The other differences are that textures can be sampled (UVs in 0-1 range, interpolation, repetition, automatic mipmaps etc…). With images you can only read/write pixels directly.

Can I pass the main view texture as a texture instead of an image? Is it as simple as assigning a sampler to the bind?

Yes. The simplest way is to declare a sampler2D uniform in the shader and set the uniform type in bound RDUniform to UNIFORM_TYPE_SAMPLER_WITH_TEXTURE.