Palette tricks. How?

#1

Hey everyone, do you have any info/tips or techniques on manipulating palettes like in old 8/16 bit consoles or pico8? Looking for a way to do palette cycling and swapping mainly and working with a limited set of colors.

0 Likes

#2

First option is to read png from resources using imageloader extension, then manipulate it’s buffer to switch colors and apply such edited texture to a model or sprite.

Another option is to write a shader that would change colors on the GPU.

2 Likes

#3

If we could pass arrays to shaders instead of only vectors doing this kind of thing would be way easier. I think that’s coming… eventually… :slight_smile:

1 Like

#4

Better shader support the biggest thing I envy Unity. (Then it’s dynamic content generation and more supported platforms)

2 Likes

#5

For sure… but Defold is still better… once it has those things it will be the… King. :sunglasses:

5 Likes

#6

Heh. I see what you did there.

2 Likes

#7

Yeah it’s a bit annoying that uniform setting is so limited. We have an exploration day tomorrow so I might take a look at it. I was planning to look at setting a matrix as uniform as well.

7 Likes

#8

Whoa, whoa, here is a list of things I will be grateful if you take a look at: matrix uniform, gl_VertexID, tangent info from model, array uniform. Thanks!

3 Likes

#9

gl_VertexID is a bit tricky since it requires an es3 context unless you do it with vertex attributes or something similar (until we finish the Vulkan support which has this by default).

6 Likes

#10

So I explored the array uniform setting and user matrix constants. I can do something like:

// In shader
uniform vec4 tint[2];

// In main.script
sprite.set_constant("#sprite", "tint[0]", vmath.vector4(1,0,0,1))
sprite.set_constant("#sprite", "tint[1]", vmath.vector4(0,1,0,1))

Also, this works:

// In shader.vp
uniform mat4 my_matrix;
uniform mat4 my_matrix_array[2];

// In main script
sprite.set_constant("#sprite", "my_matrix, vmath.matrix4(...))
sprite.set_constant("#sprite", "my_matrix_array[0]", vmath.matrix4(...))
sprite.set_constant("#sprite", "my_matrix_array[1]", vmath.matrix4(...))

This should also work, but haven’t tested it:

// Shader
uniform mat4 my_matrix;
uniform mat4 my_matrix_array[MATRIX_COUNT];
uniform vec4 my_vector_array[ARRAY_COUNT];

// Script
go.set("my_matrix", vmath.matrix4(...))
go.set("my_matrix_array[0]", vmath.matrix4(...))
go.set("my_vector_array[0]", vmath.vector4(...))

… but as always, not sure if/when/how this can be added, I think it needs a proper design discussion first at least since it kinda requires a big change in our engine structures.

4 Likes

#11

Excited! For arrays can’t we use tables in go.set()? And automatically shift indexes under the hood.

2 Likes

#12

Maybe, but I don’t know how well that would mesh with our current property representation, I wouldn’t want to add too much complexity just to add functionality that you can wrap in a small function. But I’ll formalize this into a design and we’ll see :slight_smile:

4 Likes