Add Active Camera geometry node #106065

Closed
dbsc wants to merge 15 commits from dbsc/blender:active_camera_geo_node into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

This adresses #105761

Some Geo Nodes effects are camera dependant: Frustum culling, LOD asset swaps, Camera projections, etc.

Currently it is possible to import one camera object, but handling scenes with multiple cameras is not possible easily. Having an object input similar to "Self Object" would enable using camera markers on the timeline, or per-scene cameras.

demonstration

demontration

The implemented 'Active Camera' node outputs an object that can be plugged into 'Object Info' node to extract transformation information on the active scene's camera.

This adresses https://projects.blender.org/blender/blender/issues/105761 > Some Geo Nodes effects are camera dependant: Frustum culling, LOD asset swaps, Camera projections, etc. > > Currently it is possible to import one camera object, but handling scenes with multiple cameras is not possible easily. Having an object input similar to "Self Object" would enable using camera markers on the timeline, or per-scene cameras. ![demonstration](https://projects.blender.org/attachments/6afc6398-0418-4487-8ba8-c582ec16f2ac) ![demontration](https://projects.blender.org/attachments/284a6f12-e0ef-4dd5-9e58-a1ba759fac6d) The implemented 'Active Camera' node outputs an object that can be plugged into 'Object Info' node to extract transformation information on the active scene's camera.
dbsc requested review from Jacques Lucke 2023-03-24 01:56:55 +01:00
dbsc requested review from Hans Goudey 2023-03-24 01:58:01 +01:00
Author
First-time contributor

Currently there is a problem with the camera changes using markers since they don't share a common 'set camera' function with VIEW3D_OT_object_as_camera. Is there a way to just listen to global changes on the scene's camera somehow, or do we need tamper around the individual functions that set the camera? Feels like I'm missing something here. I would be happy to hear suggestions on this 😁.

Currently there is a problem with the camera changes using markers since they don't share a common 'set camera' function with `VIEW3D_OT_object_as_camera`. Is there a way to just listen to global changes on the scene's camera somehow, or do we need tamper around the individual functions that set the camera? Feels like I'm missing something here. I would be happy to hear suggestions on this 😁.

Yes, there is some difficulty here.
In theory, it seems that we need to add a new update tag, which would be called when the active camera is changed in the scene properties. You can detect this, most likely, in the place in the code where it happens.

Yes, there is some difficulty here. In theory, it seems that we need to add a new update tag, which would be called when the active camera is changed in the scene properties. You can detect this, most likely, in the place in the code where it happens.
dbsc force-pushed active_camera_geo_node from 40bef4a134 to 199979cab2 2023-03-29 05:44:16 +02:00 Compare
dbsc changed title from WIP: Add Active Camera geometry node to Add Active Camera geometry node 2023-03-29 06:00:14 +02:00
Iliya Katushenock reviewed 2023-03-29 06:07:09 +02:00
@ -286,6 +286,8 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
DEG_add_node_tree_output_relation(ctx->node, nmd->node_group, "Nodes Modifier");
add_object_relation(ctx, *ctx->scene->camera);

Do we really want to be addicted forever? It is better to have an analogue of node_needs_own_transform_relation

Do we really want to be addicted forever? It is better to have an analogue of `node_needs_own_transform_relation`
Member

Indeed, this should do something like needs_own_transform_relation to only add the dependency when the new node is used.

Also, this crashes when there is no active object.

Indeed, this should do something like `needs_own_transform_relation` to only add the dependency when the new node is used. Also, this crashes when there is no active object.
Author
First-time contributor

I made changes that hopefully solve both issues.

I made changes that hopefully solve both issues.
dbsc marked this conversation as resolved
First-time contributor

@dbsc as proposed in original request task, i believe this node interface could be greatly improved and could provide other very useful information to the user. Poke me if interested.

img

@dbsc as proposed in [original request](https://projects.blender.org/blender/blender/issues/105761) task, i believe this node interface could be greatly improved and could provide other very useful information to the user. Poke me if interested. ![img](https://projects.blender.org/attachments/47fa2805-f31a-467a-9420-60bf37b53aec)
Hans Goudey requested changes 2023-04-18 22:28:15 +02:00
Hans Goudey left a comment
Member

@dbsc as proposed in original request task, i believe this node interface could be greatly improved and could provide other very useful information to the user. Poke me if interested.

img

To be clear, we'd like to add a separate node after this one that retrieves information from a camera object. But we want to separate retrieving the active camera object from retrieving camera data from any object.

> @dbsc as proposed in [original request](https://projects.blender.org/blender/blender/issues/105761) task, i believe this node interface could be greatly improved and could provide other very useful information to the user. Poke me if interested. > > ![img](https://projects.blender.org/attachments/47fa2805-f31a-467a-9420-60bf37b53aec) To be clear, we'd like to add a separate node after this one that retrieves information from a camera object. But we want to separate retrieving the _active_ camera object from retrieving camera data from _any_ object.
@ -278,6 +278,7 @@ class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeObjectInfo")
node_add_menu.add_node_type(layout, "GeometryNodeSelfObject")
node_add_menu.add_node_type(layout, "GeometryNodeInputSceneTime")
node_add_menu.add_node_type(layout, "GeometryNodeActiveCamera")
Member

This needs alphabetical sorting within this category

This needs alphabetical sorting within this category
Author
First-time contributor

Unless I'm mistaken the other nodes are not in alphabetical order. Should they be ordered as well?

Unless I'm mistaken the other nodes are not in alphabetical order. Should they be ordered as well?
dbsc marked this conversation as resolved
@ -1750,6 +1750,8 @@ void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
BKE_screen_view3d_scene_sync(screen, scene);
}
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
DEG_id_tag_update(&scene->camera->id, ID_RECALC_TRANSFORM);
Member

ID_RECALC_TRANSFORM doesn't really sound right here, since the camera didn't move. Does ID_RECALC_COPY_ON_WRITE work instead?

Actually... I'd imagine this second tag of camera->id isn't necessary, since the geometry nodes modifier will also add a relation to the scene in this case, and the relations update should handle finding a new camera.

`ID_RECALC_TRANSFORM` doesn't really sound right here, since the camera didn't move. Does `ID_RECALC_COPY_ON_WRITE` work instead? Actually... I'd imagine this second tag of `camera->id` isn't necessary, since the geometry nodes modifier will also add a relation to the scene in this case, and the relations update should handle finding a new camera.
Author
First-time contributor

From what I understand, DEG_id_tag_update forces an update on the values on the depsgraph or something like that, and DEG_tag_relations_update modifies the depsgraph. Since the marker changes the camera, a modification on the depsgraph is needed. However, I empirically found that without the DEG_id_tag_update, the active camera node is not updated, and don't understand why this is (even if it is put before the relations tag update).

From what I understand, DEG_id_tag_update forces an update on the values on the depsgraph or something like that, and DEG_tag_relations_update modifies the depsgraph. Since the marker changes the camera, a modification on the depsgraph is needed. However, I empirically found that without the DEG_id_tag_update, the active camera node is not updated, and don't understand why this is (even if it is put before the relations tag update).
@ -281,6 +281,7 @@ DefNode(FunctionNode, FN_NODE_STRING_LENGTH, 0, "STRING_LENGTH", StringLength, "
DefNode(FunctionNode, FN_NODE_VALUE_TO_STRING, 0, "VALUE_TO_STRING", ValueToString, "Value to String", "")
DefNode(GeometryNode, GEO_NODE_ACCUMULATE_FIELD, def_geo_accumulate_field, "ACCUMULATE_FIELD", AccumulateField, "Accumulate Field", "Add the values of an evaluated field together and output the running total for each element")
DefNode(GeometryNode, GEO_NODE_ACTIVE_CAMERA, 0, "ACTIVE_CAMERA", ActiveCamera, "Active Camera", "Retrieve the active camera")
Member

I'd suggest being more specific: Retrieve the scene's active camera

I'd suggest being more specific: `Retrieve the scene's active camera`
dbsc marked this conversation as resolved
dbsc changed title from Add Active Camera geometry node to WIP: Add Active Camera geometry node 2023-05-01 03:49:15 +02:00

Hi @dbsc any updates on this patch?

Hi @dbsc any updates on this patch?
Hans Goudey added this to the 4.0 milestone 2023-06-06 15:10:22 +02:00
dbsc force-pushed active_camera_geo_node from 199979cab2 to c69c573aa2 2023-07-18 05:49:50 +02:00 Compare
Iliya Katushenock added this to the Nodes & Physics project 2023-07-18 11:54:08 +02:00
Iliya Katushenock added the
Interest
Dependency Graph
Interest
Geometry Nodes
labels 2023-07-18 11:54:18 +02:00
dbsc force-pushed active_camera_geo_node from d102c3d483 to 34ec2bf529 2023-07-25 05:07:17 +02:00 Compare
dbsc closed this pull request 2023-07-28 15:21:58 +02:00
dbsc reopened this pull request 2023-07-28 15:22:12 +02:00
dbsc changed title from WIP: Add Active Camera geometry node to Add Active Camera geometry node 2023-07-28 15:39:47 +02:00
Iliya Katushenock reviewed 2023-07-28 22:55:58 +02:00
@ -0,0 +12,4 @@
static void node_geo_exec(GeoNodeExecParams params)
{
Scene *scene = DEG_get_evaluated_scene(params.depsgraph());

If you expect this scene to be evaluate (a copy must be created and initialized) before the geometry nodes work, then the modifier must also create a dependency on the scene and its copy-write component.
It's better to take the original scene (also, do this const). From it to get the original camera. And return it evaluated version (~gel_eval_for_id...). We are already dependent on camera update anyway, its cow copy should be already evaluated.

If you expect this scene to be evaluate (a copy must be created and initialized) before the geometry nodes work, then the modifier must also create a dependency on the scene and its copy-write component. It's better to take the original scene (also, do this const). From it to get the original camera. And return it evaluated version (~`gel_eval_for_id`...). We are already dependent on camera update anyway, its cow copy should be already evaluated.
dbsc marked this conversation as resolved
dbsc force-pushed active_camera_geo_node from b71168a649 to b8ef2e73ec 2023-08-14 15:50:43 +02:00 Compare
dbsc added 2 commits 2023-08-15 20:27:16 +02:00
Author
First-time contributor

There's currently a crash that happens when using markers and the proposed node. The crash happens on simulation_state.cc, because of this assert: BLI_assert(frame > states_at_frames_.last()->frame);. I don't know exactly how to fix it. The attached project shows a minimal setup where the crash happens (you must move the frame counter back and forth).

There's currently a crash that happens when using markers and the proposed node. The crash happens on `simulation_state.cc`, because of this assert: `BLI_assert(frame > states_at_frames_.last()->frame);`. I don't know exactly how to fix it. The attached project shows a minimal setup where the crash happens (you must move the frame counter back and forth).
dbsc requested review from Hans Goudey 2023-09-10 23:45:45 +02:00
Contributor

@dbsc, I apologize that I completely overlooked the existence of this pull request until I had already completed my own implementation for an Active Camera node. I decided to submit my own pull request anyway (!113431) since it looks like this one still has a crash that would need to be fixed, but I believe mine is fully working and ready-to-merge.

Your approach here (adding a new update tag) seems like maybe it would be more efficient than mine, so if they end up merging mine then I would encourage you to get your implementation fully working and submit it as an improvement.

@dbsc, I apologize that I completely overlooked the existence of this pull request until I had already completed my own implementation for an Active Camera node. I decided to submit my own pull request anyway (!113431) since it looks like this one still has a crash that would need to be fixed, but I believe mine is fully working and ready-to-merge. Your approach here (adding a new update tag) seems like maybe it would be more efficient than mine, so if they end up merging mine then I would encourage you to get your implementation fully working and submit it as an improvement.
Brecht Van Lommel modified the milestone from 4.0 to 4.1 2023-10-23 19:17:35 +02:00
Member
75f160ee96b93b7438c4e5900e93d7332fa1d323
Hans Goudey closed this pull request 2024-01-09 17:16:10 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
6 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#106065
No description provided.