Uniform Userdata In Custom Shader

In terms of custom shaders, it is mentioned here

https://docs.coronalabs.com/guide/graphics/customEffects.html#uniform-userdata

But it is not documented. It must be used though in the built in shaders as they take more than 4 params.

I could really use this as I need to get more data into the shader than the 4 standard params.

Any ideas?

Hello again!

I’m excerpting from a private Gist, but will see if it can’t be made public, or maybe it will be in the meantime. At one point these details were potentially in flux, but are basically frozen now.

Basically, where you would normally have vertex data, you would instead do

kernel.uniformData =

with the difference being that you also provide a type field.

Then in the kernels themselves you declare the uniform in the outer scope much like a varying, e.g. as

uniform P\_COLOR vec4 u\_UserData0; // pointLightColor

And some commentary to go with it:

Some explanation is due: You can declare up to 4 uniforms. They would be mapped to u_UserData0 - u_UserData3. You must declare them in kernels as shown. There are several acceptable types: “scalar”, “vec2”, “vec3”, “vec4”, “mat3”, “mat4”;

This will kill batching, so be careful with that.

I should have some stuff in this, which was a proof of concept of meshes. I think CalebP might have done something with it, but couldn’t find the links.

Hello!

Thanks for the reply. I will give it a try tonight.

If you can share anything I would be grateful, debugging the shaders is an almighty pain!

Ok I got it working. Thanks for the help.

Hello again!

I’m excerpting from a private Gist, but will see if it can’t be made public, or maybe it will be in the meantime. At one point these details were potentially in flux, but are basically frozen now.

Basically, where you would normally have vertex data, you would instead do

kernel.uniformData =

with the difference being that you also provide a type field.

Then in the kernels themselves you declare the uniform in the outer scope much like a varying, e.g. as

uniform P\_COLOR vec4 u\_UserData0; // pointLightColor

And some commentary to go with it:

Some explanation is due: You can declare up to 4 uniforms. They would be mapped to u_UserData0 - u_UserData3. You must declare them in kernels as shown. There are several acceptable types: “scalar”, “vec2”, “vec3”, “vec4”, “mat3”, “mat4”;

This will kill batching, so be careful with that.

I should have some stuff in this, which was a proof of concept of meshes. I think CalebP might have done something with it, but couldn’t find the links.

Hello!

Thanks for the reply. I will give it a try tonight.

If you can share anything I would be grateful, debugging the shaders is an almighty pain!

Ok I got it working. Thanks for the help.