I'm more of a programmer than a 3d artist and this is more of a system design question than a 3d art issue so I'm not sure if this is the right place to post but I'm hoping someone here might be able to help me
Anyway, I'm currently programming a 3d "tile" system for a personal project. Each tile is uniform in x/y and can be fitted next to a number of other tiles as is usual in these kinds of systems.
To have some variation each texture is also broken up into 4 tiles (actually 4x4 but that's not important here), so in the engine the UV coordinates of a tile is offset by 0.25 * (TileCoordinate MOD 4). Basically the subtexture for each tile moves one step for each step in x,y and z on the map grid and then wraps around ever four steps. Hopefully this picture illustrates this concept adequately:
The tile models use two sets of uv projections (plus one for lightmaps). One set for top down "ground" cover and the other one for "walls" or the sloping part of a tile. Finally vertex colors and some shader trickery is used to blend ground and wall textures together in a pleasant way which is the standard way to do terrain texture blending.
The problem I have is what to do with the corners.
Since the sub-texture offset is dependent on the tile position on the grid corners end up not lining up most of the time. For example, as shown in the picture above the left side of the corner is a "1" while the right side is also is "1", ideally we'd want a 1,2,3 but that's not going to be possible here.
My first naive solution is to somehow generate all transitions between tiles for the corners and keep them in a separate texture map. This solution is quite nasty because some of my tiles are 2-3 unit tall combinations of other tiles and I'm not sure how to do that for them:
Another thought is to use two vertex color channels for the wall and then store the subtexture offset instead of the texture ID corresponding to that channel - and then blend between the subtextures on the corner using vertex colors like any other blend texture. Thinking about it, this might actually be the best option.
I'd love to hear suggestions.
Maybe this problem has a super easy solution I haven't thought about. If so I'm dying to hear what that might be.
Replies
As I understand your issue it's not a modeling issue but a logic issue.
This tile-id related issue is really sounding like a basic misconception or flaw of your approach.
Imo your problem arises because you have 4 tiles on your texture but you have 6 tiles on your model. If you straighten it out you go from ?1234?1234?1234.... but your texture is 123412341234....
My suggestion would be: re-think your intentions. Why do you want to do it like you said and not like the "usual" approach which is more or less what @icegodofhungary is describing.
It's not for offline generation, the system generates tiles in real time on the fly(basically by copying a base-tile and offsetting its position and texture coordinates) to be used directly in the engine on the same frame.
But yeah thinking about it I should have used tri-planar projection from the start. I didn't want bloated vertices and tried something clever(foolish).
I find that breaking up a tiling texture into several sub textures parts helps a lot with variety, especially for cliffs and things like that. Probably less so for a wooden barrier but this is a low-res project so textures are pretty much free.
But thanks a lot, it works perfectly now!
@rollin
As I prefaced in the original post, this is indeed a system design (logic as you say) issue rather than a 3d art issue/modeling. I should have clarified that the ? is nothing special it's the same as the other tiles, a 1,2,3 or 4. I put it in there to highlight that I wasn't sure what to do about them corners(since x and y vary independently).
Personally I think I'd add specific corner textures to the atlas and treat them as a special case
Triplanar is easy but rounded corners like those illustrated breed blending artefacts and you're also left with no real way to add any unique information so I'd expect that once art happens you'll find there are limitations you don't like.
As an aside, I wonder if some sort of wangtile type logic could be applied to this