Matrix operations and sockets for geometry nodes #105408

Closed
Lukas Tönne wants to merge 37 commits from LukasTonne/blender:nodes-matrix-types into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Support for matrix operations in geometry nodes (and function nodes generally)

  • customdata layer types for 2x2, 3x3, 4x4 matrices
  • New socket type 'Matrix' to represent 4x4 matrix data
  • Basic set of function nodes for matrix operations:
    • Input nodes to specify an explicit matrix by components (default matrix is 4x4 identity)
      image
    • 'Combine' node to construct matrices by columns, rows, or individual elements
      image
    • 'Separate' node to extract columns, rows, or elements
      image
    • Translate/Rotate/Scale nodes to generate affine matrices
      image
    • 'Decompose' node to return translation, rotation, and scale.
      image
    • Matrix Math for common operations, such as matrix/scalar multiplication, inverse, determinant, etc.
      image
    • 'Transform Vector' node to apply a matrix as a transformation to a vector
      image

The socket represents a 4x4 matrix as the only type. This is to simplify matrix operations for users. Supporting 2x2 and 3x3 matrix types could have better performance and require less memory, but would make conversions necessary and force users to pick the correct variant of node for the respective matrix type. Eventually this might be supported with a generic socket type.

Support for matrix operations in geometry nodes (and function nodes generally) * customdata layer types for 2x2, 3x3, 4x4 matrices * New socket type 'Matrix' to represent 4x4 matrix data * Basic set of function nodes for matrix operations: - Input nodes to specify an explicit matrix by components (default matrix is 4x4 identity) ![image](/attachments/6e714b98-2809-40c5-af9e-0f21ec13cf2e) - 'Combine' node to construct matrices by columns, rows, or individual elements ![image](/attachments/3bb7c0fe-4e09-44f0-b6a9-5bd44bcbe584) - 'Separate' node to extract columns, rows, or elements ![image](/attachments/f3355225-110e-4731-b3c7-cdbcbaeb7ce7) - Translate/Rotate/Scale nodes to generate affine matrices ![image](/attachments/a11de734-e28f-4768-961c-b7ccf7de575e) - 'Decompose' node to return translation, rotation, and scale. ![image](/attachments/95c0de44-7703-4c0b-878d-48526953791b) - Matrix Math for common operations, such as matrix/scalar multiplication, inverse, determinant, etc. ![image](/attachments/a47724e1-5199-47fa-a04e-7759a1cff47d) - 'Transform Vector' node to apply a matrix as a transformation to a vector ![image](/attachments/f145b367-e4ec-4e1a-b2f6-00c8b178fd90) The socket represents a 4x4 matrix as the only type. This is to simplify matrix operations for users. Supporting 2x2 and 3x3 matrix types could have better performance and require less memory, but would make conversions necessary and force users to pick the correct variant of node for the respective matrix type. Eventually this might be supported with a generic socket type.
Lukas Tönne added 35 commits 2023-03-03 17:02:29 +01:00
83e4fef23c Revert "Matrix input mode for the instance-on-points node."
This reverts commit eea512fbcc.
Should be decided separately if a matrix input is better suited for the
instance-on-points node or other existing nodes.
bfde6c8a9c Removed the 2x2 and 3x3 matrix types.
Having different matrix types is likely to be confusing for users
and complicates node trees by requiring conversions.
For now there will be only a the 4x4 matrix type, which can encode
3x3 and 2x2 matrices as well at the cost of some performance.

Eventually a generic socket type could make this easier and allow
the introduction of additional matrix types without too much
inconvenience for users.
79ff2f88e2 Renamed matrix nodes without the 4x4 suffix.
Matrix nodes should be generic enough to work with all kinds
of matrices. Right now that will only be 4x4 matrices but the
nodes don't need that in their names.

I'm glad that finally there are steps to this!
A couple of things at a glance:

  1. Do we want a matrix rotation node? Would it be more extensible to have a rotation matrix generator node capable of doing this for euler, normal axis, ... ?
  2. Do we need to enter all 16 components as separate entries? 2 vectors, 3 vectors, 4 vectors and 4 values... Not sure about the purity, but there are even more sockets than the statistics node!
I'm glad that finally there are steps to this! A couple of things at a glance: 1. Do we want a matrix rotation node? Would it be more extensible to have a rotation matrix generator node capable of doing this for euler, normal axis, ... ? 2. Do we need to enter all 16 components as separate entries? 2 vectors, 3 vectors, 4 vectors and 4 values... Not sure about the purity, but there are even more sockets than the statistics node!
Contributor

I would personally recommend against going this route and instead present the user with the abstract concept of a transform. Matrices are lossy and can be easily deformed in a way that causes bugs further down the line.

Storing the location, rotation (quaternion, similarly abstracted), and scale as well as order is plenty to define and carry a transform. Imo to an end user matrices should be only used as a baked representation of these transforms (or black boxed formulas such as perspective). My approach to using them is that if avoidable they should not be manually modified, inversed (if possible to avoid loss of precision in world space), or decomposed back into LRS transforms. Possibly never exposed at all to the end user.

I would personally recommend against going this route and instead present the user with the abstract concept of a transform. Matrices are lossy and can be easily deformed in a way that causes bugs further down the line. Storing the location, rotation (quaternion, similarly abstracted), and scale as well as order is plenty to define and carry a transform. Imo to an end user matrices should be only used as a baked representation of these transforms (or black boxed formulas such as perspective). My approach to using them is that if avoidable they should not be manually modified, inversed (if possible to avoid loss of precision in world space), or decomposed back into LRS transforms. Possibly never exposed at all to the end user.

@KenzieMac130 Matrices are a very important mathematical abstraction that will give you a lot of possibilities. The quality of data accuracy is more of a general issue. And it is a consequence of poor user experience. Even transformations won't save her.

@KenzieMac130 Matrices are a very important mathematical abstraction that will give you a lot of possibilities. The quality of data accuracy is more of a general issue. And it is a consequence of poor user experience. Even transformations won't save her.
Contributor

For the average user of 3D software they will only ever use location, rotation, and scale. Decomposing is lossy with rotation and scale, therefore not ideal for storing those values to retrieve later. Shears and other non-afine transforms to be applied on vertices are likely to be done by the average user using vector math instead nowadays. Giving the user the ability to arbitrarily define matrices is a guaranteed way to get unsanitary data. From what I have seen plenty of other 3D packages and engines avoid exposing them directly to the user.

For the average user of 3D software they will only ever use location, rotation, and scale. Decomposing is lossy with rotation and scale, therefore not ideal for storing those values to retrieve later. Shears and other non-afine transforms to be applied on vertices are likely to be done by the average user using vector math instead nowadays. Giving the user the ability to arbitrarily define matrices is a guaranteed way to get unsanitary data. From what I have seen plenty of other 3D packages and engines avoid exposing them directly to the user.
Lukas Tönne added this to the Nodes & Physics project 2023-03-03 17:57:49 +01:00
Lukas Tönne requested review from Hans Goudey 2023-03-03 17:59:19 +01:00
First-time contributor

I'd love to join into the design discussion, but isn't a (not yet existing) design issue the right place for that? Or was this initial design already approved by the Nodes & Physics team?

I'd love to join into the design discussion, but isn't a (not yet existing) design issue the right place for that? Or was this initial design already approved by the Nodes & Physics team?

@McSwiff No design, Lukas took up prototyping matrix nodes after chatting in geometry nodes channel in chat

@McSwiff No design, Lukas took up prototyping matrix nodes after chatting in geometry nodes channel in chat

@KenzieMac130 Matrix is a mathematical abstraction for describing any linear 3D transformation.

  • Their correctness is a consequence of the conscious operation of the user.
  • If we consider the user to be unfamiliar with mathematics, then we simply have to make a button: Make Ok.
  • In the case of other parametric programs, it seems that matrices are included in the list of primitives, which should be in the first place.
@KenzieMac130 Matrix is a mathematical abstraction for describing any linear 3D transformation. - Their correctness is a consequence of the conscious operation of the user. - If we consider the user to be unfamiliar with mathematics, then we simply have to make a button: Make Ok. - In the case of other parametric programs, it seems that matrices are included in the list of primitives, which should be in the first place.
First-time contributor

Okay then, so minor design discussions are allowed in PRs now?
Given that matrix math is already a very sharp tool with which you can easily cut yourself. I would advocate for a "Compose/Recompose Matrix" node as a mirror to the "Decompose Matrix".
I've used it in the past, knowing fully well the loss of precision that comes with it. But I'm at the end of my chain of calculations. I just needed a simple to express and easy to read way to take my transform matrix and set the rotation of it based on something I calculated.
Is that a strong enough reason?

Okay then, so minor design discussions are allowed in PRs now? Given that matrix math is already a very sharp tool with which you can easily cut yourself. I would advocate for a "Compose/Recompose Matrix" node as a mirror to the "Decompose Matrix". I've used it in the past, knowing fully well the loss of precision that comes with it. But I'm at the end of my chain of calculations. I just needed a simple to express and easy to read way to take my transform matrix and set the rotation of it based on something I calculated. Is that a strong enough reason?
Lukas Tönne added 2 commits 2023-03-06 11:59:44 +01:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2023-07-21 21:04:32 +02:00

Any movement on this? Apart from a Compose Matrix node and possibly adding local and world matrix outputs from the Object Info node, this feels done and would be incredibly useful.

Any movement on this? Apart from a Compose Matrix node and possibly adding local and world matrix outputs from the Object Info node, this feels done and would be incredibly useful.
Member

This is being worked on in #116067, so I'll close this PR. The code still may end up being helpful though.

This is being worked on in #116067, so I'll close this PR. The code still may end up being helpful though.
Hans Goudey closed this pull request 2023-12-13 18:27:15 +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#105408
No description provided.