I'm trying to generate textures using compute shaders and then render them without reading them back to the CPU, but I can't seem to figure out a way to bind the texture.
I've tried both of the following
var imageTexture = ImageTexture.create_from_image(img)
var tex_uniform = RDUniform.new()
tex_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_IMAGE
tex_uniform.binding = 0
tex_uniform.add_id(imageTexture.get_rid()) # Texture is not valid error
tex.texture = imageTexture
This says the texture is invalid. The other method I've tried is creating the texture directly from the rendering device but then there's no way to bind it to the material's texture:
var fmt = RDTextureFormat.new()
fmt.width = 200
fmt.height = 200
fmt.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UINT
fmt.usage_bits = (
RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT | RenderingDevice.TEXTURE_USAGE_STORAGE_BIT
)
rdtex = rd.texture_create(fmt, RDTextureView.new(), [])
var tex_uniform = RDUniform.new()
tex_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_IMAGE
tex_uniform.binding = 0
tex_uniform.add_id(rdtex)
tex.texture = rdtex # Cant assign a texture from RID
Am I missing something obvious or is this not possible at the moment?