brnkhy / MapzenGo

Pokemon Go clone using Unity3D & Mapzen/OpenStreetMap
http://www.barankahyaoglu.com
MIT License
198 stars 59 forks source link

Can objects (roads, buildings) be textured? #31

Closed johnsnook closed 7 years ago

johnsnook commented 8 years ago

This may be totally due to my ignorance of unity materials and textures, which is vast, but I can't seem to get a textured material to render properly on roads or buildings.

Sorry to create an "issue" out of it, Baran.

brnkhy commented 8 years ago

No problem man ;) I'll give a tldr first; the problem is the UV generation. (I'm not expert on UVs or materials by the way so might be missing some stuff)

Road UV's should be quite easy really, I can easily do that. Landuse UV is harder, not sure about those. Water is extremely easy as well. But the real problem is the building UVs

I did a little experiment on building UVs last night; http://imgur.com/AFZBScY It's such a huge issue though, would take quite a few paragraphs to describe it here. First of all, we can't use same texture for everything so we'll have to copy materials and change textures. then we'll have to divide mesh into to, roof & sides to be able to use repeating properly. If we decided not to go repeating textures (the image above uses that), we'll need extra vertices everywhere, especially on side walls. I feel like the first option would be much easier but that's still require quite an effort. I'll most likely publish that repeating UV thing in the image just for simple usage (noisy texture instead of pure color would made everything look better for example) but a real solution would take soo much time. If there's anyone interested (and a little bit experienced in vertex/UV math) in that, I can tell the whole story for a head start.

Roads would be easy as I said, but they'll look ugly even if I do the UVs as they are disconnected in most place. And that's the osm data, not my generation code so cannot really fix that without huge effort either :(

I fucking love working with vertices, indices, triangles,uvs or generating meshes in general but damn they take sooo much time.

Still, as I said, I can get roads and water UV working in a day I believe.

johnsnook commented 8 years ago

Well, I've been enjoying looking through your code in the various factories for inspiration. I can certainly appreciate the amount of effort. I know zip about UVs though. I'll try to do some research and see if I can get up to speed fast enough to be of any use.

brnkhy commented 8 years ago

I pushed the simple UV thing on dev branch last night, it's in the building factory (that should be tidied up though, that function is a total mess, hard to read and confusing at the moment) what it does is simply applying that texture in every 1unit square area. That's like the simplest thing one can do, hardly any uv calculation/math there. But that's actually one of the better ways to do it BUT we need roof as a separate entity/material for that. We can do that repeating texture thing in side walls but same texture wont work for roof. and we cant do it if we divide texture into, say 4 segments using one for walls and one for roof.

so wait wait, I'll try to clarify it all; to me there is two ways of solving this problem (considering just one building at the moment though);

1) Use separate mesh/material for roof, then use representative texture for both. I already did the repetition part but create roof as another entity might be costly for us. That's like 2x draw calls, materials and extra calculations. (well we can merge ALL roofs in the city I guess)

2)subdivide side walls (this would be haaaard..... I guess) and use one texture/atlas for roof&side walls. Admittedly this sounds worse and worse as I keep writing. we'll have to create sooooo many extra vertices just to save extra draw calls..... damn I have no idea which one is better really.

As you can see, I'm confused as hell john, help me out with this :) (I wonder if we have anyone pro in these matters, stalking around. would really love some input)

johnsnook commented 8 years ago

Am I looking at the right documentation for the TriangleNet you're using? It looks like very useful stuff.

Also, noob question, will that dll compile onto android? If yes, is it because it's an "unmanaged" dll? or do you have to put the source in?

brnkhy commented 8 years ago

it should compile on android yea, both managed and unmanaged dll would I believe. If not, we can always use the source code, I just thought it'll be easier with one file instead of dozens in the source.

johnsnook commented 8 years ago

So, I've been playing with your dev buildingfactory and have found a different issue that effects this one and performance: If a building is on multiple tiles then multiple buildings are generated.

I'm using tilesize of 600 and a zoom of 18 here. I pulled the buildings apart in the scene so you could see them. Obviously, I've got the mergemeshes flag set true. This building just happened to straddle 4 different tiles, so 4 different meshes were generated.

bug

Should I create a new issue for this?

johnsnook commented 8 years ago

I want to say however, that textures on buildings is working (when mergmeshes == true). I can resize the textures using the tiling property. Roofs would be cool but great work in such a short time. Fixing the multiple buildings problem will get rid of the weird shimmer.

And, as far as I can tell, buildings are the only thing being duplicated. Roads and water seem unaffected, since they're just 2d polygons.

brnkhy commented 8 years ago

Double buildings is a known issue (but not logged, my bad). It was actually "fixed" by a simple hashset check but then I realized, destroyed buildings wasn't removed off that list so deleted it all together. Fix is rather easy, all we need is a simple destroyed event on tile objects but.... I was being lazy.

well yea textures are "working" but it's rather useless at this state. That building in your screenshot looks like a slice of cheese :)

brnkhy commented 7 years ago

pushed on the master branch, we can open new issues for further improvements