Star field parallax

I’m making a top down view space game. I’m using Rendercam.

I need to make a star background with parallax (both position and scale, as you can zoom in and out).

My current solution is to place 9 sprites (3x3) in a game object and child it to the Rendercam game object. I then have a script that handles the movement and scale parallax. The 3x3 seamlessly looping grid means I can recenter the game object after sufficient movement.

I don’t like this solution because it feels janky, and the sprites have to be large to account for the maximum zoom-out.

I’d ideally have 2 or 3 layers (to give the illusion of some stars being closer than others), but would be happy with an elegant single layer solution.

How would you do this?

Hoping to nerd-snipe someone here… :pray:

This might be good place to start. I remember I had to modify it a lot of my current project, but I ended up with a very nice parallax effect.

1 Like

That sounds very promising, will check it out. Thanks!

Hey Alex,

just a side note. If you are aiming at some realism you don’t need more than ONE background layer; stars are usually very very distant, so distant that you don’t see any parallax in space but the movement of objects (ships, bullets…) against the background. If you are near a planet then the planet may have a different parallax but only it.

But, of course, if you want a 80’s star field scrolling then you need more levels. But it is just a wrong design propagating in the media… :slight_smile:

Ciao!

2 Likes

Point well taken - though very little in this game will be realistic…

2 Likes

You could always have stars on one layer and space debris, meteorites, comets and stuff on closer ones. That would still be wrong in a lot of ways, but for different reasons.

3 Likes

I think this is a perfectly good approach, as long as each sprite aligns properly with each other.

3x3 sprites suggests you can travel both horizontally and vertically I guess?

And by using sprites, I assume you have prerendered textures to switch between?
Are they all the same texture? (just positioned differently so that you can move and zoom in/out)

In any case, I’d like to highlight the possibility to use a screen space quad, that always
fills the screen perfectly. I don’t have a small example for you, but perhaps others can help here. Found this example.
You can use the shader to zoom in/out by scaling the uv coordinates. By doing so you can also produce multiple layers in the same quad by sampling the texture several times per pixel, each time with a scaled uv coordinate.
Anyways, just thought I should mention it. (Sounds like a fun task for someone to help experiment with :wink: )

3 Likes