Sure.
Cpu part:
func makeTexture(width, vectors): # vectors is array of Color objects
var w = width
var h = max(w, int( floor(vectors.size() / w)) + 1)
var img = Image.new()
img.create(w, h, false, Image.FORMAT_RGBAF)
# put data into image
img.lock()
var x: int
var y: int
for i in range(vectors.size()):
y = i / w
x = i % w
img.set_pixel(x, y, vectors[i])
img.unlock()
var tex = ImageTexture.new()
tex.create_from_image(img)
return tex
var vectors = []
# fill vectors array with Color objects here
var texture = makeTexture(64, vectors)
material.set_shader_param("vectors", tex)
material.set_shader_param("vectorsTextureWidth", 64)
material.set_shader_param("vectorsCount", vectors.size())
Gpu part:
shader_type canvas_item;
uniform sampler2D vectors;
uniform int vectorsTextureWidth;
uniform int vectorsCount;
void fragment(){
for(int i=0; i<vectorsCount; ++i){
coord.x = i % vectorsTextureWidth;
coord.y = i / vectorsTextureWidth;
tex = texelFetch(vectors, coord, 0);
vec3 v = tex.xyz;
# v is your vector, do whatever you wish with it here
}
}
This code is not tested. I blindly cut stuff out and renamed some variables. So watch out. But this is it in principle.
EDIT: I forgot to put code in shader inside fragment() function. Corrected this now.
And have in mind this is highly inefficient. I was doing this only once at the startup. Updating texture each frame on the cpu and iterating through it for each pixel in the fragment shader could eat up a lot of frame time.