mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.08k stars 243 forks source link

Depth integrator is off by near_clipping plane value #547

Closed kyrollosyanny closed 1 year ago

kyrollosyanny commented 1 year ago

Summary

Im using the Depth integrator to get the depth buffer of a scene (i.e. distance from camera to the objects in the scene). I noticed that the values returned by the depth buffer are always off by the value of the near_clipping plane. Im wondering why that is? For example, in the simple example below, I place a cube scaled by 0.025 at z=0.6 m from the camera. The depth value returned is 0.475. Now adding, 0.025 (half the size of the cube to that), we get that the cube is centered at 0.5 when it should be centered at 0.6. Interestingly enough, the value of the near clip plane here is 0.1. This generalizes when I change the value of the near clipping plane

System configuration

System information:

Mitsuba version: .3

Description

Steps to reproduce

<scene version="3.0.0">
    <integrator type="depth">
        <!-- <integer name="max_depth" value="10" /> -->
    </integrator>
    <sensor type="perspective">
    <float name="fov" value="95" />
    <float name="near_clip" value="0.1" />
    <float name="far_clip" value="6.4" />
<!--     <transform name="to_world">
        <lookat origin="0 , 0, 0" target="0, 0, 1" up="0, 1, 0" />
        <scale x="-1" />
        <translate x="-0.032" />
    </transform> -->
    <sampler type="multijitter">
        <integer name="sample_count" value="64" />
    </sampler>
    <film type="hdrfilm">
        <integer name="width" value="100" />
        <integer name="height" value="100" />
        <string name="file_format" value="openexr" />
        <string name="pixel_format" value="rgb" />
        <rfilter type="tent" />
    </film>
</sensor>
<bsdf type="roughdielectric"/>
<shape type="cube" id="cube">
    <transform name="to_world">
        <scale value="0.025" />
        <!-- <rotate x="1" angle="45" /> -->
        <!-- <rotate y="1" angle="45" /> -->
        <translate z="0.6" x="0" />
    </transform>
</shape>
njroussel commented 1 year ago

Hi @kyrollosyanny

I think this is a duplicate of https://github.com/mitsuba-renderer/mitsuba3/issues/491, could you take a look at the conversation there?

kyrollosyanny commented 1 year ago

Hi @njroussel,

Thank you for your response and the very helpful pointer. I have a couple of questions to clarify:

  1. To get the correct depth map, as in how far the objects are from the pinhole camera, do we always add the near clipping plane value to the depth integrator values? or are the values returned by depth integrator the true depth values?
  2. In your response in the post you cited, you mention: "If the near_clip distance defines the plane in which the sensor's film is supposed to be placed", why does the near_clip distance define where the sensor's film is placed, my understanding is the near_clip plane defines the nearst plane in the FoV. While the sensor's film is placed at a focal length away from the pinhole position?

Best,

njroussel commented 1 year ago
  1. As mentionned in that other thread, both the depth integrator and aov integrator will return values that are "missing" the near_clip distance.
  2. Yeah, I wrote that a bit quickly :sweat_smile: . The point I was trying to convey was that the sensor was not located at the pinhole point.

The way to reason about this is that the distance/depth is computed from where the ray is spawned. You can actually see this in the perspective implementation: https://github.com/mitsuba-renderer/mitsuba3/blob/master/src/sensors/perspective.cpp#L226-L232

kyrollosyanny commented 1 year ago

That makes sense. Thanks a lot for the help and very fast responses :)