Passing a float array to shader

I’m attempting to pass a float array with size 1000 to material using

mat.setParam("TexCoords", VarType.FloatArray, array);

In my material definition, I have:

    MaterialParameters {
        TextureArray ColorMap
        Texture2D LightMap
        Color Color (Color)
        Boolean VertexColor
        Boolean SeparateTexCoord
        FloatArray TexCoords

        // Texture of the glowing parts of the material
        Texture2D GlowMap
        // The glow color of the object
        Color GlowColor

However, when I try to access the array from fragment shader, it contains nothing. I have defined it as

uniform float m_TexCoords[1000];

(which is similar to how ColorMap is defined, and ColorMap data is there for shader)

Any idea what could be wrong with this?

mhhh reminds me of an issue we had a long time ago…where float arrays couldn’t exceed 16 elements… I don’t remember if it’s been fixed.
That said… what is it you are trying to do? Looks like a very convoluted way for what I’m thinking you do.

bahaha what

when you passed them to a shader.

Well yes I get that part, just not sure on what could possibly cause such a thing.

a bug :stuck_out_tongue:

1 Like

If they are passed as uniforms to the shader the limits are set by the driver. If you are to pass that many values it is more common to pass them as a buffer or texture. But maybe that is what the material does so I might be just blowing smoke :slight_smile:

@jmaasing If the limit is hit, application just crashes. I tested with even larger arrays to be sure.

Anyway, I’m planning to use this for my voxel game. I have a combination of texture array and atlases (long story), and texture coordinates (3 floats per vertex) are taking quite a lot memory. Since texture coordinates are based on block material and not individually per vertex, I can reduce memory usage by storing only one int per vertex as array index which points to real texture coordinates in float array uniform.

I haven’t yet seen how effective is this due to this potential bug, but I anticipate that it would cut almost 1/3 of memory that texture coordinates take. Plus less data sent to GPU is better, right?

Any clues about where this potential bug originates? I would be interested in contributing a pull request to fix it.

Other approaches you can try instead of using giant float array material parameters (which won’t work for you):

-use bytes instead of floats for texture coordinates… this can work well if your atlas is nicely organized or if you are not even using an atlas (texture array or single textures)
-use math instead of an array lookup to convert from index to coordinate (that’s the most common way I guess)

The first one also works well if you have a mesh per texture instead of using an atlas or texture array. You can probably get away with two bytes per vertex either way.

Thanks for advise! Your idea seems way better than mine, considering both code complexity and hitting all the bugs.