#Texture as input to a uniform set for a CompositorEffect (Compositor-postprocessing).

1 messages · Page 1 of 1 (latest)

alpine skiff
#

Hey, I believe I'm trying to do something trivial but in the wrong way (I just started trying things with the Compositor), I'm trying to pass a texture with an RID as to use in a CompositorEffect class.

I set the texture with a preload:

@tool
extends CompositorEffect
class_name PostProcessDithering

[...]

var bayer8x8 := preload("res://addons/postprocessing/compositor/res/bayer8x8.png")

But when I try to pass the RID in the uniform set like (inside _render_callback):

var pattern_uniform := RDUniform.new()
pattern_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_SAMPLER_WITH_TEXTURE
pattern_uniform.binding = 0
pattern_uniform.add_id(linear_sampler)
pattern_uniform.add_id(bayer8x8.get_rid()) ## Error (line 94)
var uniform_set_1 := UniformSetCacheRD.get_cache(shader, 1, [ pattern_uniform ])

I got this error:

post_process_dithering.gd:94 @ _render_callback(): Texture (binding: 0, index 0) is not a valid texture.
post_process_dithering.gd:94 @ _render_callback(): Condition "rid.is_null()" is true. >  post_process_dithering.gd:94 @ _render_callback()
post_process_dithering.gd:100 @ _render_callback(): Parameter "uniform_set" is null.
post_process_dithering.gd:102 @ _render_callback(): Uniforms were never supplied for set (1) at the time of drawing, which are required by the pipeline.

To me it seems I'm retrieving the RID incorrectly? How I'm supposed to do it? Is it possible or I'm hitting a limitation in the compositor?

Thank you.

gloomy nexus
#

dont you need to convert it to the correct class?

alpine skiff
#

I think I have to use RenderingDevice.texture_create

gloomy nexus
#

found something better

#

“An Image cannot be assigned to a texture property of an object directly (such as Sprite2D.texture), and has to be converted manually to an ImageTexture first.”

alpine skiff
#

I think i did it... just now. I don't think an ImageTexture2D will work because it's still a "complex type" above the RenderingServer

#

It's still a Texture2D

#

it's still an "invalid rid", it's not a "real" texture

#

here is what i just found out:

#
func _init() -> void:
    effect_callback_type = EFFECT_CALLBACK_TYPE_POST_TRANSPARENT
    rd = RenderingServer.get_rendering_device()
    RenderingServer.call_on_render_thread(_initialized_compute)
    
    ## // Loading texture
    var tf := RDTextureFormat.new()
    var godot_img_format = bayer8x8.get_image().get_format()
    tf.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UNORM
        
    tf.height = bayer8x8.get_height()
    tf.width = bayer8x8.get_width()
    tf.usage_bits = RenderingDevice.TEXTURE_USAGE_SAMPLING_BIT
    tf.samples = RenderingDevice.TEXTURE_SAMPLES_1
        
    var tv := RDTextureView.new()
    var img_data := bayer8x8.get_image().get_data()
    bayer_texture = rd.texture_create(tf, tv, [img_data])
#

I had to use the RenderingDevice.texture_create

#

copy the texture properties from Texture2D

#

like width, height, the format is a bit of a problem

#

only RGBA textures supports TEXTURE_USAGE_SAMPLING_BIT

#

so I had to change a project setting under: Rendering > Texture > Force PNG, I had to set it to true

#

this will force the PNG format and produce an RGBA texture that will work

#

bayer_texture now is an RID

#

So i just do this:

pattern_uniform.add_id(bayer_texture)

And it works!

gloomy nexus
#

wack

#

and we’re using the same language right? RID=resource ID?

alpine skiff
#

yes, it's the same type returned by get_rid()

#

from my understanding the problem is that with a Texture2D you get an RID that's not a texture (for the RenderingServer)