How to handle rendered over and under.

Hi folks. What would be the best way to approach the following scenario.

I’m messing about with this test bed, a top down driving game. I decided to try to make the road turn and pass over the top of another part of the road, just to see how this would work in terms of code.

I’ve worked out so far that I need the full background and different textures for the ‘top’ roads, draw then in the correct order and change the car’s draw order depending what part of the road it’s on. I can set the draw order by triggers on a hit map which isn’t drawn. I can also work out the parts of the hit map that should be applied depending if the car is on top or underneath. This is all great stuff and I can see how I can implement this without any headaches.

However… (isn’t there always a ‘however’!) I’m rendering the background so I can apply textures to it before drawing, this is for leaving tyre marks and possibly some other stuff. This is a problem because I can’t add textures to the top roads as they wont be rendered like the background. I guess I could render these textures as well, but how would I decide to draw on the top or the bottom renderer? The roads can cross in any mixture of angles and on curves, so I can’t use simple intersections.

I can’t help thinking there must be a better way to achieve this, but it’s eluding me. I could drop one of the functional points and be away without any problems, but where would be the fun!

Has anyone done the same? Or have any ideas?

Thanks.

What I Would do is use a layer system (ie use rendertargets in a given order), one for the background, one for transparents objects (cars, trees, smoke) and one for skids. so you can wipe the first 2, and keep drawing on the skids one, overwriting skids from the previous laps, keeping them all till the end of the race.
If it is in 2D, it’s “easy” : for invisible parts (like tunnels), you could use a sort of mask to tell the renderer not to draw skids in these parts).
If you use 3d top down view, you can acquire the same but with a depth test before drawing.

Yeah, that’s pretty much what I’m doing at the moment, the background is drawn to a render, then I can add what I want as needed in terms of tyre marks. The trees and other items that the car drives under are drawn last and don’t affect anything. The problem is with the road that goes under the road, because sometimes the car needs to be drawn on top, and sometimes underneath. Like a crossroad junction but east-west is under north-south.

Just for testing the graphics I’ve put a different color on my hit mask. If the color is detected I draw the top road, if it isn’t I don’t. But, this means top road is always drawn at that point if the car is meant to be on top or not.
I’ve tried putting one color on the map to turn on the top road, and another color after the crossover to turn it off again, but then that doesn’t work if you drive through the cross backwards.