Monoscopic 360 Video Optimization
A very important question centers on the size()
of the Processing sketch and number of panels. If the sketch size is too small or there are not enough panels, the end result will be pixelated. The video size might be 4K but there won't be 4K of resolution. If the sketch size is too large or there are too many panels, performance will suffer as Camera3D and Processing will be doing unnecessary work that will not improve the final output.
As stated earlier, it is optimal to have one panel for each of the six camera orientations to minimize the number of calls to the draw()
method. The optimal size for the Processing sketch is a square with height \(h_{f}\) and width \(w_{f}\) equal to \(\frac{w_{p}}{\pi}\). This cannot always be achieved for all computers and projection sizes \(w_{p}\), which is why this Generator supports multiple panels per camera orientation.
To obtain the optimal size \(\frac{w_{p}}{\pi}\) we can use trigonometry to find the minimum size that ensures that neighboring pixels in the equirectangular projection are derived from different pixels in the rendering panels. Since an equirectangular projection's resolution is not uniform throughout the entire resolution, this needs to be done in the area where resolution is weakest. It may not be obvious, but that area is along the projection's equator, at the four points that are at the center of the four panels that intersect the equator. This will become more clear later.
Our first step is to derive the link between the pixels in the equirectangular projection and the pixels in each panel.
Consider an equirectangular projection with pixel dimensions \(w_{e}\) and \(h_{e}\). Each pixel in the projection has a \(\theta\) and \(\phi\) value in polar coordinates. The horizontal and vertical step sizes from one pixel to the next are:
The cartesian coordinates of a pixel in the equirectangular projection belonging to the front panel mapped to a sphere with radius 0.5 is:
If we project that point onto the face of a unit cube centered at the origin, we can calculate the coordinates of the new point using an (x,y) coordinate space of that face with an origin in the corner.
If the face of the unit cube is one of the Generator's panels, the pixel coordinates of the point would be:
Our goal is to calculate the dimensions \((w_{p}, h_{p})\) of the panel in pixels such that
This can be simplified to:
We quickly observe that the calculated dimensions \((w_{p}, h_{p})\) are largest when \(\theta = 0\) and \(\phi = \frac{\pi}{2}\), found at the center of the panel. That means this is the critical point and we can simplify the equations further and substitute in our projection step sizes:
We can then calculate the correct panel dimensions are (1304, 1304) pixels for a 4K video.
In Camera3D's example code there is a resolution test sketch for this Generator called Monoscopic360ResolutionTest. You can empirically test these calculations using that utility.
Interestingly, we note that for large values of \(w_{e}\):
This is the case because
There's nothing special about \(\pi\) here as this happens to be true for any constant \(z\):
We can see this by replacing our trigonometric functions with their respective infinite series, like so:
Evaluate the numerator's product, positioning us to take the limit.
Most of the terms drop out when \(x \to \infty\), proving that
It gave me great joy to find an elegant solution to this problem.
My friend Andrey pointed out to me that this can also be reduced to the commonly known limit \(\lim_{x \to 0} \frac{sin(x)}{x} = 1\). Obviously I forgot about this from school, but happily he remembered:
Substituting \(u = \frac{z}{x}\),
Much simpler.