|Attention||Topic was automatically imported from the old Question2Answer platform.|
I want to combine a certain number of single images to a image array used in shader. There is a sampler2DArray datatype in shader, I wonder if there is a way to generate texture in such data format in godot, which could be used in shader.
If I interpret you correctly, then I think I’m kind of working on the same problem. I want to send several textures/images as uniform-input to the shader, which should allow me to provide each vertex with several inputs.
Here’s what I have thus far:
# load shader onready var myshader = preload("res://new_shader.shader") # create texture-array that can hold several images in "layers" var textureArray = TextureArray.new() textureArray.create(1, 1, 3, Image.FORMAT_RGB8) # create the image object that should be inserted into the textureArray var image = Image.new() image.create(1, 1, false, Image.FORMAT_RGB8) # add the image to the textureArray (this makes the image appear in all layers, which I don't understand why. I'm expecting it to only appear in layer 1...) textureArray.set_layer_data(image, 1) # get the object using the shader var mesh_material = get_node("MeshInstance").mesh.material#.get_shader_param("user_input") # set the shader-defined "uniform" parameter from GDScript mesh_material.set_shader_param("user_input", textureArray )
toblin | 2020-09-01 20:56
Thank you for replying. I didn’t make it clear, what I want to do is to save it to disk and load next time for use.
I created texture array in the same way, and I saved it using
ResourceFormatSaver.save(). I got a file much larger than the sum of all individual texture in file size, which couldn’t be loaded as a valid texture array.
At last I gave up, a combination of textures as a atlas texture could be another choice.
vanyousee | 2020-09-05 03:30