Cycles Aperture Ratio - option to produce anamorphic bokeh

Thanks for Aldo Zang for the help with the fix for the panorama/fisheye
depth of field calculation and the overall math.

Reviewed By: sergey, dingto

Subscribers: juicyfruit, gregzaal, #cycles, dingto, matray

Differential Revision: https://developer.blender.org/D753
This commit is contained in:
Dalai Felinto 2014-08-27 10:51:50 +02:00
parent 9b9ddb4669
commit 146ed67d55
8 changed files with 38 additions and 4 deletions

View File

@ -329,6 +329,7 @@ static void xml_read_camera(const XMLReadState& state, pugi::xml_node node)
xml_read_float(&cam->aperturesize, node, "aperturesize"); // 0.5*focallength/fstop
xml_read_float(&cam->focaldistance, node, "focaldistance");
xml_read_float(&cam->shuttertime, node, "shuttertime");
xml_read_float(&cam->aperture_ratio, node, "aperture_ratio");
if(xml_equal_string(node, "type", "orthographic"))
cam->type = CAMERA_ORTHOGRAPHIC;

View File

@ -544,6 +544,13 @@ class CyclesCameraSettings(bpy.types.PropertyGroup):
subtype='ANGLE',
default=0,
)
cls.aperture_ratio = FloatProperty(
name="Aperture Ratio",
description="Distortion to simulate anamorphic lens bokeh",
min=0.01, soft_min=1.0, soft_max=2.0,
default=1.0,
precision=4,
)
cls.panorama_type = EnumProperty(
name="Panorama Type",
description="Distortion to use for the calculation",

View File

@ -468,6 +468,7 @@ class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
sub = col.column(align=True)
sub.prop(ccam, "aperture_blades", text="Blades")
sub.prop(ccam, "aperture_rotation", text="Rotation")
sub.prop(ccam, "aperture_ratio", text="Ratio")
class Cycles_PT_context_material(CyclesButtonsPanel, Panel):

View File

@ -46,6 +46,8 @@ struct BlenderCamera {
float2 pixelaspect;
float aperture_ratio;
PanoramaType panorama_type;
float fisheye_fov;
float fisheye_lens;
@ -167,6 +169,7 @@ static void blender_camera_from_object(BlenderCamera *bcam, BL::Object b_ob, boo
bcam->apertureblades = RNA_int_get(&ccamera, "aperture_blades");
bcam->aperturerotation = RNA_float_get(&ccamera, "aperture_rotation");
bcam->focaldistance = blender_camera_focal_distance(b_ob, b_camera);
bcam->aperture_ratio = RNA_float_get(&ccamera, "aperture_ratio");
bcam->shift.x = b_camera.shift_x();
bcam->shift.y = b_camera.shift_y();
@ -328,6 +331,9 @@ static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int
cam->fisheye_fov = bcam->fisheye_fov;
cam->fisheye_lens = bcam->fisheye_lens;
/* anamorphic lens bokeh */
cam->aperture_ratio = bcam->aperture_ratio;
/* perspective */
cam->fov = 2.0f * atanf((0.5f * sensor_size) / bcam->lens / aspectratio);
cam->focaldistance = bcam->focaldistance;

View File

@ -21,16 +21,22 @@ CCL_NAMESPACE_BEGIN
ccl_device float2 camera_sample_aperture(KernelGlobals *kg, float u, float v)
{
float blades = kernel_data.cam.blades;
float2 bokeh;
if(blades == 0.0f) {
/* sample disk */
return concentric_sample_disk(u, v);
bokeh = concentric_sample_disk(u, v);
}
else {
/* sample polygon */
float rotation = kernel_data.cam.bladesrotation;
return regular_polygon_sample(blades, rotation, u, v);
bokeh = regular_polygon_sample(blades, rotation, u, v);
}
/* anamorphic lens bokeh */
bokeh.x *= kernel_data.cam.inv_aperture_ratio;
return bokeh;
}
ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, float raster_y, float lens_u, float lens_v, Ray *ray)
@ -183,7 +189,8 @@ ccl_device void camera_sample_panorama(KernelGlobals *kg, float raster_x, float
/* calculate orthonormal coordinates perpendicular to D */
float3 U, V;
make_orthonormals(D, &U, &V);
U = normalize(make_float3(1.0f, 0.0f, 0.0f) - D.x * D);
V = normalize(cross(D, U));
/* update ray for effect of lens */
ray->P = U * lensuv.x + V * lensuv.y;

View File

@ -761,9 +761,12 @@ typedef struct KernelCamera {
/* render size */
float width, height;
int resolution;
/* anamorphic lens bokeh */
float inv_aperture_ratio;
int pad1;
int pad2;
int pad3;
/* more matrices */
Transform screentoworld;

View File

@ -38,6 +38,8 @@ Camera::Camera()
motion.post = transform_identity();
use_motion = false;
aperture_ratio = 1.0f;
type = CAMERA_PERSPECTIVE;
panorama_type = PANORAMA_EQUIRECTANGULAR;
fisheye_fov = M_PI_F;
@ -241,6 +243,9 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
/* type */
kcam->type = type;
/* anamorphic lens bokeh */
kcam->inv_aperture_ratio = 1.0f / aperture_ratio;
/* panorama */
kcam->panorama_type = panorama_type;
kcam->fisheye_fov = fisheye_fov;
@ -291,6 +296,7 @@ bool Camera::modified(const Camera& cam)
(viewplane == cam.viewplane) &&
(border == cam.border) &&
(matrix == cam.matrix) &&
(aperture_ratio == cam.aperture_ratio) &&
(panorama_type == cam.panorama_type) &&
(fisheye_fov == cam.fisheye_fov) &&
(fisheye_lens == cam.fisheye_lens));

View File

@ -54,6 +54,9 @@ public:
float fisheye_fov;
float fisheye_lens;
/* anamorphic lens bokeh */
float aperture_ratio;
/* sensor */
float sensorwidth;
float sensorheight;