<p>I am trying to implement rendering in &quot;Camera-World&quot; space following PBRT-V4's camera implementation in my Rust ray tracer. I Have been trying to solve that for days</p>
<p>I read these multiple times:</p>
<ul>
<li><a href="https://www.pbr-book.org/4ed/Cameras_and_Film/Camera_Interface#TheCameraBaseClass" rel="nofollow noreferrer">https://www.pbr-book.org/4ed/Cameras_and_Film/Camera_Interface#TheCameraBaseClass</a></li>
<li><a href="https://www.pbr-book.org/4ed/Cameras_and_Film/Projective_Camera_Models" rel="nofollow noreferrer">https://www.pbr-book.org/4ed/Cameras_and_Film/Projective_Camera_Models</a></li>
<li><a href="https://pharr.org/matt/blog/2018/03/02/rendering-in-camera-space" rel="nofollow noreferrer">https://pharr.org/matt/blog/2018/03/02/rendering-in-camera-space</a></li>
</ul>
<p>And yet, I can't make it work.<br />
I have a perspective camera located at [0, 1, 4], looking at the origin, and four spheres:</p>
<pre class="lang-rust prettyprint-override"><code>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());
</code></pre>
<p>Here are my image outputs for each space:<br />
<a href="https://i.sstatic.net/3q5k5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3q5k5.png" alt="World Space (Intended)" /></a><br />
World Space (Intended)<br />
<a href="https://i.sstatic.net/CNUuu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CNUuu.png" alt="enter image description here" /></a><br />
Camera Space<br />
<a href="https://i.sstatic.net/pvERp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pvERp.png" alt="enter image description here" /></a><br />
Camera-World Space</p>
<p>I reviewed my transformations multiple times and I can't find what's wrong.</p>
<p>Relevant code:</p>
<ul>
<li>Camera implementation: <a href="https://pastebin.com/sY2JRxDf" rel="nofollow noreferrer">https://pastebin.com/sY2JRxDf</a></li>
<li>Main: <a href="https://pastebin.com/C1EnGddT" rel="nofollow noreferrer">https://pastebin.com/C1EnGddT</a></li>
</ul>

CC BY-SA 4.0
2023-12-01T08:53:46.583Z
can you go more into detail? Whats wrong? In the last two images there is one sphere missing or what do you mean?
Thomas
CC BY-SA 4.0
2023-12-01T08:57:06.467Z
And what do you mean by "Camera-World Space"?
Thomas
CC BY-SA 4.0
2023-12-01T09:27:30.583Z
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.
AregevDev
CC BY-SA 4.0
2023-12-01T09:33:47.947Z
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
AregevDev
CC BY-SA 4.0
2023-12-01T10:33:34.437Z
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.
pmw1234
CC BY-SA 4.0
2023-12-02T05:32:51.957Z
It looks like your normal vectors are wrong... In camera space the normal vector of the center of a sphere should be (0,0,1) or (0,0,-1) depending on the coordinate system. So the color in the center should be blue with no red and no green. Or the normals you are rendering are in world space...
Thomas
<raytracing><rendering><camera>
Ray Tracing in Camera-World Space
AregevDev
# Ray Tracing in Camera-World Space

(Asked by: username_0 on 2023-12-01)

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:

* <https://www.pbr-book.org/4ed/Cameras_and_Film/Camera_Interface#TheCameraBaseClass>
* <https://www.pbr-book.org/4ed/Cameras_and_Film/Projective_Camera_Models>
* <https://pharr.org/matt/blog/2018/03/02/rendering-in-camera-space>

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:

```rust
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)](https://i.sstatic.net/3q5k5.png)](https://i.sstatic.net/3q5k5.png)  
World Space (Intended)  
[![enter image description here](https://i.sstatic.net/CNUuu.png)](https://i.sstatic.net/CNUuu.png)  
Camera Space  
[![enter image description here](https://i.sstatic.net/pvERp.png)](https://i.sstatic.net/pvERp.png)  
Camera-World Space

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

Relevant code:

* Camera implementation: <https://pastebin.com/sY2JRxDf>
* Main: <https://pastebin.com/C1EnGddT>

**Tags:** raytracing, rendering, camera

> **Comments:**
> **username_1**: can you go more into detail? Whats wrong? In the last two images there is one sphere missing or what do you mean?  
> **username_1**: And what do you mean by "Camera-World Space"?  
> **username_0**: 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.  
> **username_0**: 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  
> **username_2**: 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.  
> **username_1**: It looks like your normal vectors are wrong... In camera space the normal vector of the center of a sphere should be (0,0,1) or (0,0,-1) depending on the coordinate system. So the color in the center should be blue with no red and no green. Or the normals you are rendering are in world space...  

---

## 0 answers

