Going back to chapter 9 as a reference, I want to paint a series of tiles (each with a different texture). The tiles are squares (44x44 each), but each vertex can have a different latitude (so y value).
So I modified the Primitive to:
case .plane:
return MDLMesh( planeWithExtent: [1, 1, 1], segments: [1, 1], geometryType: .triangles, allocator: allocator)
(and I plan to then translate them to position).
That works, other then the ability to set the y on each vertex differently. Is there a way to access the vertex buffer and modify the vertex y?
If it’s just a quad, you don’t need to send a mesh. You could define the two triangles for the quad in the vertex function. You could then do an instanced draw call of six vertices. Do you have the y available in the vertex function? Can you create a buffer of y
values and send it to the vertex function where you can modify the final position of the quad?
For an example of rendering a quad without mesh, see Chapter 7, The Fragment Function.
1 Like
Well, I have 40 x 40 set of “tiles”. Each tile is a quad of the same size. But the y (altitude) varies for each vertex , and each tile has a separate texture.
I need to be able to vary the y/texture dynamically for each tile.
I guess I could just pass in a buffer of y values, and in the shader adjust, along with the texture?
I still need to use the camera, and then will put models on top of this. (the 40x40 constitutes the “map” so to speak, and then I will have models (buildings/characters) on top of it. Basically the tiles represent an Isometric 2.5 map (but in 3D) by fixing the camera perspective. As the player walks (or the camera moves), I just update the y/texture for the 40x40 field.
Yes, that’s what I meant. In the buffer, hold the y value and if the textures are in an array, an index into the array for the texture.