Problem with Compositor shader texture loading

Godot Version

4.3

Question

(question may be moderately cursed)
Very specific problem with the new Compositor feature in Godot 4.3. I was working on a post-processing effect in 4.2 that used the depth texture in a shader and wanted to apply it to the Compositor, but I ran into a problem.

First, I used the example project here and added the depth texture by changing a few lines in the compute shader. This is the shader using the depth texture:

So that worked. I went to apply it to the test project I had doing shader stuff in 4.2 and copy/pasted the modified demo code, and ran into a problem. Trying the original demo shader works fine, but adding the depth texture gives the error:
“Image (binding: 1, index 0) needs the TEXTURE_USAGE_STORAGE_BIT usage flag set in order to be used as uniform.”

Looking into the documentation like here, it’s possible to set textures to be usable in shaders like this, but I can’t figure out how to do it since it requires this method which asks for strings and I don’t know what to set them to.

I don’t get why it would work in the example project but not in mine, since it’s not in any init scripts in the former. Maybe a project created in 4.3 has some under-the-hood changes on startup compared to 4.2?

Help would be appreciated. I would post the whole compute shader code, but it’s very very long and mostly the same as the demo, so this is a bit:

1 Like

Hi, I’m meeting the same thing, any one can help.

As of now, it is not possible to set the bit for the depth texture manually, Godot sets it when it needs it internally.
You can either:

  1. Use sampler2D instead of image2D. You will have to convert from screen coordinates to UVs, and for me this caused some side effects;
  2. Set the bit indirectly, for example by enabling MSAA in Forward+. This seems to be the configuration in the demo.