forked from bartvdbraak/blender
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:
parent
9b9ddb4669
commit
146ed67d55
@ -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->aperturesize, node, "aperturesize"); // 0.5*focallength/fstop
|
||||||
xml_read_float(&cam->focaldistance, node, "focaldistance");
|
xml_read_float(&cam->focaldistance, node, "focaldistance");
|
||||||
xml_read_float(&cam->shuttertime, node, "shuttertime");
|
xml_read_float(&cam->shuttertime, node, "shuttertime");
|
||||||
|
xml_read_float(&cam->aperture_ratio, node, "aperture_ratio");
|
||||||
|
|
||||||
if(xml_equal_string(node, "type", "orthographic"))
|
if(xml_equal_string(node, "type", "orthographic"))
|
||||||
cam->type = CAMERA_ORTHOGRAPHIC;
|
cam->type = CAMERA_ORTHOGRAPHIC;
|
||||||
|
@ -544,6 +544,13 @@ class CyclesCameraSettings(bpy.types.PropertyGroup):
|
|||||||
subtype='ANGLE',
|
subtype='ANGLE',
|
||||||
default=0,
|
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(
|
cls.panorama_type = EnumProperty(
|
||||||
name="Panorama Type",
|
name="Panorama Type",
|
||||||
description="Distortion to use for the calculation",
|
description="Distortion to use for the calculation",
|
||||||
|
@ -468,6 +468,7 @@ class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
|
|||||||
sub = col.column(align=True)
|
sub = col.column(align=True)
|
||||||
sub.prop(ccam, "aperture_blades", text="Blades")
|
sub.prop(ccam, "aperture_blades", text="Blades")
|
||||||
sub.prop(ccam, "aperture_rotation", text="Rotation")
|
sub.prop(ccam, "aperture_rotation", text="Rotation")
|
||||||
|
sub.prop(ccam, "aperture_ratio", text="Ratio")
|
||||||
|
|
||||||
|
|
||||||
class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
|
class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
|
||||||
|
@ -46,6 +46,8 @@ struct BlenderCamera {
|
|||||||
|
|
||||||
float2 pixelaspect;
|
float2 pixelaspect;
|
||||||
|
|
||||||
|
float aperture_ratio;
|
||||||
|
|
||||||
PanoramaType panorama_type;
|
PanoramaType panorama_type;
|
||||||
float fisheye_fov;
|
float fisheye_fov;
|
||||||
float fisheye_lens;
|
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->apertureblades = RNA_int_get(&ccamera, "aperture_blades");
|
||||||
bcam->aperturerotation = RNA_float_get(&ccamera, "aperture_rotation");
|
bcam->aperturerotation = RNA_float_get(&ccamera, "aperture_rotation");
|
||||||
bcam->focaldistance = blender_camera_focal_distance(b_ob, b_camera);
|
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.x = b_camera.shift_x();
|
||||||
bcam->shift.y = b_camera.shift_y();
|
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_fov = bcam->fisheye_fov;
|
||||||
cam->fisheye_lens = bcam->fisheye_lens;
|
cam->fisheye_lens = bcam->fisheye_lens;
|
||||||
|
|
||||||
|
/* anamorphic lens bokeh */
|
||||||
|
cam->aperture_ratio = bcam->aperture_ratio;
|
||||||
|
|
||||||
/* perspective */
|
/* perspective */
|
||||||
cam->fov = 2.0f * atanf((0.5f * sensor_size) / bcam->lens / aspectratio);
|
cam->fov = 2.0f * atanf((0.5f * sensor_size) / bcam->lens / aspectratio);
|
||||||
cam->focaldistance = bcam->focaldistance;
|
cam->focaldistance = bcam->focaldistance;
|
||||||
|
@ -21,16 +21,22 @@ CCL_NAMESPACE_BEGIN
|
|||||||
ccl_device float2 camera_sample_aperture(KernelGlobals *kg, float u, float v)
|
ccl_device float2 camera_sample_aperture(KernelGlobals *kg, float u, float v)
|
||||||
{
|
{
|
||||||
float blades = kernel_data.cam.blades;
|
float blades = kernel_data.cam.blades;
|
||||||
|
float2 bokeh;
|
||||||
|
|
||||||
if(blades == 0.0f) {
|
if(blades == 0.0f) {
|
||||||
/* sample disk */
|
/* sample disk */
|
||||||
return concentric_sample_disk(u, v);
|
bokeh = concentric_sample_disk(u, v);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* sample polygon */
|
/* sample polygon */
|
||||||
float rotation = kernel_data.cam.bladesrotation;
|
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)
|
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 */
|
/* calculate orthonormal coordinates perpendicular to D */
|
||||||
float3 U, V;
|
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 */
|
/* update ray for effect of lens */
|
||||||
ray->P = U * lensuv.x + V * lensuv.y;
|
ray->P = U * lensuv.x + V * lensuv.y;
|
||||||
|
@ -761,9 +761,12 @@ typedef struct KernelCamera {
|
|||||||
/* render size */
|
/* render size */
|
||||||
float width, height;
|
float width, height;
|
||||||
int resolution;
|
int resolution;
|
||||||
|
|
||||||
|
/* anamorphic lens bokeh */
|
||||||
|
float inv_aperture_ratio;
|
||||||
|
|
||||||
int pad1;
|
int pad1;
|
||||||
int pad2;
|
int pad2;
|
||||||
int pad3;
|
|
||||||
|
|
||||||
/* more matrices */
|
/* more matrices */
|
||||||
Transform screentoworld;
|
Transform screentoworld;
|
||||||
|
@ -38,6 +38,8 @@ Camera::Camera()
|
|||||||
motion.post = transform_identity();
|
motion.post = transform_identity();
|
||||||
use_motion = false;
|
use_motion = false;
|
||||||
|
|
||||||
|
aperture_ratio = 1.0f;
|
||||||
|
|
||||||
type = CAMERA_PERSPECTIVE;
|
type = CAMERA_PERSPECTIVE;
|
||||||
panorama_type = PANORAMA_EQUIRECTANGULAR;
|
panorama_type = PANORAMA_EQUIRECTANGULAR;
|
||||||
fisheye_fov = M_PI_F;
|
fisheye_fov = M_PI_F;
|
||||||
@ -241,6 +243,9 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
|||||||
/* type */
|
/* type */
|
||||||
kcam->type = type;
|
kcam->type = type;
|
||||||
|
|
||||||
|
/* anamorphic lens bokeh */
|
||||||
|
kcam->inv_aperture_ratio = 1.0f / aperture_ratio;
|
||||||
|
|
||||||
/* panorama */
|
/* panorama */
|
||||||
kcam->panorama_type = panorama_type;
|
kcam->panorama_type = panorama_type;
|
||||||
kcam->fisheye_fov = fisheye_fov;
|
kcam->fisheye_fov = fisheye_fov;
|
||||||
@ -291,6 +296,7 @@ bool Camera::modified(const Camera& cam)
|
|||||||
(viewplane == cam.viewplane) &&
|
(viewplane == cam.viewplane) &&
|
||||||
(border == cam.border) &&
|
(border == cam.border) &&
|
||||||
(matrix == cam.matrix) &&
|
(matrix == cam.matrix) &&
|
||||||
|
(aperture_ratio == cam.aperture_ratio) &&
|
||||||
(panorama_type == cam.panorama_type) &&
|
(panorama_type == cam.panorama_type) &&
|
||||||
(fisheye_fov == cam.fisheye_fov) &&
|
(fisheye_fov == cam.fisheye_fov) &&
|
||||||
(fisheye_lens == cam.fisheye_lens));
|
(fisheye_lens == cam.fisheye_lens));
|
||||||
|
@ -54,6 +54,9 @@ public:
|
|||||||
float fisheye_fov;
|
float fisheye_fov;
|
||||||
float fisheye_lens;
|
float fisheye_lens;
|
||||||
|
|
||||||
|
/* anamorphic lens bokeh */
|
||||||
|
float aperture_ratio;
|
||||||
|
|
||||||
/* sensor */
|
/* sensor */
|
||||||
float sensorwidth;
|
float sensorwidth;
|
||||||
float sensorheight;
|
float sensorheight;
|
||||||
|
Loading…
Reference in New Issue
Block a user