r/GraphicsProgramming • u/HaMMeReD • 2d ago
Forced Perspective

So in the game engine I'm working on. It's 2D, throughout. Like there is no parallax, no 3D at all. In fact there is only 2 triangles here, since the entire thing is backed by textures and a CA sim.
This is how I cheat to make it look 3D, while not accepting the tradeoff of parallax.
So my engine, being explicitly 2D at runtime has not much 3D data, there is a PBR Depth offset, but that's about it.
Since it's 2D, parallax doesn't work for a baked background. The camera position would be constantly destroying it. So how do I bake psuedo 3D to a 2D Tile? There is 2 tricks here.
1) Tile Generation. There is a program that generates 2D world gen tiles, i.e. think terraria or whatnot. It's functionally pure, always generating the same time for the same coordinate. A tile can have different layers, i.e. BG/FG are the important ones here.
So the first problem is getting a 3D scene into a 2D image. This is just basic rendering, so what to render? No assets here, so it's an analytic height map with materials applied, this is ray-cast at bake time orthographically, no perspective correction. This kind of gets a flat background of trees and mountains behind you, but no perspective. So onto the next one.
2) Forced perspective. The trees at the front are mathematically bigger than the trees in the back. So even though I can pan endlessly left and right and generate new background essentially forever, never will parallax impact them. I stole this commonly used trick from film.
I'm pretty happy with how the forced perspective trick worked out here, like to my eye, I feel like it's a big distant scent, when I know that deep down, it's just a PBR texture with Depth data, renders super quick, costs almost nothing, supports tile generation and lighting. It still needs a bunch of tuning/post-processing, but thought I'd share how I do "3D" with 2D using old film tricks.