The more I look at these last two posts, the less I understand them. Are you talking about uniform variables or tile-specific attributes?
A uniform variable is the same for every single vertex. The same value will be applied to all four vertices in tile 0, and all four vertices in tile 1, and so on.
One example of a uniform variable is the view matrix (basically, the camera). Every vertex is part of the same view, so every vertex gets the same matrix. Passing a separate copy of the matrix to every single vertex would be a total waste.
An attribute is a variable that only applies to one vertex. For instance, x
, y
, and z
have to be attributes, since you need distinct points to draw a shape.
Another example is velocity. If velocity was a uniform variable, then everything would move in the same direction at the same speed. (And if that’s all you want to do, you might as well just update the camera.) Usually, if you go to the trouble of defining a velocity variable, it’s because you want one object to move relative to other objects.
You can’t (easily) store the new position after moving an object, but velocity still has a valid use in a shader program. Specifically, it’s useful if you know a particle’s trajectory in advance. In a particle system, for instance, you might spawn particles, give them a velocity, and let them go forever.
In this particle system, you can calculate a particle’s exact position based on only three things: (1) its starting location, (2) its velocity, and (3) the time elapsed. (1) and (2) need to be attributes, but (3) could be uniform, since time passes at the same rate for all particles. Since a particle’s starting location and velocity never change, this means you only need to update one value every frame: the time elapsed.
Anyway, that’s just my attempt at explaining why you’d want a velocity
attribute. Sorry if it was a bit hard to follow, but the details weren’t my main point.
My main point is, if you want to define velocity
data, you’re going to want a separate velocity value for every single tile. And that’s why Joshua’s post confused me.
This appears to set a velocity
property for the entire Tilemap. But… that would make it a uniform value.
This implies that each Tile object has its own velocity
data, which is what I’d expect. However, this data is then assigned to the Shader object, again making it a uniform property.
There’s no way this structure can store a separate velocity
value for every tile.
shader.data.uVelocity.value = tile0.data.velocity;
shader.data.uVelocity.value = tile1.data.velocity;
shader.data.uVelocity.value = tile2.data.velocity;
You’ll just overwrite it each time, and every tile will end up with the final tile’s velocity. Either that or you run a draw
call for every tile, which defeats the point of Tilemap.