Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[parse_blend_file] depth of field #139

Open
wahn opened this issue Apr 22, 2022 · 2 comments
Open

[parse_blend_file] depth of field #139

wahn opened this issue Apr 22, 2022 · 2 comments

Comments

@wahn
Copy link
Owner

wahn commented Apr 22, 2022

It would be useful to be able to specify depth of field (DOF) settings within the Blender scene and use those on the rs-pbrt side.
For .pbrt files those should work correctly already, but forparse_blend_file we still need a way how to translate the settings from the Blender UI to camera settings, which can be used for e.g. the struct PerspectiveCamera. Here an example from the Italian Flat scene:

pbrt_dof

In Blender version 2.79 the two settings in questions are shown here:

dof_blend_settings

The depth of field distance can be used as parameter focaldistance directly, but Blender's f-stop value has to be translated somehow to PBRT's lensradius (in this example I used lensradius = 0.0125):

diff --git a/src/cameras/perspective.rs b/src/cameras/perspective.rs                                  
index 92c77db..72f9d98 100644                                                                         
--- a/src/cameras/perspective.rs                                                                      
+++ b/src/cameras/perspective.rs                                                                      
@@ -173,6 +173,10 @@ impl PerspectiveCamera {                                                         
         //     params.find_one_float(String::from("halffov"), -1.0);                                 
         // TODO: if (halffov > 0.f)                                                                  
         // TODO: let perspective_camera: Arc<Camera + Sync + Send> =                                 
+       // TMP                                                                                        
+        let lensradius: Float = 0.0125;                                                              
+        let focaldistance: Float = 5.6;                                                              
+       // TMP                                                                                        
         Arc::new(Camera::Perspective(Box::new(PerspectiveCamera::new(                                
             cam2world,                                                                               
             screen,                                                                                  

The best solution would be to look into Blender's source code to find a proper translation hint.

@wahn
Copy link
Owner Author

wahn commented Apr 26, 2022

The focaldistance we need for PerspectiveCamera can be taken directly from Camera.YF_dofdist:

$ ./target/release/blend_info -n Camera.YF_dofdist ~/git/self_hosted/render_comparison/blend/italian_flat/italian_flat_v279.blend
Camera.YF_dofdist = 0_f32
Camera.YF_dofdist = 0_f32
Camera.YF_dofdist = 0_f32
Camera.YF_dofdist = 0_f32
Camera.YF_dofdist = 0_f32
Camera.YF_dofdist = 0_f32
Camera.YF_dofdist = 5.6_f32

@wahn
Copy link
Owner Author

wahn commented Apr 26, 2022

From within Blender 2.79 you can access the aperture_fstop via Python:

>>> bpy.data.cameras['Camera_Table_Details'].cycles.aperture_fstop
2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant