2d background parallax combined with planetoid curvature

Author Topic: 2d background parallax combined with planetoid curvature  (Read 1128 times)

this is a really strange general math question im putting here before i post to stack exchange. this doesn't belong in mod discussion because it is not for blockland, it is just a general problem that i've been trying to wrap my head around.

i am trying to combine two different visual effects into one which i can mentally picture but on paper seems physically impossible. the two effects are as follows:

2d parallax



this one is simple. its multiple layers that use coordinates relative to the player but move at different scales to give the illusion of depth. layers that move slower (ie 1/2th the coordinates of the player) appear farther, while those that move faster fit well in a foreground.

2d planetoid with curvature



this one is a little more complicated. it usually involves deforming/texturing a circle/sphere procedurally and it uses a radial coordinate system (coordinates can repeat and are maximum 360 degrees)


the problem: combining the two.

typical parallax uses a 2d cartesian x-y coordinate system, while planetoids/circles use 2d polar r-θ coordinate system. although they can be converted between each other, a polar parallax has several problems. first, all background layers of a planet must be the same or larger in radius in order to be visible to the camera (bigger than the planet). second, they must rotate slower than the camera rotates around the planet. the 'slower rotation' of the background circle is what is stumping me up. this is only for backgrounds, while foregrounds suffer from a similar but opposite spectrum of problems.

a slower circular background will have more data than required to display, as it will take more relative rotations of the planet to fully view all its data. this data (the 'dark side' of the planet) will never actually be viewed or used by the game because it isn't physically sound and is irrelevant. a faster circular background (foreground) will have less data than can be displayed on one rotation, leading to a problem of packing more than one rotation's worth of background into one rotation.

i drew a diagram to help communicate the ideas.

green circle - outer background circle (rotates at 0.5x speed)
red circle - inner planet circle (rotates at 1x speed)



if you superimpose two circles on each other and have the outer one rotate at 0.5 speed the inner one, by the time you traverse half the planet you would've traversed a quarter of the outer circle's background



this works fine until you traverse the whole planet once, after which you've only traversed half of the outer circle. this means, your second run around the red circle, you'd have an entirely different side of the outer circle. one hacky handicapped solution i found was to just cut the outer circle in half. since only half of the outer background can be viewed in one full planetary rotation, there is no need to display/store the other half. this half could be cloned on the opposite side of the planet and the seams connected to give the illusion of one continuous circular parallax background





this solution is far from ideal and i'm still looking for a more sound, mathematical solution. for example, this method is a mind forget on foreground (backgrounds that parallax faster than the planet) because it requires packing two circles' worth of data into one. if anyone has ever encountered a mathematically similar problem in the field of trigonometry and has some insight i'd love to hear it. this problem has been driving me partially insane for the last 5 months and has been a major holdup for one of my game design projects.
« Last Edit: August 20, 2022, 01:12:25 AM by PhantOS »

tbh the only real solution i can think of is to have two or more different backgrounds, which would allow you to reset the origin point of the parallax when transitioning in between backgrounds. trying to find a solution with only one constant background is gonna be super forgety since you're trying to visually represent non-euclidean bullstuff in a way that doesn't ruin the illusion

how much of the planets surface will be taken up by the screen? I imagine if it's a large portion (like the 2nd gif you posted) then a parallax might look tacky anyways

for small planetoids like that gif, parallax probably wouldn't work. you're looking at it straight-on, there's no perspective

for large slightly curved segments, like perennial, it would work. sort of. the same issue would still happen if you wanna go all the way around

alternative answer: do not change the rotation speed, change the size of the background. should remain in-sync with foreground angle, like looking at a cylinder



i had this extremely elaborate idea on how to make 2d parallax backgrounds using the rpgmaker2k3 event system, but then i forgot the entire thing overnight

i had this extremely elaborate idea on how to make 2d parallax backgrounds using the rpgmaker2k3 event system, but then i forgot the entire thing overnight
tried to tell you to stop eating that junk ddd was sellin' it's no good man

alternative answer: do not change the rotation speed, change the size of the background. should remain in-sync with foreground angle, like looking at a cylinder
correct me if i'm wrong, but wouldn't this have no effect? if two circles of different size rotate at the same speed, they'll still always have the same angle relative to each other. the only thing i can visualize is the background having a different curvature than the foreground due to the perspective.

an orthographic camera would also not agree with this method, as without the perspective the background would look static relative to the foreground

tbh the only real solution i can think of is to have two or more different backgrounds, which would allow you to reset the origin point of the parallax when transitioning in between backgrounds. trying to find a solution with only one constant background is gonna be super forgety since you're trying to visually represent non-euclidean bullstuff in a way that doesn't ruin the illusion
i was thinking about writing a shader for the background that renders images with curvature in real-time. the one problem then would be the camera's zoom and position matrix. i could see zooming out of the planet leading to some stretching/warping of the images, i'm just wondering if there's a good formula for having the perspective remain uniform regardless of the camera's zoom of the planet
« Last Edit: August 21, 2022, 09:56:17 PM by PhantOS »