Hydra: Use BKE_camera_params API to simplify camera code and share more with rest of Blender #114370

Merged
Brecht Van Lommel merged 20 commits from DagerD/blender:hydra-camera-refactoring into main 2023-11-15 19:03:31 +01:00

Purpose

Use BKE_camera_params API to simplify camera code and share more with rest of Blender.

Technical steps

Code rewritten using BKE_camera_params API
Removed code for PANO camera, since it's unsupported

Ref: #110765

### Purpose Use `BKE_camera_params` API to simplify camera code and share more with rest of Blender. ### Technical steps Code rewritten using `BKE_camera_params` API Removed code for `PANO` camera, since it's unsupported Ref: https://projects.blender.org/blender/blender/issues/110765
Georgiy Markelov added 2 commits 2023-11-01 16:00:23 +01:00
Georgiy Markelov requested review from Brian Savery (AMD) 2023-11-01 16:01:18 +01:00
Georgiy Markelov requested review from Vasyl Pidhirskyi 2023-11-01 16:01:18 +01:00
Vasyl Pidhirskyi requested changes 2023-11-02 14:36:22 +01:00
@ -48,3 +52,4 @@
float o_size = region_data->dist * sensor_size / camera_params_.lens;
float o_depth = v3d->clip_end;
clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5);

We could use this:
clip_range_ = pxr::GfRange1f(camera_params_.clip_start, camera_params_.clip_end);

instead of this:

float o_depth = v3d->clip_end;

clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5);
We could use this: `clip_range_ = pxr::GfRange1f(camera_params_.clip_start, camera_params_.clip_end);` instead of this: ``` float o_depth = v3d->clip_end; clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5); ```
DagerD marked this conversation as resolved
Georgiy Markelov added 4 commits 2023-11-07 17:04:09 +01:00
Georgiy Markelov added 1 commit 2023-11-07 17:11:58 +01:00
Georgiy Markelov added 1 commit 2023-11-07 17:18:04 +01:00
Bogdan Nagirniak added 1 commit 2023-11-08 16:29:44 +01:00
Bogdan Nagirniak added 1 commit 2023-11-08 20:10:40 +01:00
Bogdan Nagirniak added 1 commit 2023-11-08 20:34:11 +01:00
Bogdan Nagirniak approved these changes 2023-11-08 20:35:11 +01:00
Bogdan Nagirniak left a comment
Contributor

Made code improvements + moved camera.cc/.h to bf_render_hydra project.
Tested - works good.

Made code improvements + moved `camera.cc/.h` to `bf_render_hydra` project. Tested - works good.
Georgiy Markelov requested review from Vasyl Pidhirskyi 2023-11-09 09:04:07 +01:00
Georgiy Markelov requested review from Brecht Van Lommel 2023-11-09 09:04:19 +01:00
Vasyl Pidhirskyi requested changes 2023-11-09 15:41:12 +01:00
Vasyl Pidhirskyi left a comment
Member

gf_camera.SetFocalLength is missing.

`gf_camera.SetFocalLength` is missing.
Georgiy Markelov added 1 commit 2023-11-09 16:10:15 +01:00
Brecht Van Lommel requested changes 2023-11-09 16:57:51 +01:00
@ -0,0 +61,4 @@
pxr::GfVec2f ortho_size;
pxr::GfMatrix4d transform =
io::hydra::gf_matrix_from_transform(region_data->viewmat).GetInverse();
clip_range = pxr::GfRange1f(camera_params.clip_start, camera_params.clip_end);

There is still a lot of duplicated logic here, BKE_camera_params_from_view3d already abstracts most of the differences.

This whole switch could probably be replaced by this, but have not tested:

  const float fit_width = (region_data->persp == RV3D_CAMOB) ? rd->xasp * rd->xsch : region->winx;
  const float fit_height = (region_data->persp == RV3D_CAMOB) ? rd->yasp * rd->ysch : region->winy;
  const int sensor_fit = BKE_camera_sensor_fit(camera_params.sensor_fit, fit_width, fit_height);
  const pxr::GfVec2f sensor_fit_scale = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ?
                                            pxr::GfVec2f(1.0f, ratio) :
                                            pxr::GfVec2f(1.0f / ratio, 1.0f);

  const float camera_sensor_size = BKE_camera_sensor_size(
      sensor_fit, camera_params.sensor_x, camera_params.sensor_y);
  aperture = pxr::GfVec2f((camera_params.is_ortho) ? camera_params.ortho_scale : 
                                                     camera_sensor_size);
  aperture = pxr::GfCompMult(aperture, sensor_fit_scale);
  aperture *= camera_params.zoom;

  lens_shift = pxr::GfVec2f(camera_params.shiftx, camera_params.shifty);
  lens_shift = pxr::GfCompMult(lens_shift, sensor_fit_scale);
  lens_shift += pxr::GfVec2f(camera_params.offsetx, camera_params.offsety) * 2;
  lens_shift /= camera_params.zoom;
There is still a lot of duplicated logic here, `BKE_camera_params_from_view3d` already abstracts most of the differences. This whole switch could probably be replaced by this, but have not tested: ``` const float fit_width = (region_data->persp == RV3D_CAMOB) ? rd->xasp * rd->xsch : region->winx; const float fit_height = (region_data->persp == RV3D_CAMOB) ? rd->yasp * rd->ysch : region->winy; const int sensor_fit = BKE_camera_sensor_fit(camera_params.sensor_fit, fit_width, fit_height); const pxr::GfVec2f sensor_fit_scale = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? pxr::GfVec2f(1.0f, ratio) : pxr::GfVec2f(1.0f / ratio, 1.0f); const float camera_sensor_size = BKE_camera_sensor_size( sensor_fit, camera_params.sensor_x, camera_params.sensor_y); aperture = pxr::GfVec2f((camera_params.is_ortho) ? camera_params.ortho_scale : camera_sensor_size); aperture = pxr::GfCompMult(aperture, sensor_fit_scale); aperture *= camera_params.zoom; lens_shift = pxr::GfVec2f(camera_params.shiftx, camera_params.shifty); lens_shift = pxr::GfCompMult(lens_shift, sensor_fit_scale); lens_shift += pxr::GfVec2f(camera_params.offsetx, camera_params.offsety) * 2; lens_shift /= camera_params.zoom; ```
brecht marked this conversation as resolved
@ -0,0 +214,4 @@
pxr::GfRange1f clip_range = pxr::GfRange1f(camera_params.clip_start, camera_params.clip_end);
float ratio = float(res[0]) / res[1];

This could be simplified similar to what I suggested above.

This could be simplified similar to what I suggested above.
brecht marked this conversation as resolved
Georgiy Markelov added 2 commits 2023-11-13 13:00:48 +01:00
Bogdan Nagirniak added 1 commit 2023-11-14 11:18:02 +01:00
Bogdan Nagirniak added 1 commit 2023-11-14 15:25:26 +01:00
397a56a476 Removed create_gf_camera() as not needed.
Finished gf_camera() from camera object.
Bogdan Nagirniak added 2 commits 2023-11-14 17:39:08 +01:00
Bogdan Nagirniak added 1 commit 2023-11-14 17:43:50 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
41fee1d6cb
Removed redundant includes
Bogdan Nagirniak approved these changes 2023-11-14 17:50:19 +01:00
Bogdan Nagirniak left a comment
Contributor

Simplified code:

  • made GfCamera calculation fully from CameraParams
  • fixed camera calculation for viewport and final renders.

Tested - works good.

Simplified code: - made `GfCamera` calculation fully from `CameraParams` - fixed camera calculation for viewport and final renders. Tested - works good.
Brecht Van Lommel approved these changes 2023-11-14 18:22:20 +01:00

@blender-bot build

@blender-bot build
Vasyl Pidhirskyi approved these changes 2023-11-15 11:59:10 +01:00
Brecht Van Lommel added 1 commit 2023-11-15 19:01:14 +01:00
Brecht Van Lommel merged commit d3971628e1 into main 2023-11-15 19:03:31 +01:00
Brecht Van Lommel deleted branch hydra-camera-refactoring 2023-11-15 19:03:32 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#114370
No description provided.