- Home /
Best way to project a grid onto unity terrain
I'm trying to produce exactly this effect (the grid over the terrain) with unity and the terrain editor:
The tiles need to be highlightable, so it needs to be somehow dynamic. Also, as you can see, I don't want all the terrain to be covered in hexagons, so I need to be able to select which hexagons are there.
I've tried with a projector, but projectors and unity terrain don't seem to behave well together: When approaching with a camera to the projected grid, some chunks just disappear, not covering all of the terrain. Unfortunately there doesn't seem to be a good way for the projector not to tile its pattern all over the mesh, so I feel like this isn't the way to go as all of the terrain would be covered in hexagons. There doesn't seem to be a good way to highlight tiles either.
Using a directional light with a cookie gives me even less control over the grid, as I can't even edit the shader to achieve a better effect (painting rather than lighting). I should mention I had to do that in order for the projector to project a grid, and not a grid-ish light/shadow. Taking all that into acount, I've also discarded this method.
I know this is doable (just see the pic), and I really doubt this can't be done with Unity, so I'd like to know what's the way to go, in a general way.
I just thought I could create a custom shader taking an array of integers encoding the grid I intend to render (I could pass it to the graphics card as a texture, for example), and just paint hexagons according to that in the fragment shader. But before digging into this I'd like to know all the possibilities I have as modifying unity's terrain shader is completely out of scope for me...
So that's my question: How would I go into creating that effect? No matter how, but I want it to be done and to do it right, no weird workarounds like creating a grid mesh. I'm just doing this for fun and learning purposes and I want to do it like that.
Thank you!
DISCLAIMER:
So far I've tried all I've seen around Unity forums, and there doesn't seem to be a single user that achieved this very effect, nor I could by trying what they did. So I'd like to kindly ask not to flag this as a duplicate with any of those posts or similar, I've really searched through the whole forums and answers page:
http://forum.unity3d.com/threads/grid-on-terrain-help.203872/
http://forum.unity3d.com/threads/terrain-grid.44365/
http://answers.unity3d.com/questions/442581/how-to-draw-a-grid-over-parts-of-the-terrain.html
http://answers.unity3d.com/questions/749161/project-an-hex-grid-on-a-non-flat-terrain.html
Sorry for the disclaimer and I will remove it upon request, but I've had bad experienxes with questions being unfairly flagged as duplicate so I prefer to do this beforehand.
sorry, this is not an answer but more of a question. Have you found something yet? I'm trying to do the same thing and I looked everywhere and even asked on the forum(without replies) but I can't seem to find anything useful. $$anonymous$$y current approach is to use a square mesh(i don't have an hexagonal grid) for every tile and to change its vertices to adapt it to the terrain, the problem is that if i want the tiles and the terrain to not intersect, i have to make more subdivisions to the square and also to rise it a bit off the terrain. I don't really like the result cause it becomes somewhat heavy and also not so good looking.
In the places I've seen hex-terrain-like settings, the underlying mesh is built off of vertices in a hex shape, and the resolution of the grid matches the size of the hex tiles. A terrain is a rectangular grid. You could write a script that creates a new hex mesh grid and use it in place of the terrain. Or you could have sections overlay the grid, but an overlay would not necessarily blend into the existing terrain at the edges.
Your answer
Follow this Question
Related Questions
Create squares and draw them on terrain 1 Answer
Tree color variation 0 Answers
Weird ring-shaped artifact on terrain around camera 1 Answer
Objects visible through terrain 2 Answers
3D Terrain or Mesh Grid 1 Answer