- Home /
Projecting a grid over a mesh
Hello everyone.
I'm having some problems trying to figure out how to project a grid over a mesh. To keep this simple, this is basically what I'm attempting to do: http://2.bp.blogspot.com/_EwDBFLRie5Q/SinU5hy0J2I/AAAAAAAAAHU/JyHdKz5SVjs/s1600-h/goodgrid.jpg
Projecting a grid over a terrrain but only where I want it to be projected, despite being parts of the same mesh (just like the picture).
This picture, as well as my initial idea on how to do this, comes from a topic in the unity forums where someone posted a script which did that creating the whole grid texture and using a small image where each pixel represented a tile (the black pixels represented where he didn't want to place a tile and the white ones, where there should be one). Then with a simple script, he got a plain grid texture and deleted the tiles which corresponded to the black pixels of his (let's call it) tiny alpha map.
I found this to be a really good idea and I preety much understand how to do it, but I've found several problems and I want to discuss this after I start scripting it.
So, first of all, I'm not really familiar with projectors, nor the documentation was able to provide any help with that (I'm starting to get used to this...) and my question is, how can I get a "clear" projection as it's done on the image above? And by clear I mean that all the examples of projectors I've seen make the textures you project "fade off" and smooth and thus, not resulting into anything like this grid.
My second question is quite more relevant to what I'm trying to accomlpish. In my game I'm planning to have large maps, let's say, 200x200 tiles of average. I don't think the method I saw of doing this (the same I did explain) would work nicely with a projector, as I would need a grid image as large as the grid I want to display, and this might be a problem, I've done some calculations, and I'd be easily going over 2000x2000 pixels textures, which I think might cause performance problems. Am I right with this?
Other than that, I think it might be important to mention that I'm not planning into using a small alpha map. Rather than that, I'll be using the array where I've got stored my map info as data and checking wether a map tile equals "null" or doesn't. I don't think this would cause much trouble but it might be useful to someone in order to answer this.
Thank you very much! ^^
Answer by tomekkie2 · Dec 30, 2012 at 12:46 PM
To get an effect like that on the linked picture I would divide the whole mesh into the submeshes, basing on the average vertices y coordinates on the mesh triangles, and then would apply separate materials, with one of them containing the grid texture. In order to do that you need to use a shader capable to accomodate multiple textures like decal for the material containing the grid texture.
Well, what I'm actually trying to accomplish is to display the gird on a given point only if I want to, and that condition is based on an input file (or an array in memory, I still don't know), not on the mesh vertices height. This would work on the picture i linked, but my map might be flat and I still would want to not display the grid on a given group of tiles, so I'm afraid this might not be what I'm looking for.
I think this should work this way as long as you can deter$$anonymous$$e the mesh triangles where you like this to happen and the mesh has a flat uv mapping
Just as $$anonymous$$e says, basically use more than one texture, one way or another.
You know, the absolutely best way to do something like this could be with a ("slightly") modified shader that either adds or does not add the grid, depending on some value.
You'd need a shader expert though! :)
Yes, I was thinking as well on modifying a shader but that might be a little tricky. I understand what you meant on the triangles method, and it might work as well. I'll keep investigating
Well, I don't think I have the time right now to get myself into program$$anonymous$$g shaders. It seems like a whole new world to me, so I'll stuck into the other possibilities. Just to make it clear, would it be that costly to use a very big (and by big I mean 2000x2000) grid texture to cover the whole map with an ortographic projector? I've found a nice shader surfing the Unity forums which can easily help me to do the rest, but I'd need large texture files to make it work. To clear that even more, my grid texture isn't going to have any fancy effects, just black and white pixels for$$anonymous$$g a nice grid shape, I don't really need more than that. Also, creating that texture programatically is going to hurt any performance of my game? I'm not planning to modify this on runtime, just on load.
EDIT: Well, it seems I've been missing the obvious. If I don't need at all my grid to be generated at runtime, i could just set it in the scene and forget about programatically editing textures, i could even use paint. I don't think a couple of grid textures would hurt much the game's size more than this would have hurt performance. Until I find a good way to do this with shaders I'll stuck to the easy way. I'll mark this as answered