Geometry Nodes: Add Viewport Transform node #118680

Merged
Hans Goudey merged 22 commits from HooglyBoogly/blender:geometry-nodes-viewport-transform into main 2024-04-26 19:47:31 +02:00
Member

Add a node that outputs the transform of the viewport relative to the
self object's transform. This node can be used to build effects like
billboarding or aligning geometry to the current view. In combination
with the mouse position node in the future it will allow tools like
generating geometry at the mouse click position.

There are two output matrices. The first is the projection matrix
that takes positions in camera space and applies the final perspective
projection. The other is the "view" matrix which contains the location
and rotation of the camera. These are separate because though their
combination is useful, it isn't used like a typical rotation/transform matrix.


image
Example node group to be used for aligning to camera (billboards):
image
image

Add a node that outputs the transform of the viewport relative to the self object's transform. This node can be used to build effects like billboarding or aligning geometry to the current view. In combination with the mouse position node in the future it will allow tools like generating geometry at the mouse click position. There are two output matrices. The first is the projection matrix that takes positions in camera space and applies the final perspective projection. The other is the "view" matrix which contains the location and rotation of the camera. These are separate because though their combination is useful, it isn't used like a typical rotation/transform matrix. --- ![image](/attachments/d1af1ef0-77eb-4b57-b9cc-d425ed440c19) Example node group to be used for aligning to camera (billboards): ![image](/attachments/076c989e-85b5-4e16-a9be-742b448cde50) ![image](/attachments/b1284d97-a495-40f5-accc-8ec6ceb4cd74)
Hans Goudey added 1 commit 2024-02-23 18:58:18 +01:00
Hans Goudey added this to the Nodes & Physics project 2024-02-23 19:04:55 +01:00
Hans Goudey added the
Interest
Geometry Nodes
label 2024-02-23 19:05:01 +01:00
Member

It might be useful to also add a boolean wheher or not the user is in camera view?

It might be useful to also add a boolean wheher or not the user is in camera view?
Author
Member

It might be useful to also add a boolean wheher or not the user is in camera view?

I don't doubt it, but do you have a use case in mind? Maybe it's more generally useful to have a camera object output for those cases.

> It might be useful to also add a boolean wheher or not the user is in camera view? I don't doubt it, but do you have a use case in mind? Maybe it's more generally useful to have a camera object output for those cases.
Hans Goudey added 1 commit 2024-02-27 14:45:58 +01:00
Hans Goudey added 1 commit 2024-02-29 01:24:04 +01:00
Hans Goudey added 4 commits 2024-03-01 20:30:40 +01:00
Hans Goudey added 2 commits 2024-03-12 22:13:36 +01:00
Hans Goudey added 1 commit 2024-03-12 22:36:25 +01:00
Hans Goudey added 1 commit 2024-04-12 22:44:01 +02:00
Hans Goudey added 1 commit 2024-04-12 22:56:58 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
eae375cf3f
Remove orthographic output
Hans Goudey requested review from Jacques Lucke 2024-04-12 22:59:13 +02:00
Author
Member

@blender-bot build

@blender-bot build
Member

What do you think should be the merging strategy here? With this node but without Mouse Position we are not really in a releasable state.

Would be good to have an example of how you intend people to use this.

What do you think should be the merging strategy here? With this node but without `Mouse Position` we are not really in a releasable state. Would be good to have an example of how you intend people to use this.
Author
Member

I think this still has value on its own. Things like billboarding or aligning geometry to the camera which is a relatively common modeling operation could use this. I planned to create a PR for the mouse position node right after this is committed.

I think this still has value on its own. Things like billboarding or aligning geometry to the camera which is a relatively common modeling operation could use this. I planned to create a PR for the mouse position node right after this is committed.
Member

Things like billboarding or aligning geometry to the camera which is a relatively common modeling operation could use this.

Ok, well then maybe add a simple example in the PR description? Currently, it says that the node is not useful as is.

> Things like billboarding or aligning geometry to the camera which is a relatively common modeling operation could use this. Ok, well then maybe add a simple example in the PR description? Currently, it says that the node is not useful as is.
Author
Member

Currently, it says that the node is not useful as is.

Ah right, sorry. Will do!

>Currently, it says that the node is not useful as is. Ah right, sorry. Will do!
Hans Goudey added 1 commit 2024-04-22 19:13:57 +02:00
Hans Goudey added 1 commit 2024-04-22 19:55:35 +02:00
Member

Need to merge main again. Also, last time I tried the setup in the image it didn't work. Did you try it yourself? Can you provide a .blend file?

Need to merge `main` again. Also, last time I tried the setup in the image it didn't work. Did you try it yourself? Can you provide a .blend file?
Hans Goudey added 2 commits 2024-04-24 18:17:07 +02:00
Hans Goudey added 1 commit 2024-04-24 18:41:46 +02:00
Author
Member

Also, last time I tried the setup in the image it didn't work. Did you try it yourself?

Of course :P I misinterpreted the results though, in retrospect it was clearly not working. And I realized that's because the persmat isn't a proper rotation matrix. We need to output the view and projection matrices separately from this node. For raycasting use cases, they can be combined with a multiply matrix node. For "align to camera" use cases, the view matrix is enough.

Can you provide a .blend file?

Sure, attached a simple example.

> Also, last time I tried the setup in the image it didn't work. Did you try it yourself? Of course :P I misinterpreted the results though, in retrospect it was clearly not working. And I realized that's because the `persmat` isn't a proper rotation matrix. We need to output the view and projection matrices separately from this node. For raycasting use cases, they can be combined with a multiply matrix node. For "align to camera" use cases, the view matrix is enough. > Can you provide a .blend file? Sure, attached a simple example.
Hans Goudey added 1 commit 2024-04-24 18:50:13 +02:00
Hans Goudey added this to the 4.2 LTS milestone 2024-04-24 19:17:49 +02:00
Jacques Lucke requested changes 2024-04-25 11:41:28 +02:00
Dismissed
Jacques Lucke left a comment
Member

The example for how to align something to the view seems to work fine for orthographic view or when the object is in the center of the 3D view. I found that this works better in perspective mode, because it actually aligns the matrix to the camera position instead of just to the viewing direction. Unfortunately, this approach does not work so well for orthographic view, because there the camera position is less well defined.

image

Any thoughts on how to deal with this? Might also be good to expose the camera position for perspective mode directly.

The example for how to align something to the view seems to work fine for orthographic view or when the object is in the center of the 3D view. I found that this works better in perspective mode, because it actually aligns the matrix to the camera position instead of just to the viewing direction. Unfortunately, this approach does not work so well for orthographic view, because there the camera position is less well defined. ![image](/attachments/276d4103-99b4-4aa8-9d6c-542f39b1a69d) Any thoughts on how to deal with this? Might also be good to expose the camera position for perspective mode directly.
@ -0,0 +13,4 @@
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_output<decl::Matrix>("Projection")
.description("The 3D viewport's perspective projection matrix");
Member

perspective or orthographic?

perspective or orthographic?
Author
Member

Okay I guess it deals with orthographic projection too. I'll change it to perspective or orthographic

Okay I guess it deals with orthographic projection too. I'll change it to `perspective or orthographic`
HooglyBoogly marked this conversation as resolved
@ -0,0 +24,4 @@
return;
}
const Object &self_object = *params.self_object();
const RegionView3D &rv3d = *params.user_data()->call_data->operator_data->rv3d;
Member

Node group operators should work even when there is no 3D view.

Node group operators should work even when there is no 3D view.
HooglyBoogly marked this conversation as resolved
Author
Member

Any thoughts on how to deal with this? Might also be good to expose the camera position for perspective mode directly.

I'd rather not output redundant information from this node, I think that's more confusing than helpful for this sort of low level building block. I'd expect there to be some way to check if a matrix is orthographic/perspective in the future, then some node group using this can change its behavior based on that.

>Any thoughts on how to deal with this? Might also be good to expose the camera position for perspective mode directly. I'd rather not output redundant information from this node, I think that's more confusing than helpful for this sort of low level building block. I'd expect there to be some way to check if a matrix is orthographic/perspective in the future, then some node group using this can change its behavior based on that.
Hans Goudey added 3 commits 2024-04-26 17:24:32 +02:00
Hans Goudey requested review from Jacques Lucke 2024-04-26 17:24:35 +02:00
Hans Goudey added 1 commit 2024-04-26 19:09:28 +02:00
Jacques Lucke approved these changes 2024-04-26 19:38:28 +02:00
Jacques Lucke left a comment
Member

Would like to see the billboard example more explicitly in the PR description (with screenshot). Other than that, LGTM.

Would like to see the billboard example more explicitly in the PR description (with screenshot). Other than that, LGTM.
Hans Goudey merged commit 83ed92d533 into main 2024-04-26 19:47:31 +02:00
Hans Goudey deleted branch geometry-nodes-viewport-transform 2024-04-26 19:47:34 +02:00
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
3 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#118680
No description provided.