TheDuckCow / godot-road-generator

A godot plugin for creating 3D highways and streets.
MIT License
328 stars 17 forks source link

Road Texture rules #21

Closed TheDuckCow closed 1 year ago

TheDuckCow commented 1 year ago

Copying over some additional discussion that was in email, but useful to capture here (and is in parallel to above):

From Bret:


In order for lane texturing to work consistently, there need to be some rules or guidelines to follow. Thus, I would like to propose the following:

LANE TEXTURING GUIDELINES

  1. Lanes have a "Lane Type" and a "Traffic Direction".
  2. Lane Type determines the lines that will be drawn within a lane.
  3. Lines will be drawn on the side of the lane determined by Traffic Direction.
  4. A lane's "Forward" direction is from start point to end point.
  5. If Traffic Direction is "Forward", then road lines will be on the left.
  6. If Traffic Direction is "Reverse", then road lines will be on the right.
  7. For any single lane, lines should only be drawn on one side: either left or right.
    • That means for a fast lane: 1 yellow line. For a slow lane: 1 striped line. For a shoulder: 1 white line plus a gradient...
  8. Lane textures and UV mappings should include a margin of at least 1 pixel between a lane stripe and the edge of a UV tile in order to prevent texture bleed between lanes.

The following image helps to illustrate what I've just described. Think of the black lines as UV tiles that mark the lane and texture divisions.

hkjajafnnbfabcdh

In the current application, I'm seeing lines that are partly cutoff or even non-existent in some cases where they should be there. I occasionally also see lines that shouldn't be there like a faint cutoff solid white line along a striped line.

lhoojmimnlmofkmd

I believe I can address the problems by updating the road texture and also reviewing and/or updating the UV calculations.

Please feel free to correct or fill in any gaps in knowledge that may be missing from the above guidelines.

TheDuckCow commented 1 year ago

My initial reply:

Good questions, and appreciate the eye for detail here. First thing first, the original design for the UV texture was intentionally that all lines were exactly on the borders. Meaning, the white line for the shoulder did bleed into the lane on one side, and the shoulder texture on the other. That lead to some of the seamless ability to combine thing together, but now that we are looking at lane transitions, it was very evident from your test it was better that the painted elements are better of shifted the minimum amount possible to one side or the other.

I am open to change the UV texture, it was a starting point. We could add more “columns”, or double it up to have a whole other row to make it more square which is processor-optimal (though might get complicating with tiling vertically, if ever needed).

Now taking a look at your proposal: Basically everything you outlined sounds great to me. It works well to maintain all the use cases I can think of, including multiple middle medium-slow lanes. The only edge case I can really think of is a single bidirectional lane, but even there we could use a blank texture in the middle, and the two shoulders on either side would contain the white texture, so that works well too actually.

The initial texture was made using Affinity Designer - a vector program (not free, but no subscription!). It actually has some really nice tools which let you visualize how things will turn into pixels on export. The initial file I will admit is a little sloppy, out of my own lack of making the most of those tools vs it being a software limitation, hence you see some of these issues in the test scene. I can work on creating the cleaned up, more pixel-perfect variant based on what you have proposed (I’d rather have you spend time coding, than time in texturing). Unless you think there are any further changes you want to try I might not be aware of.

TheDuckCow commented 1 year ago

Bret's counter reply

Another not so edge scenario occurred to me. Often, we see two yellow lines in the middle of the road. BUT, it's also quite common to have a single striped line or, perhaps, even a single solid line.

This could be achieved even if we adhered to the lines are always on the left rule. We could just use odd UV coordinates to split a striped line in half and show half in the forward lane and half in the reverse lane. But, that adds complexity to the UV positioning.

The point is: we probably don't want to do that. The alternative would be to reserve a tile in the road texture where we break the rules and split a line in half. We would need to do that for each line type we wish to place in the middle of the road where forward and reverse lanes meet. These "half line" tiles would probably also need to be positioned so that they don't cause bleeding into other UV tiles.

An easier, albeit, less satisfying approach is to keep things the way they are and just place two lines side by side in the middle of the road when we want striped or solid lines in the middle. One line in the forward lane and one in the reverse.

Let me know if you want pictures and please share your thoughts.

TheDuckCow commented 1 year ago

Hey @bdog2112 just an FYI that I brought our email discussion over here, but the last back and forth we had was actually before our weekly team call on Sunday, so let me know if you have any updated thoughts.

Regarding a 2-way road where there's a single dotted line down the middle, I'd be ok presuming we just need to pick one side or the other to have the texture, and thus it's technically slightly offset. I suppose it's not ideal, but it would still work with the rest of material strategy. We could also pair this with a special geometry rule, to essentially make that middle edge loop be a little bit more to one side than the other to compensate to make the dotted line look more in the middle, though that too gets a little tricky.

TheDuckCow commented 1 year ago

Here is an example of what the updated road texture might look like:

road_texture

"Margins" are needed in order to prevent texture bleed. Each UV tile has a 1-pixel black line along its border in order to visualize the margins between UV tiles. The black lines are strictly for reference and should not be present in the production road texture.

Note that the solid white line is shown twice. Once with a black/gray gradient and once with a solid gray background. This is required. However, we could do away with one of the two solid yellow lines since we only need one. That could free up space for another pattern. There are also two solid gray lanes on the right. We only need one. Hence, that leaves room for another pattern, there, if needed.

The striped yellow lines were originally white and painting them yellow was just an idea. We can do away with the pattern in that lane, altogether, if striped yellow lines aren't needed. Then, use that texture space for something else.

Since we have two or three lanes whose current textures aren't needed, we could potentially use two of those lanes to create textures with split striped white lines. One lane in the forward direction and one in the reverse direction.

Split white lines could be used in the center divider of a segment in place of double yellow lines since this is quite common on two lane roads. We wouldn't have to worry about texture bleed because the stripe in the forward lane tile would be touching the stripe in the reverse lane tile. Even if we didn't use the textures, they would be good to have as placeholders.

At present, split white lines have been clearly defined as out of scope. But, if you change your mind, then feel free to put 'em in the road texture!

TheDuckCow commented 1 year ago

Bret has been using this locally modified texture, I'll be reflecting this update into the repo's template soon.

road_texture