# How can I fix the "fisheye" distortion in my raycast renderer?

I've just started making a 'raycast' engine, a pseudo 3D FPS engine similar to Wolfenstein/Doom. I haven't done much reading so my implementation is likely very naive.

My current working prototype has a 'fisheye' distortion [2nd image] which makes sense because the middle of the wall is closer than the far edges, but this is not how Doom looks.

What's the right way to do this? an orthogonal projection seems wrong because you would lose the foreshortening.

• How are you calculating your projection? Mar 31, 2015 at 1:06
• Horizontal FOV is 90 degrees (pi/2 rad), all rays begin at the player, the distance for each ray is just the Euclidean distance from the user to the ray/wall intersection. The wall height is essentially the height/distance. Top left on the images shows the player in a box, pink lines are the rays. image here Mar 31, 2015 at 9:48

You need to use the range instead of the distance when you cast the ray. The range is the length of the projection of the ray onto the camera plane.

See this source.

Though IMHO some amount of fisheye distortion is kind of cool to keep around.

• I just started doing something very similar (scaling the ray to the the length of the middle vector), and it almost fixes it, but there is still a slight curve, so I suspect my distance calculation is wrong. Thank you very much for the link. Mar 31, 2015 at 9:21
• @ReubenCrimp if you want a second source that uses the same method described in this answer, see Lode's Computer Graphics Tutorial on Raycasting. If you prefer a video see Wolfenstein 3D's map renderer, which is based on the actual source code of Wolfenstein 3D (and yes, it has the same basic approach for this problem). The video goes on a bit more detail than the linked articles (it talks about some of the optimizations done in the game). Jun 22, 2019 at 16:05

Typically, you wouldn't space your rays at even angles. This is the source of the distortion. See this answer for details: https://gamedev.stackexchange.com/a/156853

• how did you even stumble on this 5 year old questino? Jul 13, 2020 at 7:11
• I was actually googling how to create a fish eye effect in a raytracer. Jul 13, 2020 at 7:31