The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

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.

in Engine by (25 points)

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.create(1, 1, 3, Image.FORMAT_RGB8)

# create the image object that should be inserted into the textureArray
var image =
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 )

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 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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.