Get a free id or similar per vertex

Basically I’m working on a larger material for atlastextures.

Basic idea, I load 14 textures into one shader, containg all maps for all objects. Now I tell the shader wich map’s to use on a per vertex basis → the whole map can be combined into few larger geometrys.

As far as I understand it I need a way to pass the shader a value, however normaly shader values are only per geometry.

Now my idea would be to use the normal for selecting the right map, and regenerate the normal needed for correct rendering with the help of a normal map. Are there better ways to pass a value in a similar way ? Also are there any problems with the rendering if I have kinda random normals that get corrected in the vertex shader only?

I think there is a way to add a buffer to the mesh

Look at the TangentBinormalGenerator, it create a tangent buffer, and it once created a binormal buffer.

this was passed to the shader in attributes names inTangent, inBinormal per vertex.

the inBinormal is not used anymore maybe you can use it.

but it’s a bit hacky, maybe @Momoko_Fan has a better way to do this.

The preferred way would be to actually have 3D texture coordinates, and pass the texture to use in the Z coordinate. This way you’re also compatible with OpenGL texture arrays for which we might add support at some point

Well yeah the problem is since I need to be able to create batches, I need to pass the same values then or not? So basically the problem how to transmit a value depending on the mesh/vertex still remains or did I misunderstood you?

However I will take a look at the 3d textures as they sound like a more intelligent solution.

I’m not sure I understand your question, but texture coordinates are per vertex. 3D texture coordinates would therefore give you an extra value per vertex.

In my own shaders, I’ve also used the per-vertex color to pass values since I get four floats that I can attach to each vertex.

Ah I get it, so I define the texcoords with 3 values instead of 2 per vertex, So that I get one for my own use :wink:

damn I’m stupid, I just recognized that I just can use any values for the two 2d texture coordinates

So I can just say layer 1 is normal layer two is from texcoord 1,0 to 2,1 ect

There is absolutly no need to use a extra value if I just handle them like being next to each other

Yes you can do that, but wouldn’t it require using something like “mod” to get the texture ID?

Not at all, assuming I have 3 textures in teh shader, and i get the texture coordinate


It would need one compare if it is over 2, then i knw I can get the correct one with

2.5,x - 2,0 in the third texture

I assume that such kinda of calculations should be kinda fast. Also they can be done in the vertex shader already, no need to recalculate it for each fragment