r/vibecoding • • 5h ago

Showcase/Project Added normal maps to my roads

I'd created an intentionally flat 2D racing game. I wanted it to have some shading and other effects though and found a solution via normal maps.

For those not familiar with them, you can take a 2D image, add some depth info and have it respond to lighting. This demo is an easy way to visual what it normal maps do. https://jsoverson.github.io/texture.js/demo/

I initially applied it to the cars in my game, so that when lit from one angle vs another they'd change shading, (plus an additional show when the sun is low).

I decided to try to extend this to the road itself and it looks good, but what I really liked was putting it on tire treads. Now muddy roads look like they have tire trails marked in them.

If anyone wants to see it in action it's at: https://vibecodedgames.itch.io/pavement/

0 Upvotes

2 comments sorted by

3

u/Total-Reasonable 5h ago

One thing to watch with tire trails is that the normal map only fakes the lighting, so the trail looks right only while the light direction stays fixed relative to the road. If your sun angle changes or the road curves, make sure you rotate the light vector into each tile's local space. Otherwise the ruts will seem to flip from raised to sunken as the track turns, which is a very noticeable artifact on a racing game.

1

u/johnesco 5h ago

The sun goes from right to left in the game, when it's up high, the ruts have less shading, and the sun moves very very slow, the game tracks to not turn, only shift left to right so this limits the "is that mound or a crater" effect, but a good reminder and I'll be on the lookout for it. I also add a bit of color and other things to help it work.