this is my first post in this stack exchange!

I was wondering how I would go about mapping the texture of my tiles for my tilemap directly to the texture atlas.

I generate the mesh with unique vertices per tile to circumvent having to generate a Texture2D in memory to map all the squares to. I know it's possible to map the uv coords of the vertices to the texture like in the image below, since I have unique vertices per square. But I have no idea how to actually do it in my code. I tried just filling the uv array with random values between 0 and 1 to see if it worked at all but I just get a green mesh, no other colours in there.

Amazing Paint Skills

Does anyone know a way to implement this?

  • 1
    \$\begingroup\$ Myself, I like doing this via a tile index texture, so I don't need to set up 4 vertices & 6 indices per tile - a single pixel of the index map suffices, and the whole map can be rendered on a single quad. \$\endgroup\$ – DMGregory Sep 4 '18 at 12:55
  • \$\begingroup\$ Ah that could work, but I want to implement procedural terrain generation as well later on which is why I don't think I can apply that to this usecase \$\endgroup\$ – Pim Schwippert Sep 4 '18 at 13:07
  • \$\begingroup\$ did you find the answer? \$\endgroup\$ – Marcelo Filho Mar 8 '19 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.