mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.86k stars 444 forks source link

GBufferFilm position value differences for perspective vs realistic camera #149

Closed kontramind closed 3 years ago

kontramind commented 3 years ago

According to existing docs:

Hence I'm using GBufferFilm to record position and generate depth map by looking into Pz. I have a simple scene; plane (covers whole field of view) at some distance (0.7 m) from a camera.

It is not quite clear what is meant by position.

I'll assume in the rest of the text that position is reported wrt. sensor's optical center

When rendering with perspective camera I indeed get reasonable depth map values. See plot below. perspective-depth-map

However, when using a realistic model (camera with wide.8mm.dat lens), we get a completely different/skewed outcame. See plot below. realistic-depth-map

I would expect that the two above are same.

The difference seem to stem from update frequency of p.pSum and p.weightSum values. This can be illustrated by instrumentation. See examples for center pixel.

Perspective camera:

p.pSum: [ 0.00035202169, 0.037117153, 0.6596188 ], weight: 0.942313 p.weightSum: 0.942313 p.pSum: [ 0.00053130416, 0.07391011, 1.3192375 ], weight: 0.942312 p.weightSum: 1.88462 p.pSum: [ 0.00073881017, 0.11078025, 1.9788562 ], weight: 0.942312 p.weightSum: 2.82694 p.pSum: [ 0.000731312, 0.14796646, 2.638475 ], weight: 0.942312 p.weightSum: 3.76925 p.pSum: [ 0.0011555634, 0.1847914, 3.2980938 ], weight: 0.942312 p.weightSum: 4.71156 p.pSum: [ 0.0012534049, 0.2217432, 3.9577127 ], weight: 0.942313 p.weightSum: 5.65387 p.pSum: [ 0.0015609148, 0.25876477, 4.6173315 ], weight: 0.942312 p.weightSum: 6.59619 p.pSum: [ 0.0014674542, 0.2954116, 5.2769504 ], weight: 0.942312 p.weightSum: 7.5385 p.pSum: [ 0.0017937518, 0.33240616, 5.936569 ], weight: 0.942312 p.weightSum: 8.48081 p.pSum: [ 0.0019416936, 0.36953443, 6.596188 ], weight: 0.942312 p.weightSum: 9.42312 p.pSum: [ 0.0021624828, 0.40627623, 7.255807 ], weight: 0.942312 p.weightSum: 10.3654 p.pSum: [ 0.0022192106, 0.44315344, 7.915426 ], weight: 0.942312 p.weightSum: 11.3077 p.pSum: [ 0.0027184158, 0.48037854, 8.575045 ], weight: 0.942312 p.weightSum: 12.2501 p.pSum: [ 0.0027925551, 0.51723593, 9.234663 ], weight: 0.942313 p.weightSum: 13.1924 p.pSum: [ 0.003054739, 0.55415595, 9.894281 ], weight: 0.942313 p.weightSum: 14.1347 p.pSum: [ 0.0029719218, 0.5912084, 10.5539 ], weight: 0.942313 p.weightSum: 15.077 p.pSum: [ 0.003362249, 0.6278908, 11.213518 ], weight: 0.942312 p.weightSum: 16.0193 p.pSum: [ 0.0035300173, 0.6649002, 11.8731365 ], weight: 0.942313 p.weightSum: 16.9616 p.pSum: [ 0.003727273, 0.7019813, 12.532755 ], weight: 0.942312 p.weightSum: 17.9039 p.pSum: [ 0.003736091, 0.73874605, 13.192373 ], weight: 0.942313 p.weightSum: 18.8462 p.pSum: [ 0.0041398136, 0.7756531, 13.851992 ], weight: 0.942312 p.weightSum: 19.7886 p.pSum: [ 0.0042600655, 0.81293106, 14.51161 ], weight: 0.942312 p.weightSum: 20.7309 p.pSum: [ 0.004544182, 0.84974426, 15.171228 ], weight: 0.942312 p.weightSum: 21.6732 p.pSum: [ 0.004357654, 0.8866782, 15.830847 ], weight: 0.942312 p.weightSum: 22.6155 p.pSum: [ 0.0046865633, 0.9237419, 16.490465 ], weight: 0.942312 p.weightSum: 23.5578 p.pSum: [ 0.004814229, 0.96027607, 17.150084 ], weight: 0.942313 p.weightSum: 24.5001 p.pSum: [ 0.005056221, 0.9972454, 17.809702 ], weight: 0.942313 p.weightSum: 25.4424 p.pSum: [ 0.005099694, 1.034366, 18.46932 ], weight: 0.942312 p.weightSum: 26.3847 p.pSum: [ 0.005654054, 1.0711411, 19.128939 ], weight: 0.942312 p.weightSum: 27.3271 p.pSum: [ 0.005742235, 1.1080154, 19.788557 ], weight: 0.942312 p.weightSum: 28.2694 p.pSum: [ 0.005991978, 1.1451763, 20.448175 ], weight: 0.942312 p.weightSum: 29.2117 p.pSum: [ 0.005961227, 1.1820058, 21.107794 ], weight: 0.942312 p.weightSum: 30.154

Realistic camera:

p.weightSum: 0.942313 p.pSum: [ 0.00017172814, 0.035672303, 0.65961874 ], weight: 0.942312 p.weightSum: 1.88462 p.pSum: [ 0.0004107715, 0.07136337, 1.3192375 ], weight: 0.942312 p.weightSum: 2.82694 p.weightSum: 3.76925 p.pSum: [ 0.0008216834, 0.107149266, 1.9788562 ], weight: 0.942312 p.weightSum: 4.71156 p.pSum: [ 0.0009469621, 0.14298676, 2.638475 ], weight: 0.942313 p.weightSum: 5.65387 p.pSum: [ 0.0012506527, 0.17888224, 3.2980938 ], weight: 0.942312 p.weightSum: 6.59619 p.pSum: [ 0.0012163913, 0.2143872, 3.9577124 ], weight: 0.942312 p.weightSum: 7.5385 p.pSum: [ 0.0015050576, 0.25031257, 4.617331 ], weight: 0.942312 p.weightSum: 8.48081 p.pSum: [ 0.0016526623, 0.2863329, 5.27695 ], weight: 0.942312 p.weightSum: 9.42312 p.weightSum: 10.3654 p.pSum: [ 0.0016598515, 0.32211396, 5.9365687 ], weight: 0.942312 p.weightSum: 11.3077 p.pSum: [ 0.0021203582, 0.35819805, 6.5961876 ], weight: 0.942312 p.weightSum: 12.2501 p.weightSum: 13.1924 p.pSum: [ 0.0023701573, 0.39398065, 7.2558064 ], weight: 0.942313 p.weightSum: 14.1347 p.weightSum: 15.077 p.pSum: [ 0.002673539, 0.4295724, 7.9154253 ], weight: 0.942312 p.weightSum: 16.0193 p.pSum: [ 0.0028372074, 0.46545717, 8.575044 ], weight: 0.942313 p.weightSum: 16.9616 p.pSum: [ 0.0030705498, 0.50139254, 9.234662 ], weight: 0.942312 p.weightSum: 17.9039 p.pSum: [ 0.0031086586, 0.53710705, 9.89428 ], weight: 0.942313 p.weightSum: 18.8462 p.weightSum: 19.7886 p.weightSum: 20.7309 p.pSum: [ 0.0033872991, 0.57281125, 10.553899 ], weight: 0.942312 p.weightSum: 21.6732 p.weightSum: 22.6155 p.weightSum: 23.5578 p.pSum: [ 0.0034820796, 0.6082015, 11.213517 ], weight: 0.942313 p.weightSum: 24.5001 p.weightSum: 25.4424 p.pSum: [ 0.0035198794, 0.6441991, 11.873136 ], weight: 0.942312 p.weightSum: 26.3847 p.pSum: [ 0.004070954, 0.6798573, 12.532754 ], weight: 0.942312 p.weightSum: 27.3271 p.weightSum: 28.2694 p.pSum: [ 0.0043091266, 0.7159632, 13.192372 ], weight: 0.942312 p.weightSum: 29.2117 p.weightSum: 30.154

I do not understand why would visible surface be so different (especially for a point on a plane in the mid of a scene)? Am I missing something, or there is a bug?

mmp commented 3 years ago

Thanks for reporting this! There was a bug due to an unexpected interaction between rays sometimes being vignetted by the lens aperture in the realistic camera and how values were accumulated in the g-buffer film. While we would like things like RGB color to be darkened by vignetting, it makes no sense for that to happen with position, normal, uvs, etc.

The position et al. in the g-buffer film are all either in world-space or camera-space, depending on how the "coordinatesystem" parameter is set. (Camera space is the default.)

kontramind commented 3 years ago

Many thanks for such quick response and fix.