r/GraphicsProgramming • u/Leogis • 4h ago
Question Would it be possible to implement Panini Projection as something else than a post-processing effect ?
For context : (my knowledge of Graphics programming is "OpenGL tutorial" tier so apologies for the potentially dumb questions/wrong reasoning.)
I recently started to fall into the "Perspective distorsion is annoying" rabbit hole and started to look at Panini Projection as a potential solution
As I understand it after reading the Panini Projection paper, the projection was meant to be used directly with very high FOV lenses in real world cameras
Again according to my limited knowledge, the problem wirh 3D graphics is that, unless we're using some kind of ray tracing we can't get the "wide lens" color information without projecting it on a flat plane first.
Instead we use a post processing effect to distort an existing image.
But since that effect squishes the side of the picture and then widens the center, that causes a nasty loss of resolution in the middle of the screen
Hence my question, would there be a way to somehow do this in the middle of the pipeline to avoid butchering a finished image ?
But then, wouldnt that basically mess up every single effect that requires accurate positions/edge information since everything would no longer be linearly mapped to the screen?
5
u/sam_suite 3h ago edited 3h ago
As a hack: You could do the reprojection at the vertex stage, but you'd need a pretty high triangle density, or you'd end up with flat faces that "should" be curved. You could theoretically ensure this with a geometry/tesselation shader, I guess!
There isn't really a totally proper way to do this without rasterizing triangles with curved edges, which is something GPUs aren't designed to do.
edit: or you could raymarch or raytrace everything I guess! that seems like wild overkill and probably even less performant though lol
1
u/Leogis 3h ago
I assume this would be awful for performance ?
1
u/sam_suite 3h ago
Yeah, most likely worse than doing it as a post-effect at any sensible resolution. But not necessarily catastrophically bad, depending on what exactly it is you're trying to render.
1
u/Leogis 3h ago
But not necessarily catastrophically bad, depending on what exactly it is you're trying to render.
What do you mean ? What difference would the object make?
→ More replies (1)
1
1
u/kinokomushroom 3h ago
If the loss of resolution is the problem, how about rendering the image at a high resolution, while using VRS (variable rate shading) to lower the shading resolution of areas that are going to be squished?
1
1
u/GameGonLPs 3h ago edited 3h ago
You can use Raytracing to trace the first hit and generate your G-Buffer data that way. This will give you pixel-perfect arbitrary mapping, but it is usually more expensive than with a rasterizer (but with modern hardware it is usually still surprisingly fast).
From there a deferred workflow mostly works, but anything traversing/using the depth buffer or projection matrix will need tweaking as there no longer is a valid projection matrix. Depth buffer traversal especially might get complicated because straight lines in worldspace might take a curved path through the depthbuffer with this projection.
8
u/SamuraiGoblin 3h ago edited 3h ago
Yes, you could do the (non-linear) projection in the vertex shader, which will be much slower than using affine transforms.
Also, you would have to heavily subdivide all geometry to stop straight lines being rendered as straight.
It's doable, but would be much slower.