Camera: Move panoramic projection settings to DNA #111310

Merged
Clément Foucault merged 14 commits from fclem/blender:blender-camear-panoramic-parameters into main 2023-08-22 15:49:40 +02:00

This is in prevision of EEVEE panoramic projection support.

EEVEE-Next is planned to add support for these parameters.
Not having these parameters in Blender DNA will make Cycles
and EEVEE not share the same parameters and will be confusing
for the user.

We handle forward compatibility by still writing the parameters
as ID properties as previous cycles versions expect.

Since this change will break the API compatibility it is crucial
to make it for the 4.0 release.

Related Task #109639

This is in prevision of EEVEE panoramic projection support. EEVEE-Next is planned to add support for these parameters. Not having these parameters in Blender DNA will make Cycles and EEVEE not share the same parameters and will be confusing for the user. We handle forward compatibility by still writing the parameters as ID properties as previous cycles versions expect. Since this change will break the API compatibility it is crucial to make it for the 4.0 release. Related Task #109639
Clément Foucault added this to the 4.0 milestone 2023-08-20 00:19:43 +02:00
Clément Foucault added 1 commit 2023-08-20 00:19:53 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
f715c51452
Camera: Move panoramic projection settings to DNA
This is in prevision of EEVEE panoramic projection
supprt.

Related Task #109639
Clément Foucault requested review from Sergey Sharybin 2023-08-20 00:20:10 +02:00
Clément Foucault requested review from Weizhen Huang 2023-08-20 00:20:10 +02:00
Clément Foucault added this to the Render & Cycles project 2023-08-20 00:20:24 +02:00
Author
Member

@blender-bot build

@blender-bot build
Sergey Sharybin requested changes 2023-08-21 11:41:17 +02:00
Sergey Sharybin left a comment
Owner

The patch seems to miss a subverison bump. Without it I don't think this will properly when file is modified and re-loaded after landing the change.

The cycles_camera_cpu test seems to be failing as well, and it does not seem to be caused by some compositor tests which are currently failing (I'm looking into those).

As for forward compatibility. Blender 3.6 is supposed to be forward compatible with Blender 4.0. Nut I am not sure it will be practical to try to support such change in there.
Curious what @mont29 opinion here.

The patch seems to miss a subverison bump. Without it I don't think this will properly when file is modified and re-loaded after landing the change. The `cycles_camera_cpu` test seems to be failing as well, and it does not seem to be caused by some compositor tests which are currently failing (I'm looking into those). As for forward compatibility. Blender 3.6 is supposed to be forward compatible with Blender 4.0. Nut I am not sure it will be practical to try to support such change in there. Curious what @mont29 opinion here.
@ -210,2 +196,2 @@
bcam->fisheye_polynomial_k3 = RNA_float_get(&ccamera, "fisheye_polynomial_k3");
bcam->fisheye_polynomial_k4 = RNA_float_get(&ccamera, "fisheye_polynomial_k4");
switch (b_camera.panorama_type()) {
default:

Don't use default, and let compiler to point out at missing cases, to help in the future to who are adding new panorama types.

Don't use `default`, and let compiler to point out at missing cases, to help in the future to who are adding new panorama types.
Author
Member

What if you are loading a newer file with a non existing panorama type?

What if you are loading a newer file with a non existing panorama type?

Good point.

Then you move the switch to a function like blender_panorama_type_to_cycles, replace assignment with return, and explicitly outside of the switch statement return PANORAMA_EQUIRECTANGULAR with a comment that it is for the forward compatibility.

best of many worlds:

  • Clear explanation why it is needed
  • Single responsibility principle
  • Best guidance from compiler when adding new panorama type
Good point. Then you move the switch to a function like `blender_panorama_type_to_cycles`, replace assignment with `return`, and explicitly outside of the `switch` statement return `PANORAMA_EQUIRECTANGULAR` with a comment that it is for the forward compatibility. best of many worlds: - Clear explanation why it is needed - Single responsibility principle - Best guidance from compiler when adding new panorama type
fclem marked this conversation as resolved
@ -700,0 +707,4 @@
camera->fisheye_fov = version_cycles_property_float(ccam, "fisheye_fov", M_PI);
camera->fisheye_lens = version_cycles_property_float(ccam, "fisheye_lens", 10.5f);
camera->latitude_min = version_cycles_property_float(
ccam, "latitude_min", -0.5f * (float)M_PI);

Use functional cast: float(M_PI)

More about it https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast

Use functional cast: `float(M_PI)` More about it https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast
fclem marked this conversation as resolved
@ -700,0 +710,4 @@
ccam, "latitude_min", -0.5f * (float)M_PI);
camera->latitude_max = version_cycles_property_float(
ccam, "latitude_max", 0.5f * (float)M_PI);
camera->longitude_min = version_cycles_property_float(ccam, "longitude_min", -M_PI);

Why is it in some cases there is explicit cast to float, but not in others?

Why is it in some cases there is explicit cast to float, but not in others?
Author
Member

Because explicit cast is usually to avoid double promotion. Or maybe I'm missing something.

Because explicit cast is usually to avoid `double` promotion. Or maybe I'm missing something.

Ah, it is expression vs. single value as an argument. Makes sense now.

Ah, it is expression vs. single value as an argument. Makes sense now.
fclem marked this conversation as resolved

Don't think there is a need for subversion bump here, using something like DNA_struct_elem_find would work since new members are added to a DNA struct. However, given how big and disruptive this change is, think a file subversion bump would be good indeed.

Regarding forward compatibility, think that these properties should also be written as 'old' Cycles IDProperties on filewrite. Not having properties from EEVEE next load in 3.6 EEVEE is one thing and acceptable, fully breaking some existing Cycles camera settings when loading a 4.0+ file into 3.6 is something else and absolutely not acceptable imho.

Don't think there is a _need_ for subversion bump here, using something like `DNA_struct_elem_find` would work since new members are added to a DNA struct. However, given how big and disruptive this change is, think a file subversion bump would be good indeed. Regarding forward compatibility, think that these properties should also be written as 'old' Cycles IDProperties on filewrite. Not having properties from EEVEE next load in 3.6 EEVEE is one thing and acceptable, fully breaking some existing Cycles camera settings when loading a 4.0+ file into 3.6 is something else and absolutely not acceptable imho.
Bastien Montagne requested review from Bastien Montagne 2023-08-21 11:57:38 +02:00
Weizhen Huang requested changes 2023-08-21 12:41:15 +02:00
@ -212,0 +199,4 @@
bcam->panorama_type = PANORAMA_EQUIRECTANGULAR;
break;
case BL::Camera::panorama_type_EQUIANGULAR_CUBEMAP_FACE:
bcam->panorama_type = PANORAMA_FISHEYE_EQUIDISTANT;
Member

These types don't match

These types don't match
fclem marked this conversation as resolved
@ -699,1 +700,4 @@
/* Panorama properties shared with Eevee. */
LISTBASE_FOREACH (Camera *, camera, &bmain->cameras) {
IDProperty *ccam = version_cycles_properties_from_ID(&camera->id);
Member

I think it's not enough to do versioning for ccam. If there is a camera in the scene, but the render engine is not Cycles (as in the default file), then after changing to Cycles all the camera parameters in panoramic type are zero instead of the default values.

I think it's not enough to do versioning for `ccam`. If there is a camera in the scene, but the render engine is not Cycles (as in the default file), then after changing to Cycles all the camera parameters in panoramic type are zero instead of the default values.
fclem marked this conversation as resolved
@ -44,0 +50,4 @@
.longitude_min = -M_PI,\
.longitude_max = M_PI,\
/* Fit to match default projective camera with focal_length 50 and sensor_width 36. */ \
.fisheye_polynomial_k0 = -1.1735143712967577e-05,\
Member

There should be a f suffix.
The default values in addon/camera.py can be deleted I think. Turns out that the whole addon/camera.py is just for reference and not used. Probably fine to keep the default values there, but maybe refer to the function fisheye_lens_polynomial_from_projective() here to make it more clear where these values come from.

There should be a `f` suffix. ~~The default values in `addon/camera.py` can be deleted I think.~~ Turns out that the whole `addon/camera.py` is just for reference and not used. Probably fine to keep the default values there, but maybe refer to the function `fisheye_lens_polynomial_from_projective()` here to make it more clear where these values come from.
fclem marked this conversation as resolved
Clément Foucault added 8 commits 2023-08-21 14:49:23 +02:00
Clément Foucault requested review from Sergey Sharybin 2023-08-21 14:49:32 +02:00
Clément Foucault requested review from Weizhen Huang 2023-08-21 14:49:34 +02:00
Bastien Montagne requested changes 2023-08-21 15:01:11 +02:00
Bastien Montagne left a comment
Owner

The change to camera_blend_write should be isolated in their own set of functions, e.g. camera_write_cycles_compatibility_data_create()/camera_write_cycles_compatibility_data_clear()

The change to `camera_blend_write` should be isolated in their own set of functions, e.g. `camera_write_cycles_compatibility_data_create()`/`camera_write_cycles_compatibility_data_clear()`
Sergey Sharybin reviewed 2023-08-21 15:18:27 +02:00
@ -110,0 +135,4 @@
/* For forward compatibility, still write panoramic properties as ID properties for
* previous cycles versions. */
IDProperty *idprop = IDP_GetProperties(id, false);

The write code should not modify the input ID. In fact, the ID should be const-qualified.

One way to achieve this I can think of is to make a shallow copy of the Camera, duplicate the ID properties, set the required properties, write using BLO_write_struct_at_address, and free the copied version of ID properties.

Additionally, such versioning should not happen for undo pushes.

The write code should not modify the input ID. In fact, the ID should be const-qualified. One way to achieve this I can think of is to make a shallow copy of the Camera, duplicate the ID properties, set the required properties, write using `BLO_write_struct_at_address`, and free the copied version of ID properties. Additionally, such versioning should not happen for undo pushes.

@Sergey all IDs are already shallow-duplicated by generic write code, precisely because we do 'modify' these a lot when writing (esp. by setting many runtime data to NULL e.g.).

@Sergey all IDs are already shallow-duplicated by generic write code, precisely because we do 'modify' these a lot when writing (esp. by setting many runtime data to NULL e.g.).

Then no shallow-copy needed, but you still should not add ID properties to the original data-block.

Then no shallow-copy needed, but you still should not add ID properties to the original data-block.
Clément Foucault added 1 commit 2023-08-21 15:28:34 +02:00
Clément Foucault added 1 commit 2023-08-21 17:47:55 +02:00
Bastien Montagne requested changes 2023-08-21 18:08:38 +02:00
@ -106,0 +148,4 @@
};
/* For forward compatibility, still write panoramic properties as ID properties for
* previous cycles versions. */

previous blender versions

`previous blender versions`
fclem marked this conversation as resolved
@ -106,0 +181,4 @@
if (data.idprop_temp) {
IDP_FreeProperty(data.idprop_temp);
}

More of a 'good practice' than strictly required, but would clear both IDPropoerty pointers in data. That way, any potential future access to these would give an obvious 'accessing NULL pointer' error.

More of a 'good practice' than strictly required, but would clear both IDPropoerty pointers in `data`. That way, any potential future access to these would give an obvious 'accessing NULL pointer' error.
fclem marked this conversation as resolved
@ -109,1 +190,4 @@
CameraCyclesCompatibilityData cycles_data;
if (!BLO_write_is_undo(writer)) {

Could be stored as a const bool is_undo variable, instead of calling the function several times.

Could be stored as a `const bool is_undo` variable, instead of calling the function several times.
fclem marked this conversation as resolved
@ -700,0 +713,4 @@
camera->fisheye_polynomial_k4 = version_cycles_property_float(
ccam, "fisheye_polynomial_k4", -2.6064646454854524e-08f);
}
else {

Rather than duplicating the info here (and risking future out-of-sync issues), would rather create a temp dummy Camera data, initialize it (calling camera_init_data on it), and then copy the variables' values from it into the real ID. That way you get defaults as defined in DNA.

Rather than duplicating the info here (and risking future out-of-sync issues), would rather create a temp dummy `Camera` data, initialize it (calling `camera_init_data` on it), and then copy the variables' values from it into the real ID. That way you get defaults as defined in DNA.
fclem marked this conversation as resolved
Clément Foucault added 1 commit 2023-08-21 18:26:52 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
a65e42cae1
Address reviewer's comments
Author
Member

@blender-bot build

@blender-bot build
Sergey Sharybin reviewed 2023-08-22 09:29:31 +02:00
@ -8,6 +8,7 @@
#include <cstddef>
#include <cstdlib>
#include <iostream>

Unused include?

Unused include?
fclem marked this conversation as resolved

@fclem You can try merging main to your patch, the failing matte test should pass. In theory :)

@fclem You can try merging main to your patch, the failing matte test should pass. In theory :)
Weizhen Huang added 1 commit 2023-08-22 09:48:49 +02:00
Bastien Montagne approved these changes 2023-08-22 11:37:18 +02:00
Bastien Montagne left a comment
Owner

From Core PoV LGTM now. Will let the Cycles team give the final green light ;)

From Core PoV LGTM now. Will let the Cycles team give the final green light ;)

@blender-bot build

@blender-bot build
Sergey Sharybin approved these changes 2023-08-22 12:03:27 +02:00
Sergey Sharybin left a comment
Owner

From the design perspective it seems good to me, as well as trying to carefully read the code.

One of the builds is already green, so probably the rest are good as well, but worth waiting a bit before landing.

From the design perspective it seems good to me, as well as trying to carefully read the code. One of the builds is already green, so probably the rest are good as well, but worth waiting a bit before landing.
Clément Foucault added 1 commit 2023-08-22 14:31:18 +02:00
Member

After adding version bump (0e5639d003), when I save a file using this patch, then open it in an older version and try to overwrite the file, I get either
terminated by signal SIGSEGV (Address boundary error)
or

Error: Not freed memory blocks: 1, total unfreed memory 0.000130 MB
IDProperty group len: 136 0x6000058012e8

Seems like a problem in main introduced by forward compatibility handling, not by this patch, so I'm accepting.

After adding version bump (0e5639d00305f3da695796827a50322e484a4c3c), when I save a file using this patch, then open it in an older version and try to overwrite the file, I get either `terminated by signal SIGSEGV (Address boundary error)` or ``` Error: Not freed memory blocks: 1, total unfreed memory 0.000130 MB IDProperty group len: 136 0x6000058012e8 ``` Seems like a problem in main introduced by forward compatibility handling, not by this patch, so I'm accepting.
Weizhen Huang approved these changes 2023-08-22 15:40:22 +02:00
Clément Foucault merged commit acd6dd96b7 into main 2023-08-22 15:49:40 +02:00
Clément Foucault deleted branch blender-camear-panoramic-parameters 2023-08-22 15:49:42 +02: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 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#111310
No description provided.