Changeset View
Standalone View
intern/cycles/blender/blender_camera.cpp
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | struct BlenderCamera { | ||||
| PanoramaType panorama_type; | PanoramaType panorama_type; | ||||
| float fisheye_fov; | float fisheye_fov; | ||||
| float fisheye_lens; | float fisheye_lens; | ||||
| float latitude_min; | float latitude_min; | ||||
| float latitude_max; | float latitude_max; | ||||
| float longitude_min; | float longitude_min; | ||||
| float longitude_max; | float longitude_max; | ||||
| bool use_spherical_stereo; | |||||
| float interocular_distance; | |||||
| float convergence_distance; | |||||
| enum { AUTO, HORIZONTAL, VERTICAL } sensor_fit; | enum { AUTO, HORIZONTAL, VERTICAL } sensor_fit; | ||||
| float sensor_width; | float sensor_width; | ||||
| float sensor_height; | float sensor_height; | ||||
| int full_width; | int full_width; | ||||
| int full_height; | int full_height; | ||||
| Show All 27 Lines | static void blender_camera_init(BlenderCamera *bcam, BL::RenderSettings b_render) | ||||
| bcam->full_width = render_resolution_x(b_render); | bcam->full_width = render_resolution_x(b_render); | ||||
| bcam->full_height = render_resolution_y(b_render); | bcam->full_height = render_resolution_y(b_render); | ||||
| /* pixel aspect */ | /* pixel aspect */ | ||||
| bcam->pixelaspect.x = b_render.pixel_aspect_x(); | bcam->pixelaspect.x = b_render.pixel_aspect_x(); | ||||
| bcam->pixelaspect.y = b_render.pixel_aspect_y(); | bcam->pixelaspect.y = b_render.pixel_aspect_y(); | ||||
| } | } | ||||
| static float blender_camera_focal_distance(BL::RenderEngine b_engine, BL::Object b_ob, BL::Camera b_camera) | static float blender_camera_focal_distance(BL::RenderEngine b_engine, BL::Object b_ob, BL::Camera b_camera) | ||||
sergey: Why exactly we need to have special handling of those two functions? Something tells me it's… | |||||
Not Done Inline ActionsThe RNA API (b_engine.camera_shift_x) is not aware of this special case of stereo (since Blender Internal doesn't support it). dfelinto: The RNA API (b_engine.camera_shift_x) is not aware of this special case of stereo (since… | |||||
Not Done Inline ActionsThink it's more clear to pass bcam and access to bcam->use_spherical_stereo. So if shift/matrix will ever depend on more settings you don't need to pass them sergey: Think it's more clear to pass `bcam` and access to `bcam->use_spherical_stereo`. So if… | |||||
| { | { | ||||
| BL::Object b_dof_object = b_camera.dof_object(); | BL::Object b_dof_object = b_camera.dof_object(); | ||||
Not Done Inline ActionsGuess this is because b_engine.camera_shift_x applies offset for an eye? Worth mentioning this in the comment. sergey: Guess this is because `b_engine.camera_shift_x` applies offset for an eye? Worth mentioning… | |||||
| if(!b_dof_object) | if(!b_dof_object) | ||||
| return b_camera.dof_distance(); | return b_camera.dof_distance(); | ||||
| /* for dof object, return distance along camera Z direction */ | /* for dof object, return distance along camera Z direction */ | ||||
| BL::Array<float, 16> b_ob_matrix; | BL::Array<float, 16> b_ob_matrix; | ||||
Not Done Inline ActionsSame as above. sergey: Same as above. | |||||
| b_engine.camera_model_matrix(b_ob, b_ob_matrix); | b_engine.camera_model_matrix(b_ob, b_ob_matrix); | ||||
| Transform obmat = get_transform(b_ob_matrix); | Transform obmat = transform_clear_scale(get_transform(b_ob_matrix)); | ||||
| Transform dofmat = get_transform(b_dof_object.matrix_world()); | Transform dofmat = get_transform(b_dof_object.matrix_world()); | ||||
Not Done Inline ActionsSeems phab got confused here with comments.. Still think we can make more clear Py-API for such things, but at least please bother explaining why it's special case here as well ;) sergey: Seems phab got confused here with comments..
Still think we can make more clear Py-API for… | |||||
| float3 view_dir = normalize(transform_get_column(&obmat, 2)); | float3 view_dir = normalize(transform_get_column(&obmat, 2)); | ||||
| float3 dof_dir = transform_get_column(&obmat, 3) - transform_get_column(&dofmat, 3); | float3 dof_dir = transform_get_column(&obmat, 3) - transform_get_column(&dofmat, 3); | ||||
| return fabsf(dot(view_dir, dof_dir)); | return fabsf(dot(view_dir, dof_dir)); | ||||
| } | } | ||||
| static void blender_camera_from_object(BlenderCamera *bcam, BL::RenderEngine b_engine, BL::Object b_ob, bool skip_panorama = false) | static void blender_camera_from_object(BlenderCamera *bcam, BL::RenderEngine b_engine, BL::Object b_ob, bool skip_panorama = false) | ||||
Not Done Inline ActionsSame. sergey: Same. | |||||
| { | { | ||||
| BL::ID b_ob_data = b_ob.data(); | BL::ID b_ob_data = b_ob.data(); | ||||
Not Done Inline ActionsUse RenderSettings::view_format_STEREO_3D instead of 0. sergey: Use `RenderSettings::view_format_STEREO_3D` instead of 0. | |||||
Not Done Inline Actionsdone dfelinto: done | |||||
| if(b_ob_data.is_a(&RNA_Camera)) { | if(b_ob_data.is_a(&RNA_Camera)) { | ||||
| BL::Camera b_camera(b_ob_data); | BL::Camera b_camera(b_ob_data); | ||||
| PointerRNA ccamera = RNA_pointer_get(&b_camera.ptr, "cycles"); | PointerRNA ccamera = RNA_pointer_get(&b_camera.ptr, "cycles"); | ||||
| bcam->nearclip = b_camera.clip_start(); | bcam->nearclip = b_camera.clip_start(); | ||||
| bcam->farclip = b_camera.clip_end(); | bcam->farclip = b_camera.clip_end(); | ||||
| switch(b_camera.type()) | switch(b_camera.type()) | ||||
| Show All 32 Lines | if(b_ob_data.is_a(&RNA_Camera)) { | ||||
| bcam->fisheye_fov = RNA_float_get(&ccamera, "fisheye_fov"); | bcam->fisheye_fov = RNA_float_get(&ccamera, "fisheye_fov"); | ||||
| bcam->fisheye_lens = RNA_float_get(&ccamera, "fisheye_lens"); | bcam->fisheye_lens = RNA_float_get(&ccamera, "fisheye_lens"); | ||||
| bcam->latitude_min = RNA_float_get(&ccamera, "latitude_min"); | bcam->latitude_min = RNA_float_get(&ccamera, "latitude_min"); | ||||
| bcam->latitude_max = RNA_float_get(&ccamera, "latitude_max"); | bcam->latitude_max = RNA_float_get(&ccamera, "latitude_max"); | ||||
| bcam->longitude_min = RNA_float_get(&ccamera, "longitude_min"); | bcam->longitude_min = RNA_float_get(&ccamera, "longitude_min"); | ||||
| bcam->longitude_max = RNA_float_get(&ccamera, "longitude_max"); | bcam->longitude_max = RNA_float_get(&ccamera, "longitude_max"); | ||||
| bcam->interocular_distance = b_camera.stereo().interocular_distance(); | |||||
| bcam->convergence_distance = b_camera.stereo().convergence_distance(); | |||||
| bcam->use_spherical_stereo = b_engine.use_spherical_stereo(b_ob); | |||||
| bcam->ortho_scale = b_camera.ortho_scale(); | bcam->ortho_scale = b_camera.ortho_scale(); | ||||
| bcam->lens = b_camera.lens(); | bcam->lens = b_camera.lens(); | ||||
| /* allow f/stop number to change aperture_size but still | /* allow f/stop number to change aperture_size but still | ||||
| * give manual control over aperture radius */ | * give manual control over aperture radius */ | ||||
| int aperture_type = RNA_enum_get(&ccamera, "aperture_type"); | int aperture_type = RNA_enum_get(&ccamera, "aperture_type"); | ||||
| ▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | if(viewplane != NULL) { | ||||
| viewplane->left += dx; | viewplane->left += dx; | ||||
| viewplane->right += dx; | viewplane->right += dx; | ||||
| viewplane->bottom += dy; | viewplane->bottom += dy; | ||||
| viewplane->top += dy; | viewplane->top += dy; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int height) | static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int height, const char *viewname) | ||||
| { | { | ||||
| /* copy camera to compare later */ | /* copy camera to compare later */ | ||||
| Camera prevcam = *cam; | Camera prevcam = *cam; | ||||
| float aspectratio, sensor_size; | float aspectratio, sensor_size; | ||||
| /* viewplane */ | /* viewplane */ | ||||
| blender_camera_viewplane(bcam, width, height, | blender_camera_viewplane(bcam, width, height, | ||||
| &cam->viewplane, &aspectratio, &sensor_size); | &cam->viewplane, &aspectratio, &sensor_size); | ||||
| Show All 40 Lines | static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int height, const char *viewname) | ||||
| cam->fisheye_fov = bcam->fisheye_fov; | cam->fisheye_fov = bcam->fisheye_fov; | ||||
| cam->fisheye_lens = bcam->fisheye_lens; | cam->fisheye_lens = bcam->fisheye_lens; | ||||
| cam->latitude_min = bcam->latitude_min; | cam->latitude_min = bcam->latitude_min; | ||||
| cam->latitude_max = bcam->latitude_max; | cam->latitude_max = bcam->latitude_max; | ||||
| cam->longitude_min = bcam->longitude_min; | cam->longitude_min = bcam->longitude_min; | ||||
| cam->longitude_max = bcam->longitude_max; | cam->longitude_max = bcam->longitude_max; | ||||
| /* panorama stereo */ | |||||
| cam->interocular_distance = bcam->interocular_distance; | |||||
| cam->convergence_distance = bcam->convergence_distance; | |||||
| cam->use_spherical_stereo = bcam->use_spherical_stereo; | |||||
| if(cam->use_spherical_stereo) { | |||||
| if(strcmp(viewname, "left") == 0) | |||||
| cam->stereo_eye = STEREO_LEFT; | |||||
Not Done Inline ActionsThink we can avoid exposing eyes to the underlying camera classes. See comments below in the kernel. sergey: Think we can avoid exposing eyes to the underlying camera classes. See comments below in the… | |||||
| else if(strcmp(viewname, "right") == 0) | |||||
| cam->stereo_eye = STEREO_RIGHT; | |||||
| else | |||||
| cam->stereo_eye = STEREO_NONE; | |||||
| } | |||||
| /* anamorphic lens bokeh */ | /* anamorphic lens bokeh */ | ||||
| cam->aperture_ratio = bcam->aperture_ratio; | 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; | ||||
| cam->aperturesize = bcam->aperturesize; | cam->aperturesize = bcam->aperturesize; | ||||
| cam->blades = bcam->apertureblades; | cam->blades = bcam->apertureblades; | ||||
| Show All 20 Lines | static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int height, const char *viewname) | ||||
| /* set update flag */ | /* set update flag */ | ||||
| if(cam->modified(prevcam)) | if(cam->modified(prevcam)) | ||||
| cam->tag_update(); | cam->tag_update(); | ||||
| } | } | ||||
| /* Sync Render Camera */ | /* Sync Render Camera */ | ||||
| void BlenderSync::sync_camera(BL::RenderSettings b_render, BL::Object b_override, int width, int height) | void BlenderSync::sync_camera(BL::RenderSettings b_render, BL::Object b_override, int width, int height, const char *viewname) | ||||
| { | { | ||||
| BlenderCamera bcam; | BlenderCamera bcam; | ||||
| blender_camera_init(&bcam, b_render); | blender_camera_init(&bcam, b_render); | ||||
| /* pixel aspect */ | /* pixel aspect */ | ||||
| bcam.pixelaspect.x = b_render.pixel_aspect_x(); | bcam.pixelaspect.x = b_render.pixel_aspect_x(); | ||||
| bcam.pixelaspect.y = b_render.pixel_aspect_y(); | bcam.pixelaspect.y = b_render.pixel_aspect_y(); | ||||
| bcam.shuttertime = b_render.motion_blur_shutter(); | bcam.shuttertime = b_render.motion_blur_shutter(); | ||||
| Show All 35 Lines | if(b_ob) { | ||||
| BL::Array<float, 16> b_ob_matrix; | BL::Array<float, 16> b_ob_matrix; | ||||
| blender_camera_from_object(&bcam, b_engine, b_ob); | blender_camera_from_object(&bcam, b_engine, b_ob); | ||||
| b_engine.camera_model_matrix(b_ob, b_ob_matrix); | b_engine.camera_model_matrix(b_ob, b_ob_matrix); | ||||
| bcam.matrix = get_transform(b_ob_matrix); | bcam.matrix = get_transform(b_ob_matrix); | ||||
| } | } | ||||
| /* sync */ | /* sync */ | ||||
| Camera *cam = scene->camera; | Camera *cam = scene->camera; | ||||
| blender_camera_sync(cam, &bcam, width, height); | blender_camera_sync(cam, &bcam, width, height, viewname); | ||||
| } | } | ||||
| void BlenderSync::sync_camera_motion(BL::RenderSettings b_render, | void BlenderSync::sync_camera_motion(BL::RenderSettings b_render, | ||||
| BL::Object b_ob, | BL::Object b_ob, | ||||
Not Done Inline ActionsSome API questions. Is it always limited to "left" and "right"? Is there some non-string constants to distinguish those two? sergey: Some API questions.
Is it always limited to "left" and "right"? Is there some non-string… | |||||
Not Done Inline ActionsIt is always limited to "left" and "right", and we have the constants in Blender (STEREO_LEFT_NAME/STEREO_RIGHT_NAME). I wasn't sure how to proceed here (whether to expose the Blender constants to Cycles, or to re-define them here) dfelinto: It is always limited to "left" and "right", and we have the constants in Blender… | |||||
Not Done Inline ActionsThat's a bit weird:
So seems would have some redundant updates. sergey: That's a bit weird:
- Cycles sets current view to the render engine, so in theory it knows… | |||||
| int width, int height, | int width, int height, | ||||
| float motion_time) | float motion_time) | ||||
Not Done Inline ActionsWould it make sense to have some sort of view.type which could be {VIEW_LEFT, VIEW_RIGHT, VIEW_CUSTOM}? sergey: Would it make sense to have some sort of `view.type` which could be `{VIEW_LEFT, VIEW_RIGHT… | |||||
| { | { | ||||
| if(!b_ob) | if(!b_ob) | ||||
| return; | return; | ||||
| Camera *cam = scene->camera; | Camera *cam = scene->camera; | ||||
| BL::Array<float, 16> b_ob_matrix; | BL::Array<float, 16> b_ob_matrix; | ||||
| b_engine.camera_model_matrix(b_ob, b_ob_matrix); | b_engine.camera_model_matrix(b_ob, b_ob_matrix); | ||||
| Transform tfm = get_transform(b_ob_matrix); | Transform tfm = get_transform(b_ob_matrix); | ||||
Not Done Inline ActionsThat' wrong. Camera is to be tagged for update only if it was modified, which is already checked in blender_camera_sync. So my guess this code belongs to other place of the file and no force tag is needed. sergey: That' wrong. Camera is to be tagged for update only if it was modified, which is already… | |||||
| tfm = blender_camera_matrix(tfm, cam->type, cam->panorama_type); | tfm = blender_camera_matrix(tfm, cam->type, cam->panorama_type); | ||||
| if(tfm != cam->matrix) { | if(tfm != cam->matrix) { | ||||
| VLOG(1) << "Camera " << b_ob.name() << " motion detected."; | VLOG(1) << "Camera " << b_ob.name() << " motion detected."; | ||||
| if(motion_time == -1.0f) { | if(motion_time == -1.0f) { | ||||
| cam->motion.pre = tfm; | cam->motion.pre = tfm; | ||||
| cam->use_motion = true; | cam->use_motion = true; | ||||
| } | } | ||||
| else if(motion_time == 1.0f) { | else if(motion_time == 1.0f) { | ||||
| cam->motion.post = tfm; | cam->motion.post = tfm; | ||||
| cam->use_motion = true; | cam->use_motion = true; | ||||
| } | } | ||||
| } | } | ||||
| if(cam->type == CAMERA_PERSPECTIVE) { | if(cam->type == CAMERA_PERSPECTIVE) { | ||||
| BlenderCamera bcam; | BlenderCamera bcam; | ||||
| float aspectratio, sensor_size; | float aspectratio, sensor_size; | ||||
| blender_camera_init(&bcam, b_render); | blender_camera_init(&bcam, b_render); | ||||
| blender_camera_from_object(&bcam, b_engine, b_ob); | blender_camera_from_object(&bcam, b_engine, b_ob); | ||||
| blender_camera_viewplane(&bcam, | blender_camera_viewplane(&bcam, | ||||
| width, height, | width, height, | ||||
| NULL, | NULL, | ||||
| &aspectratio, | &aspectratio, | ||||
| &sensor_size); | &sensor_size); | ||||
| /* TODO(sergey): De-duplicate calculation with camera sync. */ | /* TODO(sergey): De-duplicate calculation with camera sync. */ | ||||
| float fov = 2.0f * atanf((0.5f * sensor_size) / bcam.lens / aspectratio); | float fov = 2.0f * atanf((0.5f * sensor_size) / bcam.lens / aspectratio); | ||||
| ▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | |||||
| void BlenderSync::sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height) | void BlenderSync::sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height) | ||||
| { | { | ||||
| BlenderCamera bcam; | BlenderCamera bcam; | ||||
| blender_camera_init(&bcam, b_scene.render()); | blender_camera_init(&bcam, b_scene.render()); | ||||
| blender_camera_from_view(&bcam, b_engine, b_scene, b_v3d, b_rv3d, width, height); | blender_camera_from_view(&bcam, b_engine, b_scene, b_v3d, b_rv3d, width, height); | ||||
| blender_camera_border(&bcam, b_engine, b_scene.render(), b_scene, b_v3d, b_rv3d, width, height); | blender_camera_border(&bcam, b_engine, b_scene.render(), b_scene, b_v3d, b_rv3d, width, height); | ||||
| blender_camera_sync(scene->camera, &bcam, width, height); | blender_camera_sync(scene->camera, &bcam, width, height, ""); | ||||
| } | } | ||||
| BufferParams BlenderSync::get_buffer_params(BL::RenderSettings b_render, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, Camera *cam, int width, int height) | BufferParams BlenderSync::get_buffer_params(BL::RenderSettings b_render, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, Camera *cam, int width, int height) | ||||
| { | { | ||||
| BufferParams params; | BufferParams params; | ||||
| bool use_border = false; | bool use_border = false; | ||||
| params.full_width = width; | params.full_width = width; | ||||
| Show All 30 Lines | |||||
Why exactly we need to have special handling of those two functions? Something tells me it's better idea to make it so camera's RNA API will be giving you proper shift/matrix depending on it's settings? Might be missing something tho..