Archive 17/01/2023.

Troubles Setting attribute for a shader

GoogleBot42

Hello I cannot seem to set the MASK_OBJECTINDEX attribute for a shader. I am creating every vertex with this and it works just fine:

vertexData.Push(x); vertexData.Push(y); vertexData.Push(z);
vertexData.Push(0.5f);

The fourth is some data that I want to be the OBJECTINDEX.

Here is how I am setting the size of type of my vertex buffer (where VERTEX_SIZE is just 4)

vb->SetSize(vertexData.Size()/VERTEX_SIZE, MASK_POSITION | MASK_OBJECTINDEX);

Here is a simplified version my shader:

#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"

varying float vObjectIndex;

void VS()
{
    vec3 worldPos = GetWorldPos(iModelMatrix);
    gl_Position = GetClipPos(worldPos);

    vObjectIndex = iObjectIndex / 10000000000.0;
}

void PS()
{
    gl_FragColor = vec4(vObjectIndex, vObjectIndex, vObjectIndex, 1.0);
}

If I don’t have the 10000000000.0 in there the entire mesh I am rendering is completely white and including it makes the mesh a dark grey. Thus, even though every vertex should be a 0.5f it ends up being in the 10s of billions instead… there must be something strange I am doing here…

Is this even what iObjectIndex is meant to be used for? If not, how can I have a single float or 4 byte int (int is preferred) for every vertex?

Eugene

Are you sure OI is float? More likely it is something interger.
To prevent such errors, don’t use masks.

GoogleBot42

Yes. :confused: In Transform.glsl

....
    attribute vec4 iTexCoord6;
#endif
attribute float iObjectIndex;

#ifdef SKINNED
....

Ok… I guess I would use this instead?

bool SetSize(unsigned vertexCount, const PODVector<VertexElement>& elements, bool dynamic = false);

I really should be able to use the mask just fine though. The strangest thing is in similar code when I was passing UV coords and was using the MASK_TEXCOORD1 mask it was working just fine. :unamused: I guess I will look at that tomorrow but it is late where I live.

Thanks for you input, I didn’t know about the other SetSize function for the vertex buffer objects.

Eugene

It may be not enough since mask silently requires all attributes to have specified type and order. Position must be float3 and 1st, UV must be float2, color must be ubyte4… What must be ObjectIndex??
If you use VertexElement-s, all this stuff become explicit.

GoogleBot42

it looks like uou were right. it is a 32bit int

what is very strange about this is that it is a float in transform.glsl is this a bug?