Tile Explosion for Diagonal Roads

Recommended Posts

Roads that turn at only 90 degrees seem unnatural, but rendering 45 degree turns is turning into a major headache, because it means that roads cut diagonally across tiles and leave pieces of themselves in neighboring tiles. In addition to having textures to render all the various turns an intersections, we also need every combination of nearby roads sticking out in the corners of the tile. In total that seems to be 4096 road tiles just to cover all the possibilities, even when we restrict roads to only going tile-center to tile-center.

We can save memory by doing some flips and rotations in UV coordinates, but I estimate we'd still need dozens of tiles. We can also save some effort by making the tiles transparent beyond the edges of the road, and then layer together multiple tiles when appropriate, either in pre-processing or in the shader. Whatever we do, it is becoming a major headache for something which seems to be so simple in concept. Am I somehow approaching this problem from the wrong direction?

Share this post


Link to post
Share on other sites

I'm misunderstanding you somewhere - you are talking about "tiles" but also mentioning tiles crossing over other tiles. Are your tiles always in a uniform, non-overlapping, axis-aligned grid, or do you depart from that?

What I mean is, if you have a diagonal road like this:

59c9ba7391a24_Crossingtile.png.cc280589eb6ebe7ebb8c1a81222b785e.png

I would count that as four tiles - is that how your game works?

I'm also not understanding where you are getting the number 4096 from. Recently when I was thinking about the same concept (with grid-aligned tile-based games), I calculated it as a max of 256 for automapping tiles, and for roads specifically, it was less - and if using rotations and horizontal/vertical mirroring, less still.

Share this post


Link to post
Share on other sites
46 minutes ago, Servant of the Lord said:

You are talking about "tiles" but also mentioning tiles crossing over other tiles.

Actually I meant that roads cross over neighboring tiles. The tiles are a perfectly regular, axis aligned grid as one would expect. Here's an illustration of the kind of thing I was thinking about:

roadtiles.gif.33de47b49ed891966c9d55c1da8b6029.gif

Notice how when the road goes from the center tile to the bottom-left tile, it doesn't just affect those two tiles but also adds a bit of road to the center-left tile and the center-bottom tile. That's how I got to 4096, because every combination of curves and intersections has to also include every possible combination of bits of road in the corners. For example, the center tile and the center-right tile are almost identical except for a bit of road in the bottom-right corner of the center tile.

Now I see that using smaller tiles could potentially solve the problem. By chopping the road into smaller pieces, there are more ways to assemble roads from fewer pieces. The downside of this is more tiles will mean more triangles on the screen, less variety in the shape of roads, and it also turns road rendering into a jigsaw puzzle where we have to figure out how to assemble the pieces to get the road we want. One tricky point will be ensuring that diagonal roads are the same width as axis-aligned roads.

Edited by Outliner

Share this post


Link to post
Share on other sites

Ouch, that does complicate matters.

Can you just cheat? Draw your roads as you normally do:

59c9c62b4621b_Crossingtile.png.d9e64a9875b2ee0400a421a8cd97b014.png

And then come back and layer the corners on top of existing tiles in a second pass:

59c9c62a9ca6f_Crossingtile2.png.ac2f34e264aea63a582f21297accd62e.png

Then, while you still have a buttload of tiles, you at least simplify it somewhat by not having to worry about the tiny corners.

e.g:

59c9c6fd1e5ae_Crossingtile3.png.e227bb49fb00bc391b2543620e80497b.png

 

 

Share this post


Link to post
Share on other sites
8 minutes ago, Outliner said:

Now I see that using smaller tiles could potentially solve the problem. By chopping the road into smaller pieces, there are more ways to assemble roads from fewer pieces. The downside of this is more tiles will mean more triangles on the screen, less variety in the shape of roads, and it also turns road rendering into a jigsaw puzzle where we have to figure out how to assemble the pieces to get the road we want. One tricky point will be ensuring that diagonal roads are the same width as axis-aligned roads.

As far as the "more triangles on the screen", you could make the road pieces in smaller tiles, but then use a tool to programmatically assemble the different variations (including rotations and flippings) into the large/regular tiles.

Even poor videocards can output bajillions of triangles, though, so I wouldn't worry about having to draw a bunch of small triangles unless it actually proves to be a bottleneck. I don't know how many will be onscreen in your game, though.

A third option would be to split the tiles into 2x2 instead of 3x3:

59c9c8a3579b1_Crossingtile4.png.3bec050bc8d2b71b8c9219bba29a20e0.png

Share this post


Link to post
Share on other sites
4 hours ago, h8CplusplusGuru said:

Why cant you just splat the roads?

As far as I know, splat just means having multiple textures on a mesh so we can have one texture in some places and other textures in other places by using a splat map to to define where each texture is visible. That has several issues. For one, the splat map is a raster, so it tends to pixelate unless it has hugely high resolution. For another, roads often have a direction to their texture, like the lines of a highway, or the grooves of a dirt road. I'm not aware of any way to achieve that effect with splatting.

Edited by Outliner

Share this post


Link to post
Share on other sites

Every combination of road directions and wat-not, that would be a lot of tiles. However, maybe it is not necessary to pre-gen them and instead generate them on the fly as a road placement is determined. Like, is your game really going to be using all those tiles such that it's necessary to worry about having so many? I said splatting: my idea is, because the actual amount of roads are probably not that high, you can have a series of tiles that contain a road, say 3x3, and then you have a splat map and it splats the road right onto that area. The splat map can be generated on the fly depending on the shape of the road, and its resolution can be high as well because you aren't stretching it across your entire terrain. As far as directions of the road go, you can use a detail map or decals or something like that to add features that give the road a particular direction. (or just bake the data into the road splat ).

Edited by h8CplusplusGuru

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Forum Statistics

    • Total Topics
      628645
    • Total Posts
      2984015
  • Similar Content

    • By dell96
      I'm trying to make my first project but I'm stuck i don't know how to make my crate to start to spawn again when i hit the start button after i die.
      hoping someone can help!!!
      Crate.cs
      CrateSpawn.cs
      Cratework.cs
      GameController.cs
      GameManager.cs
    • By alex1997
      Hey, I've a minor problem that prevents me from moving forward with development and looking to find a way that could solve it. Overall, I'm having a sf::VertexArray object and looking to reander a shader inside its area. The problem is that the shader takes the window as canvas and only becomes visible in the object range which is not what I'm looking for.. 
      Here's a stackoverflow links that shows the expected behaviour image. Any tips or help is really appreciated. I would have accepted that answer, but currently it does not work with #version 330 ...
    • By Kerrick
      TL;DR: noob non-coding teacher somehow thinks they can build a narrative educational game in WordPress; plz halp how do I games?
      I'm mostly a teacher with no coding background--I played with teaching myself Java for a bit but couldn't really code anything from scratch. I'm interested in developing (as a hobbyist) an educational game that would be a sort of choice-based narrative branching storyline, a bit like Fallen London/Storynexus. Because it's so storyline based and I don't need crazy 3d animation, I'm considering just building it as a WordPress site with a couple of gamification plug ins to handle inventory and choice consequences. The unique hook is that the game requires (suggests really) that the player accomplish real world building challenges to accomplish your goals. I.e. Your character has to cross a river? Get some popsicle sticks or cardboard or whatever and build a model bridge. Take a photo of your bridge and upload it to your portfolio to continue (and maybe I don't develop this feature right away).
      I'm in this for three reasons: the educational value for families and teachers, the storyline and world I'm building that I'm super excited about, and the fame and massive wealth (just kidding but it has to have to potential to pay for itself).
      Before I sink too much of my life into this, I want to know more about what I'll need to do to make it work.
      Specifically my questions are:
      1) I get that WordPress isn't optimal for developing games. But can I do it or will I have to learn a new engine because I can't make do what I want? (And if so, what's a better engine with low-to-no coding prereq that will still allow me to sell my game?)
      2) How do I budget for a project like this? (The link to the Reddit post about legal fees was very useful thank you)
      3) What are the additional considerations when creating a game like this intended for children with adult supervision? (Obviously privacy, and I need to cover my assets in case some kid takes "go build a bridge!" too literally and gets hurt with mama's table saw in the garage...)
      4) Is this not the forum for this since what I'm talking about is something more like educational narrative fiction and certainly not the spectacularly complex and amazing projects you all are working on?
      Thank you for any and all thoughts.
    • By shillhunter
      I'm looking to add some new experience so I can get better at development, so I'm looking to join a team. I'm great with retro pixel art, even better with reference images (below is an example of my pixel art work), and I just started learning about mobile development. More specifically, Android Studio, though I am trying to expand my horizons. I have great programming experience, and am versatile. I took one year of C++ at my school, and studied Java independently. I'd like to find a team to join that's working on a 2D pixel art game for Android phones.

    • By oranssi
      Still in an early stage of development, but animations and characters are lined up. You will be able to choose from 28 different characters. This game is a psychedelic adult fighting game.
       
      Archelementals of Eiss - A psychedelic short story : 
      https://www.youtube.com/watch?v=24HAKK623U4
       
      (18+) Testing sex mechanics embedded in-combat action.
      https://www.youtube.com/watch?v=pPuTfLIbh7o
       
      AEISS version 0.20 publicly available. Try it now!
      https://www.patreon.com/posts/archelementals-0-15665875
       
      Some images used as splash art:

       

  • Popular Now