I am trying to implement rendering in "Camera-World" space following PBRT-V4's camera implementation in my Rust ray tracer. I Have been trying to solve that for days

I read these multiple times:

And yet, I can't make it work.
I have a perspective camera located at [0, 1, 4], looking at the origin, and four spheres:

let mut scene = Scene::new();
scene.push(Sphere::new(Vec3::new(0.0, -100.5, 0.0), 100.0, Vec3::new(0.8, 0.8, 0.0), camera.transform.render_from_world).into());
scene.push(Sphere::new(Vec3::new(0.0, 0.0, 0.0), 0.5, Vec3::new(0.1, 0.2, 0.5), camera.transform.render_from_world).into());
scene.push(Sphere::new(Vec3::new(-1.0, 0.0, -1.0), 0.5, Vec3::new(0.8, 0.8, 0.8), camera.transform.render_from_world).into());
scene.push(Sphere::new(Vec3::new(1.0, 0.0, 1.0), 0.5, Vec3::new(0.8, 0.4, 0.5), camera.transform.render_from_world).into());

Here are my image outputs for each space:
World Space (Intended)
World Space (Intended)
enter image description here
Camera Space
enter image description here
Camera-World Space

I reviewed my transformations multiple times and I can't find what's wrong.

Relevant code:

  • 1
    $\begingroup$ can you go more into detail? Whats wrong? In the last two images there is one sphere missing or what do you mean? $\endgroup$
    – Thomas
    Dec 1, 2023 at 8:53
  • $\begingroup$ And what do you mean by "Camera-World Space"? $\endgroup$
    – Thomas
    Dec 1, 2023 at 8:57
  • $\begingroup$ When rendering in camera space, I believe something's wrong in my transformation matrices. The blogpost by Pharr talks about how precision is lost when rendering far from the world origin. Rendering in camera space should should solve that issue. $\endgroup$
    – AregevDev
    Dec 1, 2023 at 9:27
  • $\begingroup$ Camera-world space means that the origin is the camera position, but it isn't necessarily looking towards the camera direction. The camera rotation is applied after the intersection tests to maintain good AABBs. That's my understanding. You can read the blog post and the chapters I posted for more information $\endgroup$
    – AregevDev
    Dec 1, 2023 at 9:33
  • $\begingroup$ It is generally accepted that a "space" such as "camera space" or "world space" is a homogeneous coordinate system with an associated transform, usually as a 4x4 matrix. Objects can be transformed from "camera space" to "world space" with the "World To Camera" transform. Meaning that an object is in world space and the inverse of the camera matrix is being applied to it. So the statement "Camera-World space" is mixing the terminology of describing a coordinate system with the terminology of transforming between them. $\endgroup$
    – pmw1234
    Dec 1, 2023 at 10:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.