I’ve got a question about the projectors, one thing I don’t get how and why the following problem happens.
Background: I got a map which I’d to draw a grid and highlight selectable tiles etc. I’ve managed to make the Grid projector work and show the grid correctly. But the tile highlighting part makes me some headache.
Currently I have for each time it’s own projector. It’s a plenty of projectors I know, but most of them are only active if a certain type of tiles need to be displayed (i.e. show all tiles with the attribute “Ground”).
The problem is, that each Projector which hits the Terrain (which is a mesh done in Blender by a friend), it will increase the Tri count by ~500 Tris. Problem is, with 184 active projectors (for 184 green highlighted tiles, out of 256 (its a 16x16 grid)), that makes 92.000 additional tris and drives up the tile count form 5000 to 105.000 Tris, which is pretty much, considering that it should work on mobile phones too.
The weird thing is, each tile projector hits exactly 2 tris (a tile consists of only 2 tris), but unity still creates much more additional Tris. I was assuming that the it would only “costs” where the projector hits the terrain and I really don’t know what happens internally when the projector hits it.
Is there a way to reduce this? Or any other, better solutions? I have looked for days for a solution and haven’t found a way how to highlight multiple tiles with a single projector or what else i could attempt.
So my thought is, if there is a way to fix this with a shader? But I have no real knowledge of shaders, but it should be possible to get the affected vertices and only compute these instead of the one of the whole mesh it hits, shouldn’t it?
Every projector that touches an object causes it to be re-drawn. It doesn’t matter how many triangles the projector is touching. So if you have an object with 100 tris, and you have 4 projectors on it, that’s 500 tris.
Assuming the tiles are different meshes you could always change the material color on the highlighted tiles and avoid projection all together. AFAIK they should still be able to batch fine with different colors as long as it’s the same material.
Well, currently the “tiles” only consists of a projector, a script and a help-mesh I use for tiles in the air (its the grid has up to 3 elevation levels. The help mesh is only visible when an air tile needs to be highlighted.
I’ve went for the projector attempt, because the tiles follow terrain quite nicely, while a mesh/plan for rendering only works for flat ground.
Yea, I guess I’ll have to try that. I just activated the 30 days Trial for unity and tried out my demo scene on Android and the results are horrible.
Android can handle one projector fine, 5 will drop the fps from 30 to ~25, 50 will make it absolutely unplayable (~6 fps in best case, and that’s without NPCs, Buildings).
ill just say that when you change material color this object is prevented from batching, cuz color changing makes instance of a material n it, and from then objects have different materials and are not batched.
so when highlightning finished you need to return old material to the tile. for that store a reference to it in temp variable (use sharedMaterial for temporary storing)
Whoops, he’s absolutely right - forgot I had to use a UV trick to “change the color” without changing the material or texture at all when I did something similar for an iOS project.
EDIT:
Note - this statement applies to the “individual game objects” situation, not the projector. The projector will double the draw calls and triangle count of everything it touches still though, like Eric said.
first you need a shader that can apply vertex colors - particle shaders fork for that for ex
then you get mesh filter component, to gain access to mesh vertices. then you change vertex colors, and apply them back to mesh. This trick can allow you change color/opacity of objects without increasing draw calls count.
Well, I suppose this trick is no good for complex meshes that have big amount of vertices, but I haven’t experimented with it
EDIT: maybe that is not the trick KyleStaves mentioned, but just another way of optimization =)