Geometry Nodes: Point Distribute Node - Density Max value #85585

Closed
opened 2021-02-12 15:36:14 +01:00 by Charlie Jolly · 18 comments
Member

image.png

In Random mode, the Density Max socket suggests that this limits the maximum density.

However, multiplying the Density Attribute means that the Density Max can be overridden. It seems there is an assumption that the Density Attribute is likely to be a scalar value from a weight map in which case this would work.

Either this is a bug or it is by design.

If it is a bug then here is a suggested fix in the sample_mesh_surface function in source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc:

const float v0_density_factor = std::max(0.0f, (*density_factors)[v0_index]);

change to

const float v0_density_factor = std::max(0.0f, std::min(base_density, (*density_factors)[v0_index])); etc...

Otherwise the socket should just be renamed to Density to avoid confusion.

![image.png](https://archive.blender.org/developer/F9794250/image.png) In Random mode, the **Density Max** socket suggests that this limits the maximum density. However, multiplying the Density Attribute means that the Density Max can be overridden. It seems there is an assumption that the Density Attribute is likely to be a scalar value from a weight map in which case this would work. Either this is a bug or it is by design. If it is a bug then here is a suggested fix in the `sample_mesh_surface` function in `source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc`: `const float v0_density_factor = std::max(0.0f, (*density_factors)[v0_index]);` change to `const float v0_density_factor = std::max(0.0f, std::min(base_density, (*density_factors)[v0_index]));` etc... Otherwise the socket should just be renamed to **Density** to avoid confusion.
Author
Member

Added subscriber: @CharlieJolly

Added subscriber: @CharlieJolly

Added subscriber: @victorlouis

Added subscriber: @victorlouis

I've asked something similar before in the chat, and I believe this is the intended behavior.

The Density Attribute is intended to function as an kind of mask that says: "here I want more stuff and here I want less stuff". The Density Max was added to have a convenient slider in the node to tweak the density (by multiplying every density with this value).

I think the name Density Max originated when it was assumed that the Density Attribute would be between 0 and 1. In that case, it would indeed be the maximum density. But because the density attribute can be > 1, it's somewhat of a misnomer. Maybe Density Max should be renamed to Density Multiplier?

I've asked something similar before in the chat, and I believe this is the intended behavior. The `Density Attribute` is intended to function as an kind of mask that says: "here I want more stuff and here I want less stuff". The `Density Max` was added to have a convenient slider in the node to tweak the density (by multiplying every density with this value). I think the name `Density Max` originated when it was assumed that the `Density Attribute` would be between 0 and 1. In that case, it would indeed be the maximum density. But because the density attribute can be > 1, it's somewhat of a misnomer. Maybe `Density Max` should be renamed to `Density Multiplier`?
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Member

Right, "Density Factor" might work too. "Max" is definitely misleading.

Right, "Density Factor" might work too. "Max" is definitely misleading.
Author
Member

gn_weight_max.blend

File for testing, ignore messy nodes!

Please note how Density Max and Density Attribute affect the number of points in Random and Poisson Disk modes.

When the Density Attribute is in the range of 0-1, the Density Max setting works for both methods in a predictable way. Once the Density Attribute range is increased, there is a multiplication in the Random method and not the Poisson Disk method.

From a user perspective, the relationship should be the same for both methods.

Yellow Torus = Random; Green Cones = Poisson;
Density Max = 4; Density Attribute = 4; Total = 16;
image.png

Density Max = 16; Density Attribute = 1; Total = 16;
image.png

Density Max = 32; Density Attribute = 1; Total = 32;
image.png

Density Max = 8; Density Attribute = 4; Total = 32;
image.png

[gn_weight_max.blend](https://archive.blender.org/developer/F9795352/gn_weight_max.blend) File for testing, ignore messy nodes! Please note how Density Max and Density Attribute affect the number of points in Random and Poisson Disk modes. When the Density Attribute is in the range of 0-1, the Density Max setting works for both methods in a predictable way. Once the Density Attribute range is increased, there is a multiplication in the Random method and not the Poisson Disk method. From a user perspective, the relationship should be the same for both methods. Yellow Torus = Random; Green Cones = Poisson; Density Max = 4; Density Attribute = 4; Total = 16; ![image.png](https://archive.blender.org/developer/F9795346/image.png) Density Max = 16; Density Attribute = 1; Total = 16; ![image.png](https://archive.blender.org/developer/F9795350/image.png) Density Max = 32; Density Attribute = 1; Total = 32; ![image.png](https://archive.blender.org/developer/F9795353/image.png) Density Max = 8; Density Attribute = 4; Total = 32; ![image.png](https://archive.blender.org/developer/F9795355/image.png)

I've looked at the code to see why this happens. The reason is quite subtle, and I agree the behavior is inconsistent.

The random method calls sample_mesh_surface and passes the density_factors. These two lines then determine the density:

looptri_density_factor = (v0_density_factor + v1_density_factor + v2_density_factor) / 3.0f;

and

const float points_amount_fl = area * base_density * looptri_density_factor;

Note here that looptri_density_factor can be greater than 1, depending on the other density_factors. For the Poisson distribute method, this is different, the sample_mesh_surface is also called, but without the density_factors, and thus:

float looptri_density_factor = 1.0f;

The Poisson method uses the density_factors later in update_elimination_mask_based_on_density_factors, and there they are interpreted as probabilities, so they're effectively capped at 1:

const float probablity = v0_density_factor * bary_coord.x + v1_density_factor * bary_coord.y +
                         v2_density_factor * bary_coord.z;

The easiest change to make both methods consistent, would be to calculate the looptri_density_factor like this:

looptri_density_factor = std::max(1.0f, (v0_density_factor + v1_density_factor + v2_density_factor) / 3.0f);

This way, the Density Attribute is always interpreted as a mask with value between 0 and 1, but I'm not sure this is the behavior we want.

I've looked at the code to see why this happens. The reason is quite subtle, and I agree the behavior is inconsistent. The random method calls `sample_mesh_surface` and passes the `density_factors`. These two lines then determine the density: ``` looptri_density_factor = (v0_density_factor + v1_density_factor + v2_density_factor) / 3.0f; ``` and ``` const float points_amount_fl = area * base_density * looptri_density_factor; ``` Note here that `looptri_density_factor` can be greater than 1, depending on the other `density_factors`. For the Poisson distribute method, this is different, the `sample_mesh_surface` is also called, but without the `density_factors`, and thus: ``` float looptri_density_factor = 1.0f; ``` The Poisson method uses the density_factors later in `update_elimination_mask_based_on_density_factors`, and there they are interpreted as probabilities, so they're effectively capped at 1: ``` const float probablity = v0_density_factor * bary_coord.x + v1_density_factor * bary_coord.y + v2_density_factor * bary_coord.z; ``` The easiest change to make both methods consistent, would be to calculate the `looptri_density_factor` like this: ``` looptri_density_factor = std::max(1.0f, (v0_density_factor + v1_density_factor + v2_density_factor) / 3.0f); ``` This way, the `Density Attribute` is always interpreted as a mask with value between 0 and 1, but I'm not sure this is the behavior we want.
Author
Member

Alternatively, density_factors could be passed to sample_mesh_surface when using the poisson option and remove the update_elimination_mask_based_on_density_factors function. In my tests this seems to work quite well but there maybe a good reason to use different density_factors for each distribution type.

Change Poisson from:

  sample_mesh_surface(
      mesh, max_density, nullptr, seed, r_positions, r_bary_coords, r_looptri_indices);
  Array<bool> elimination_mask(r_positions.size(), false);
  update_elimination_mask_for_close_points(r_positions, minimum_distance, elimination_mask);
  update_elimination_mask_based_on_density_factors(
      mesh, density_factors, r_bary_coords, r_looptri_indices, elimination_mask);
  eliminate_points_based_on_mask(elimination_mask, r_positions, r_bary_coords, r_looptri_indices);

To:

  sample_mesh_surface(
      mesh, max_density, &density_factors, seed, r_positions, r_bary_coords, r_looptri_indices);
  Array<bool> elimination_mask(r_positions.size(), false);
  update_elimination_mask_for_close_points(r_positions, minimum_distance, elimination_mask);
  eliminate_points_based_on_mask(elimination_mask, r_positions, r_bary_coords, r_looptri_indices);
Alternatively, `density_factors` could be passed to `sample_mesh_surface` when using the `poisson` option and remove the `update_elimination_mask_based_on_density_factors` function. In my tests this seems to work quite well but there maybe a good reason to use different `density_factors` for each distribution type. Change Poisson from: ``` sample_mesh_surface( mesh, max_density, nullptr, seed, r_positions, r_bary_coords, r_looptri_indices); Array<bool> elimination_mask(r_positions.size(), false); update_elimination_mask_for_close_points(r_positions, minimum_distance, elimination_mask); update_elimination_mask_based_on_density_factors( mesh, density_factors, r_bary_coords, r_looptri_indices, elimination_mask); eliminate_points_based_on_mask(elimination_mask, r_positions, r_bary_coords, r_looptri_indices); ``` To: ``` sample_mesh_surface( mesh, max_density, &density_factors, seed, r_positions, r_bary_coords, r_looptri_indices); Array<bool> elimination_mask(r_positions.size(), false); update_elimination_mask_for_close_points(r_positions, minimum_distance, elimination_mask); eliminate_points_based_on_mask(elimination_mask, r_positions, r_bary_coords, r_looptri_indices); ```
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

I asked @JacquesLucke about that before. That order is to provide stability in id attribute that this node generates.

To test, add an attribute randomize node on the point's radius, try painting the density, transforming the mesh, or extruding some of the mesh's faces. Odds are changing the order makes one of those operations unstable.

I asked @JacquesLucke about that before. That order is to provide stability in `id` attribute that this node generates. To test, add an attribute randomize node on the point's `radius`, try painting the density, transforming the mesh, or extruding some of the mesh's faces. Odds are changing the order makes one of those operations unstable.
Contributor

Added subscriber: @KenzieMac130

Added subscriber: @KenzieMac130
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Shall we confirm this for now?

Shall we confirm this for now?
Member

Added subscriber: @SimonThommes

Added subscriber: @SimonThommes
Member

I think the behavior of being able to control the density with both inputs to a similar capacity without capping it is fine. But I do agree that the Naming should change. I think just using Density is totally fine even though it is more vague. Density Factor is a bit misleading when no attribute is used.

I think the behavior of being able to control the density with both inputs to a similar capacity without capping it is fine. But I do agree that the Naming should change. I think just using `Density` is totally fine even though it is more vague. `Density Factor` is a bit misleading when no attribute is used.
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Jacques Lucke self-assigned this 2021-10-25 13:42:59 +02:00
Member

The node is deprecated and the Distribute Points on Faces node does not have the same problem.

The node is deprecated and the Distribute Points on Faces node does not have the same problem.
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
7 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#85585
No description provided.