Cycles: option to specify camera aperture in radius or f/stop:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 7 Mar 2012 13:01:30 +0000 (13:01 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 7 Mar 2012 13:01:30 +0000 (13:01 +0000)
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Camera#Depth_of_Field

Patch by Ejner Fergo.

intern/cycles/blender/addon/enums.py
intern/cycles/blender/addon/properties.py
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_camera.cpp

index e1b138def3c1aea2da7ca3fb9f68c91b5ba117c8..889a8f03552565e6c004116ae2d8b96b8a9e0e74 100644 (file)
@@ -49,3 +49,9 @@ filter_types = (
     ("BOX", "Box", "Box filter"),
     ("GAUSSIAN", "Gaussian", "Gaussian filter"),
     )
+
+aperture_types = (
+    ("RADIUS", "Radius", "Directly change the size of the aperture"),
+    ("FSTOP", "F/stop", "Change the size of the aperture by f/stops"),
+    )
+
index 7e7e83b4f69b99f2e6247e5b1b81d58581780f97..751baedca455e60b6cb135a3767677f55952a41f 100644 (file)
@@ -231,11 +231,27 @@ class CyclesCameraSettings(bpy.types.PropertyGroup):
                 type=cls,
                 )
 
+        cls.aperture_type = EnumProperty(
+                name="Aperture Type",
+                description="Use f/stop number or aperture radius",
+                items=enums.aperture_types,
+                default='RADIUS',
+                )
+        cls.aperture_fstop = FloatProperty(
+                name="Aperture F/stop",
+                description="F/stop ratio (lower numbers equals more bokeh while higher numbers equals less bokeh)",
+                min=0.0, soft_min=0.1, soft_max=64.0,
+                default=5.6,
+                step=10,
+                precision=1,
+                )
         cls.aperture_size = FloatProperty(
                 name="Aperture Size",
                 description="Radius of the aperture for depth of field",
-                min=0.0, max=10.0,
+                min=0.0, soft_max=10.0,
                 default=0.0,
+                step=1,
+                precision=4,
                 )
         cls.aperture_blades = IntProperty(
                 name="Aperture Blades",
index faf057e13cc63eaaf94d16c0ea91c30eabba9992..a8f499cf324fd71888713523ff5aaab2dd7dda51 100644 (file)
@@ -263,7 +263,12 @@ class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
         col = split.column()
 
         col.label("Aperture:")
-        col.prop(ccam, "aperture_size", text="Size")
+        sub = col.column(align=True)
+        sub.prop(ccam, "aperture_type", text="")
+        if ccam.aperture_type == 'RADIUS':
+            sub.prop(ccam, "aperture_size", text="Size")
+        elif ccam.aperture_type == 'FSTOP':
+            sub.prop(ccam, "aperture_fstop", text="Number")
 
         sub = col.column(align=True)
         sub.prop(ccam, "aperture_blades", text="Blades")
index 7c9c162f8b1080c4566f313b1b57651298c9d0bc..e7704c5f885b7245950719d6aeb8c9b87ae2dcd5 100644 (file)
@@ -98,7 +98,18 @@ static void blender_camera_from_object(BlenderCamera *bcam, BL::Object b_ob)
                bcam->ortho_scale = b_camera.ortho_scale();
 
                bcam->lens = b_camera.lens();
-               bcam->aperturesize = RNA_float_get(&ccamera, "aperture_size");
+
+               /* allow f/stop number to change aperture_size but still
+                  give manual control over aperture radius */
+               int aperture_type = RNA_enum_get(&ccamera, "aperture_type");
+
+               if(aperture_type == 1) {
+                       float fstop = RNA_float_get(&ccamera, "aperture_fstop");
+                       bcam->aperturesize = (bcam->lens*1e-3f)/(2.0f*max(fstop, 1e-5f));
+               }
+               else
+                       bcam->aperturesize = RNA_float_get(&ccamera, "aperture_size");
+
                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);