0
$\begingroup$

I am trying to make a particular kind of raytracer, but there is some strange bug occurring when I attempt to rotate the camera.

As you can see, there is some important distortion ocurring when the voxels are closed to the camera and I am not sure what may be cuasing it.

This is how I am calculating my ray:

vec3 r = (vec3(f_coord.xy,1.f/tan(radians(40)))) //initialize the ray for a field of view of 40, f_coord is the pizel coordinate in OpenGL (-1 to 1);
r.y /= aspect_ratio // crunch the y direction to fit the aspect ratio;
vec3 dir = vec3(view_m*vec4(normalize(r),1)); //rotate the ray by the camera's rotation
r+= camera_pos; //Set the ray at the camera's position
$\endgroup$
  • 1
    $\begingroup$ From you video it looks like the ray direction, not ray-origin is being skewed by changes to the position. Does view_m have a translation component ? You should be multiplying normalised r with W=0 also when multiplying direction vectors by a matrix. $\endgroup$ – PaulHK Jun 22 '18 at 5:43
  • $\begingroup$ I construct the rotation matrix using glm:rotate(mat4, float, vec3). I don't think that creates a translation component. But I agree with your diagnosis $\endgroup$ – Makogan Jun 22 '18 at 5:47
  • $\begingroup$ I've just editted my comment, try view_m*vec4(normalize(r), 0)); $\endgroup$ – PaulHK Jun 22 '18 at 5:48
  • $\begingroup$ @PaulHK I did the suggested change however the outcome is the same $\endgroup$ – Makogan Jun 22 '18 at 6:55
  • $\begingroup$ Presumably you start from 'r' in the direction of 'dir' ? What is the purpose of r+= camera_pos; ? Should you be starting from 'camera_pos' ? $\endgroup$ – PaulHK Jun 22 '18 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.