Best way to calculate road parallax in racing games?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Best way to calculate road parallax in racing games?

Post by Vectrex2809 »

Right now, I'm thinking about making a racing game. So far, I managed to implement a routine that can easily calculate the next frame of the road's parallax, like so

Image to Image

The only problem is that it takes a long time in CPU time to calculate the next frame, as you can see on the pic below (This is for 2 road frames at once)

Image

This could potentially be a problem when the player encounters a sharp turn or gets sent to the other side of the road quickly, as it could be the source of slowdown (Not to mention road rendering takes a ton of CPU time too)

So I would like to know if there is a better way to calculate the road's parallax, making it possible to go from the pic on the left to the pic of the right directly.

Image to Image
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Best way to calculate road parallax in racing games?

Post by Memblers »

My first thought would be a look-up table, assuming you're not limited on ROM. If your scrolling covers 128 scanlines, then you'd have 128 entries in the table with the H value for each line. Then for the left-to-right position, duplicate the table for each step. In that case, 256 steps would make a 32kB table.
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: Best way to calculate road parallax in racing games?

Post by Vectrex2809 »

I thought about this actually, but I don't want to waste too much ROM space even though I'll probably end up doing it on an MMC3 because IRQs
User avatar
pubby
Posts: 555
Joined: Thu Mar 31, 2016 11:15 am

Re: Best way to calculate road parallax in racing games?

Post by pubby »

I was thinking use a lookup table but only for slope values. That way it would be only 256 128 bytes and not 32k.
So I would like to know if there is a better way to calculate the road's parallax
It would really help if you were to describe your current attempt and how you want the parallax to actually behave.
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: Best way to calculate road parallax in racing games?

Post by Vectrex2809 »

So I decided to transcribe the scroll values onto a massive file and do as Memblers suggested. It seems to work fine :D - I ended up saying "*%$@ it" and going MMC3!
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Best way to calculate road parallax in racing games?

Post by tokumaru »

pubby wrote:I was thinking use a lookup table but only for slope values. That way it would be only 256 128 bytes and not 32k.
Slope values would work, since the road is straight, not curved like in many teaching games. These values would have to be fixed-point numbers, but they can probably still fit in 8 bits. But you'd also need the initial scroll value for the topmost scanline, doubling the amount of space necessary for this approach, but that's still waaaay less than full lookup tables with values for every scanline.
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Best way to calculate road parallax in racing games?

Post by Drew Sebastino »

I can't help but feel that the road should get even smaller toward the top. It looks like it's as wide as the buildings.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Re: Best way to calculate road parallax in racing games?

Post by Bregalad »

What I did in the only demo I did who does that is use an exponential curve. The top scroll value is multiplied by a fixed-point constant and goes closer to zero each line. It works pretty well, although it's probably not the only way to do that.

Rad Racer does it all with lookup tables.
User avatar
mikejmoffitt
Posts: 1352
Joined: Sun May 27, 2012 8:43 pm

Re: Best way to calculate road parallax in racing games?

Post by mikejmoffitt »

Espozo wrote:I can't help but feel that the road should get even smaller toward the top. It looks like it's as wide as the buildings.
Certainly. The only other justification is the player is going around a small sphere or up a hill, forever.
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3496
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Best way to calculate road parallax in racing games?

Post by Drew Sebastino »

It's going around the entire planet, those buildings are actually moving backward. :lol:
Post Reply