Random UV of flipbook on particles (shader)

Godot Version

4.3 stable

Question

Classic thing.

I have an 8x8(tiles of 32x32 pixels) texture atlas.

I spawn a bunch of particles.

Each particle is a quad and should get a random tile from that 8x8 texture atlas.

I’ve tried INSTANCE_ID and INSTANCE_CUSTOM but both of them yield an error in my shader for me.


caption: I cant even get it to accept the statement…

.

What am i missing here? How would you normally utilize IDs to “shift” the UVs in an atlas? :no_mouth:

.

void fragment()
{
	int id = INSTANCE_ID;
	vec2 atlas_uv = flipbook(UV, vec2(TILING, TILING), TIME * FLIP_SPEED);//Speed is 0, so image stays put.
	vec4 atlas_result = texture(TEXTURE, atlas_uv);
	
	
	ALBEDO = atlas_result.rgb;
	ALPHA = atlas_result.a;
	ALPHA_SCISSOR_THRESHOLD = ALPHA_THRESHOLD;
}

doing this will yield particles that change from one tile to another, they will not stick to one…

arg
see. its just swapping between different uv offsets, which tell me INSTANCE_CUSTOM is not what im looking for.

void vertex() {
    id1 = round(INSTANCE_CUSTOM.x * 1.0);
	id2 = round(INSTANCE_CUSTOM.y * 1.0);
}

void fragment() {
	vec2 atlas_uv = flipbook(UV + vec2(id1,id2), vec2(TILING, TILING), TIME * FLIP_SPEED);//Speed is 0, so image stays put.
	vec4 atlas_result = texture(TEXTURE, atlas_uv);
	
	
	ALBEDO = atlas_result.rgb;
}