Textures created from RenderingDevice ignoring depth

Godot Version

4.4.1stable

Question

I’m trying to create a 3d texture uniform for a compute shader, but it seems like even if i set texture’s depth > 1, it still creates a 2d texture with depth = 1:

	var rd: RenderingDevice = RenderingServer.create_local_rendering_device()
	var tex_format := RDTextureFormat.new()
	
	tex_format.format = RenderingDevice.DATA_FORMAT_R16_UNORM
	
	tex_format.width = 8
	tex_format.height = 8
	tex_format.depth = 8
	
	
	tex_format.usage_bits = \
	RenderingDevice.TEXTURE_USAGE_SAMPLING_BIT +\
	RenderingDevice.TEXTURE_USAGE_STORAGE_BIT +\
	RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT
	
	
	print(tex_format.depth)
	var texture: RID = rd.texture_create(tex_format, RDTextureView.new())
	print(rd.texture_get_format(texture).depth)

prints:

8
1

Why is that so? And how can I actually create a 3d texture for my compute shader?
Thanks in advance!

Looking at the RDTextureFormat docs, there’s a texture_type property that you don’t appear to be setting. That seems to be what specifies it:

That worked! Thank you very much

Just another question: How can I create a godot’s Texture3D from the one created in the script above?

I think you can pull that out of texture, since’ it’s a resource id.

Thanks again for the reply!
Have you got any tips about how to do that in practice?

RenderDevice.texture_3d_get() I would imagine, though I’ve not tried it.

You probably mean RenderingServer.texture_3d_get() instead of RenderDevice.texture_3d_get()
That totally makes sense! So silly of me not to have noticed it!
Again, thank you very much!

1 Like