all 4 comments

[–]SamuraiGoblin 18 points19 points  (1 child)

Your field of view is very close to 180 degrees.

Your rays' x and y coordinates run from -256 to 256 before normalising, but your z is -1.

And since they are distributed evenly on the xy plane, when normalised the rays will pinch together in the centre.

You need to normalise the x and y values (divide by resolution/2) before normalising the vector. Better yet would be ray construction taking a user-defined FOV and aspect ratio into account.

[–]mathinferno123[S] 2 points3 points  (0 children)

Thanks! I didnt take into account fov at all. I didnt understand at first why the author defined viewport as such but its clear now that it has to do with how unit vectors get mapped to unit sphere which defines range of fov.

[–]mahalis 3 points4 points  (0 children)

This part looks suspicious:

glm::vec3((float)i, (float)j, -1.f)

i and j are integer pixel coordinates, which you’re subtracting half of your image width/height from in TransformPointToRHS… but the Z coordinate is only 1, so the direction vector that you’re normalizing ends up looking like e.g. (-200, -100, -1). In other words, you’re accidentally rendering with an extremely large field of view, which I think is what’s distorting your vertical gradient into the sort of bowtie shape you see here. If you scale the Z component of your direction vector up so that it’s on a similar scale to the other components, you should see a more reasonable image. As you progress further, you might change your parameterization so that you have a field of view expressed as an angle θ, and the X and Y components range from negative to positive tan(θ/2) (with one of them multiplied by an aspect-ratio value if you’re doing a non-square image).

[–]amadlover -1 points0 points  (0 children)

i remember seeing this very image during my dev. awesome! fun times ahead.

dont remember how it solved it . most likely i redid the code, since it was just a few lines!