Advanced Camera

All Advanced Camera Features are implemented in adv_camera.cpp. Chromatic aberration additionally introduces some changes to render.cpp. All Features are implemented so that they can be used within the same scene.

Depth of Field

To controll the camera's focus, the user can set two variables: A float apertureRadius and a float focusDistance. First, we create a sample on a disk, which we then scale using the aperture radius. We also create the focal point using the focus distance. With these variables, we then set original and direction of the camera ray.


                        Point2f aperture = Warp::squareToUniformDisk(apertureSample);

                        aperture *= m_apertureRadius;
                        Point3f aperturePoint(aperture.x(), aperture.y(), 0);

                        Point3f focalPoint = d * m_focusDistance / d.z();

                        ray.o = m_cameraToWorld * aperturePoint;
                        ray.d = m_cameraToWorld * Vector3f((focalPoint - aperturePoint).normalized());
                    

Validation

To validate the implementation, I created equal scenes for Mitsuba an compared the results.

Mitsuba Mine

                        
                    
Mitsuba Mine

                        

                    

Chromatic aberration

Chromatic aberration is most often an unwanted effect, when using cheap cameras. However, it can also be used to create a sense of discomfort. There is no strict mathematical or physical description available for this, but from images with chromatic aberration we know, what such an effect should look like. For this part, I want to give the user as much freedom as possible. A Vector3f chromaticAberration can be set. These three values depict, how far the color channels are distorted.

When chromatic aberration is activated, the renderer samples the same point three times - once per color-channel. These values are then combined into a single result.


                            if (camera->hasChromaticAberration()) {
                                /* Sample a ray from the camera */
                                Ray3f ray0, ray1, ray2;
                
                                Color3f value0 = camera->sampleRay(ray0, pixelSample, apertureSample, 0);
                                Color3f value1 = camera->sampleRay(ray1, pixelSample, apertureSample, 1);
                                Color3f value2 = camera->sampleRay(ray2, pixelSample, apertureSample, 2);
                
                                /* Compute the incident radiance */
                                value0 *= integrator->Li(scene, sampler, ray0);
                                value1 *= integrator->Li(scene, sampler, ray1);
                                value2 *= integrator->Li(scene, sampler, ray2);
                
                                value = value0 + value1 + value2;
                            }
                        

Back in the camera, I then calculate the chromatic aberration offset and add it to the focal point.


                            Point2f aberrationOffset = chromaticAberrationWeight * centeredSamplePosition * centeredSamplePosition.squaredNorm();

                            focalPoint += Point3f(-aberrationOffset.x(), aberrationOffset.y(), 0);
                        
Mine

Here we can clearly see, how the colors seperate at the border of the image.


                        
                    
Mine

The effect can also be used in combination with other camera features.


                        

                    

Lens Distortion

For this task, I use the definition on OpenCV to set the value of a Vector2f kc. The distortion is then calculated as here


                            float r2 = dist.squaredNorm();
                            focalPoint.x() *= 1 + r2 * m_distortion.x() + r2 * r2 * m_distortion.y();
                            focalPoint.y() *= 1 + r2 * m_distortion.x() + r2 * r2 * m_distortion.y();
                        

Validation

To validate, we can compare my results with the sketches from OpenCV.

Mine OpenCV

                                
                            
Mine OpenCV

                                
                            
Mine OpenCV