Reduce the paralax effect or fish bowl distortion?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Markuss
Posts: 16
Joined: Tue May 02, 2023 4:48 pm

Reduce the paralax effect or fish bowl distortion?

Post by Markuss »

Ive gota 2.5d pixel art game and Ive noticed that when my mesh is on the edge of the screen that the pixels dont line up too good:
No Distortion: https://imgur.com/a/n4Pxg9w
Distortion: https://imgur.com/a/O3ZKvHb
I can fix this using: projMat.buildProjectionMatrixOrthoLH(600,200,10,6000);

But I do really like the parallax effect. Is there some way that I can have the parallax effect without so much distortion?
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Reduce the paralax effect or fish bowl distortion?

Post by CuteAlien »

Sorry, I can't tell from the shot what you are doing there.Are you using one polygon per tile and they have different depths? Or is this real 3d geometry?

Not sure if it helps for your case, but if you use svn trunk there has been recently added lens shift support to the camera. Which can in some cases be used to have a kind of view which is projective but doesn't have vertical lines distorted. Thought it only works up to a point as you don't have real projection anymore when moving so once you scroll too far you'll notice you can't ever see stuff which was hidden in your original shot. It basically allows you to render one shot and then scroll around that one as if the renderered shot would be way larger. So in this case for example: You'd start with a camera looking straight ahead but above your target - and then use lens-shift y value to scroll downwards. Guess you'd really have to try to see if that helps or not for your game.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Markuss
Posts: 16
Joined: Tue May 02, 2023 4:48 pm

Re: Reduce the paralax effect or fish bowl distortion?

Post by Markuss »

Its real 3d geometry. The blocks are cubes that flare out at the bottom and the little wooden sticks are rectangular cuboids.
Unfortunately Im using Minetests version of Irrlicht which likely will be hard to merge with the actual version... Im pretty sure I compile Irrlicth every time I compile my game so maybe I can just swap out some of the Irrlicht camera files and it will work?
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Reduce the paralax effect or fish bowl distortion?

Post by CuteAlien »

You'd need CCameraSceneNode.cpp, CCameraSceneNode.h, ICameraSceneNode.h and matrix4.h
Or you can use another camera implementation without changing Irrlicht - always can add your own nodes.
Just search the code for lensshift and you should find the places which need to be changed. Maybe Minetest guys even find it useful and are willing to add it. It's this patch: https://sourceforge.net/p/irrlicht/code/6565
Thought it's possible it depends on earlier patches to simplify matrix4 which are maybe also not yet in Minetest.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Markuss
Posts: 16
Joined: Tue May 02, 2023 4:48 pm

Re: Reduce the paralax effect or fish bowl distortion?

Post by Markuss »

Thank you!
Markuss
Posts: 16
Joined: Tue May 02, 2023 4:48 pm

Re: Reduce the paralax effect or fish bowl distortion?

Post by Markuss »

@CuteAlien Thank you again. I was able to integrate those changes with Minetest and updating the matrix code even fixed a bug with the orthogonal view I was having so thats nice, but Im not exactly sure how to use lens shift. Do you have any examples of how I should set up my camera to make use of it?
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Reduce the paralax effect or fish bowl distortion?

Post by CuteAlien »

No examples yet. But use it as I wrote above. The trick is to start with a view-direction where you have no distortion in vertical lines - meaning you have to look straight ahead. But as you want to look a bit down on your character (in your screenshots at least) this means you have to put the camera higher - so you just look straight ahead above his head. And then use setLensShift with a non-zero y value (x stays 0 in this case) to scroll downwards (not sure if plus or minus y right now). That's all, rest is experimenting with values.

It will then nearly be like looking down but without distorted vertical lines. But it's not exactly the same as really looking down as you still have the original perspective - in artistic terms it will be a bit like a 2 point perspective.

Bit hard to explain - just start with a straight camera and experiment with setLensShift and you'll see what it does. You may also find some info on the web about this effect if you google for it (not exactly the same as this doesn't simulate a real lens).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply