3
\$\begingroup\$

So for my game I need the ability to add a grid overlay over my tilemap. Now I don't think that making the grid with each cell being its own GameObject with some SpriteRenderer would be hard to do but I know it would be extremely inefficient. I was thinking about using a LineRenderer to draw the grid lines but I don't know how to make the cells have their own traits since they wouldn't be their own individual instance and more of a product of the grid lines. In my case, the cells need their own color and should all have the ability to be accessed individually and that's where I need your help. Do you guys have an idea on how to make this efficient?

\$\endgroup\$
  • \$\begingroup\$ Would this previous Q&A help in this regard? \$\endgroup\$ – DMGregory Feb 15 '18 at 18:34
  • \$\begingroup\$ Well since I lack all knowledge in shaders I don't know if I can use that exact technique but it does give me an idea of using a texture 2d and just drawing that over the screen potentially. \$\endgroup\$ – G3tinmybelly Feb 15 '18 at 18:51
0
\$\begingroup\$

You could make an array of structs with a struct for each cell, that includes the cell's grid coordinates and color. Then copy this into a vertex array for rendering so you have a vertex for each cell, and use a geometry shader to turn each vertex into a quad with its own color, and draw the whole grid as 1 object.

\$\endgroup\$
  • \$\begingroup\$ "Use a geometry shader" -- goodbye efficiency! :P \$\endgroup\$ – jhoffman0x May 1 '18 at 8:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.