Nodes: Implement Gabor noise #121820

Merged
Omar Emara merged 24 commits from OmarEmaraDev/blender:gabor-noise into main 2024-06-19 09:33:43 +02:00
Member

This patch implements a new Gabor noise node based on [1] but with the
improvements from [2] and the phasor formulation from [3].

We compare with the most popular existing implementation, that of OSL,
from the user's point of view:

  • This implementation produces C1 continuous noise as opposed to the
    non continuous OSL implementation, so it can be used for bump
    mapping and is generally smother. This is achieved by windowing the
    Gabor kernel using a Hann window.

  • The Bandwidth input of OSL was hard-coded to 1 and was replaced with
    a frequency input, which OSL hard codes to 2, since frequency is
    more natural to control. This is even more true now that that Gabor
    kernel is windowed as opposed to truncated, which means increasing
    the bandwidth will just turn the Gaussian component of the Gabor
    into a Hann window. While decreasing the bandwidth will eliminate
    the harmonic from the Gabor kernel, which is the point of Gabor
    noise.

  • OSL had three discrete modes of operation for orienting the kernel.
    Anisotropic, Isotropic, and a hybrid mode. While this implementation
    provides a continuous Anisotropy parameter which users are already
    familiar with from the Glossy BSDF node.

  • This implementation provides not just the Gabor noise value, but
    also its phase and intensity components. The Gabor noise value is
    basically sin(phase) * intensity, but the phase is arguably more
    useful since it does not suffer from the low contrast issues that
    Gabor suffers from. While the intensity is useful to hide the
    singularities in the phase.

  • This implementation converges faster that OSL's relative to the
    impulse count, so we fix the impulses count to 8 for simplicitly.

  • This implementation does not implement anisotropic filtering.

Future improvements to the node includes implementing surface noise and
filtering. As well as extending the spectral control of the noise,
either by providing specialized kernels as was done in #110802, or by
providing some more procedural control over the frequencies of the
Gabor.

References:

[1]: Lagae, Ares, et al. "Procedural noise using sparse Gabor
convolution." ACM Transactions on Graphics (TOG) 28.3 (2009): 1-10.

[2]: Tavernier, Vincent, et al. "Making gabor noise fast and
normalized." Eurographics 2019-40th Annual Conference of the European
Association for Computer Graphics. 2019.

[3]: Tricard, Thibault, et al. "Procedural phasor noise." ACM
Transactions on Graphics (TOG) 38.4 (2019): 1-13.

This patch implements a new Gabor noise node based on [1] but with the improvements from [2] and the phasor formulation from [3]. We compare with the most popular existing implementation, that of OSL, from the user's point of view: - This implementation produces C1 continuous noise as opposed to the non continuous OSL implementation, so it can be used for bump mapping and is generally smother. This is achieved by windowing the Gabor kernel using a Hann window. - The Bandwidth input of OSL was hard-coded to 1 and was replaced with a frequency input, which OSL hard codes to 2, since frequency is more natural to control. This is even more true now that that Gabor kernel is windowed as opposed to truncated, which means increasing the bandwidth will just turn the Gaussian component of the Gabor into a Hann window. While decreasing the bandwidth will eliminate the harmonic from the Gabor kernel, which is the point of Gabor noise. - OSL had three discrete modes of operation for orienting the kernel. Anisotropic, Isotropic, and a hybrid mode. While this implementation provides a continuous Anisotropy parameter which users are already familiar with from the Glossy BSDF node. - This implementation provides not just the Gabor noise value, but also its phase and intensity components. The Gabor noise value is basically sin(phase) * intensity, but the phase is arguably more useful since it does not suffer from the low contrast issues that Gabor suffers from. While the intensity is useful to hide the singularities in the phase. - This implementation converges faster that OSL's relative to the impulse count, so we fix the impulses count to 8 for simplicitly. - This implementation does not implement anisotropic filtering. Future improvements to the node includes implementing surface noise and filtering. As well as extending the spectral control of the noise, either by providing specialized kernels as was done in #110802, or by providing some more procedural control over the frequencies of the Gabor. References: [1]: Lagae, Ares, et al. "Procedural noise using sparse Gabor convolution." ACM Transactions on Graphics (TOG) 28.3 (2009): 1-10. [2]: Tavernier, Vincent, et al. "Making gabor noise fast and normalized." Eurographics 2019-40th Annual Conference of the European Association for Computer Graphics. 2019. [3]: Tricard, Thibault, et al. "Procedural phasor noise." ACM Transactions on Graphics (TOG) 38.4 (2019): 1-13.
Omar Emara added 7 commits 2024-05-15 12:43:11 +02:00
Omar Emara added 2 commits 2024-05-16 15:10:51 +02:00
Omar Emara added 1 commit 2024-05-16 15:12:21 +02:00
Omar Emara added 1 commit 2024-05-17 10:46:19 +02:00
Omar Emara added 1 commit 2024-05-17 16:08:53 +02:00
Omar Emara added 4 commits 2024-05-22 13:06:18 +02:00
Omar Emara added 1 commit 2024-05-23 17:00:46 +02:00
Omar Emara added 1 commit 2024-05-23 17:54:05 +02:00
Cleanup
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
6b3d358e86
Omar Emara requested review from Brecht Van Lommel 2024-05-23 17:54:23 +02:00
Omar Emara requested review from Sergey Sharybin 2024-05-23 17:54:23 +02:00
Omar Emara changed title from WIP: Nodes: Implement Gabor noise to Nodes: Implement Gabor noise 2024-05-23 17:54:28 +02:00
Omar Emara added the
Module
Render & Cycles
Interest
Cycles
Interest
EEVEE
labels 2024-05-23 17:55:39 +02:00
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR121820) when ready.
Brecht Van Lommel requested changes 2024-06-06 20:21:09 +02:00
Dismissed
Brecht Van Lommel left a comment
Owner

This is working well overall. There are not that many inputs, so not really much to say regarding UI.

I ran Cycles benchmarks with CUDA and saw no performance impact there.

This is working well overall. There are not that many inputs, so not really much to say regarding UI. I ran Cycles benchmarks with CUDA and saw no performance impact there.
@ -0,0 +21,4 @@
b.add_input<decl::Vector>("Vector").implicit_field(implicit_field_inputs::position);
b.add_input<decl::Float>("Scale").default_value(5.0f);
b.add_input<decl::Float>("Impulses").default_value(8.0f).min(0.0f).max(16.0f);
b.add_input<decl::Float>("Frequency").default_value(2.0f).min(0.0f);

Impulses and Frequency seem to turn the texture from grey to black when they go from a small value to zero.

Could we internally (not in the UI) clamp them to some minimum values to avoid that discontinuity? It seems better when texturing these inputs.

Impulses and Frequency seem to turn the texture from grey to black when they go from a small value to zero. Could we internally (not in the UI) clamp them to some minimum values to avoid that discontinuity? It seems better when texturing these inputs.
OmarEmaraDev marked this conversation as resolved
@ -0,0 +35,4 @@
.subtype(PROP_DIRECTION);
b.add_output<decl::Float>("Value");
b.add_output<decl::Float>("Phase");
b.add_output<decl::Float>("Intensity");

It would be good to add descriptions for all these inputs and outputs.

It would be good to add descriptions for all these inputs and outputs.
OmarEmaraDev marked this conversation as resolved
Omar Emara added 3 commits 2024-06-10 10:32:00 +02:00
Brecht Van Lommel requested changes 2024-06-10 11:43:33 +02:00
Dismissed
@ -0,0 +32,4 @@
.description(
"The number of impulses used to compute the noise. This is a quality control parameter "
"and has minimal effect on the structure of the output. Higher values yield higher "
"quality noise at the cost of more compute time");

compute time -> computation time

compute time -> computation time
OmarEmaraDev marked this conversation as resolved
@ -0,0 +37,4 @@
.default_value(2.0f)
.min(0.0f)
.description(
"The rate at which the Gabor noise change across space. This is different from the "

change -> changes

change -> changes
OmarEmaraDev marked this conversation as resolved
@ -0,0 +46,4 @@
.subtype(PROP_FACTOR)
.description(
"The directionality of Gabor noise. 1 means the noise is completely directional, while "
"0 means the noise is completely omnidirectional");

completely omnidirectional -> omnidirectional

(doesn't make logical sense to me since you can't be partially omnidirectional)

completely omnidirectional -> omnidirectional (doesn't make logical sense to me since you can't be partially omnidirectional)
OmarEmaraDev marked this conversation as resolved
Author
Member

@brecht What do you think about removing the impulses input and setting it internally to something reasonable like 8? Because it doesn't provide much control to the user, when it is very low, the normalization doesn't really work, and setting it to a constant might improve performance.

@brecht What do you think about removing the impulses input and setting it internally to something reasonable like 8? Because it doesn't provide much control to the user, when it is very low, the normalization doesn't really work, and setting it to a constant might improve performance.

Are there situations where 8 is not enough? I see OSL defaults to 16.

I guess that would be the main reason to have it, situations where more impulses are needed but always setting them so high being bad for performance. But I'm not sure if that happens in practice.

If we do need to keep it, we can increase the minimum value at least.

Are there situations where 8 is not enough? I see OSL defaults to 16. I guess that would be the main reason to have it, situations where more impulses are needed but always setting them so high being bad for performance. But I'm not sure if that happens in practice. If we do need to keep it, we can increase the minimum value at least.
Author
Member

@brecht I don't think there are situations where 8 is not enough, we could even go for 4. this is essentially described in details in Tavernier's paper, but the gist of it is as follows.

Gabor noise converges to a Gaussian distribution as the number of impulses increase, the authors use the so called Cramer von Mises criterion (CvM) to assess the quality of convergence for a particular impulses count. They empirically show that a CvM lower than 0.5 is good enough, and all methods converge rather slowly after reaching a CvM of 0.5.

The original Gabor noise method requires around 30 impulses to reach a CvM of 0.5, while the author's suggested method of stratified poisson sampling with bernoulli distribution for weights achieves that in just 2 impulse, so this patch generally requires 15x less impulses to get the same quality as the original Gabor noise.

This could explain why OSL needs a large default of 16 to get something reasonable and why we shouldn't use OSL's implementation as a reference. However, we should note that OSL eliminate the weights of kernels and replace them with a random phase angle for the phase augmented gabor kernel, which was not evaluated in Tavernier's paper. But it probably doesn't change much, which is easy to see empirically in the following examples.

Left is our implementation, right is OSL. Impulses count set to 2 for both. Our implementation already converged to something good while OSL doesn't provide anything useful.

20240610-134808.png

For the following example, I raised OSL's impulses count to 32 (Their maximum possible count), while still keeping our implementation at 2, and I feel like ours is still better.

20240610-135347.png

@brecht I don't think there are situations where 8 is not enough, we could even go for 4. this is essentially described in details in Tavernier's paper, but the gist of it is as follows. Gabor noise converges to a Gaussian distribution as the number of impulses increase, the authors use the so called Cramer von Mises criterion (CvM) to assess the quality of convergence for a particular impulses count. They empirically show that a CvM lower than 0.5 is good enough, and all methods converge rather slowly after reaching a CvM of 0.5. The original Gabor noise method requires around 30 impulses to reach a CvM of 0.5, while the author's suggested method of stratified poisson sampling with bernoulli distribution for weights achieves that in just 2 impulse, so this patch generally requires 15x less impulses to get the same quality as the original Gabor noise. This could explain why OSL needs a large default of 16 to get something reasonable and why we shouldn't use OSL's implementation as a reference. However, we should note that OSL eliminate the weights of kernels and replace them with a random phase angle for the phase augmented gabor kernel, which was not evaluated in Tavernier's paper. But it probably doesn't change much, which is easy to see empirically in the following examples. Left is our implementation, right is OSL. Impulses count set to 2 for both. Our implementation already converged to something good while OSL doesn't provide anything useful. ![20240610-134808.png](/attachments/beee8d32-244d-40a8-bad5-edcbd543f49f) For the following example, I raised OSL's impulses count to 32 (Their maximum possible count), while still keeping our implementation at 2, and I feel like ours is still better. ![20240610-135347.png](/attachments/a152f481-6ff5-468c-a9fb-3bb48195ab20)

Then indeed we can set impulses to a fixed value.

Then indeed we can set impulses to a fixed value.
Omar Emara added 1 commit 2024-06-10 13:19:24 +02:00
Brecht Van Lommel requested changes 2024-06-10 17:49:35 +02:00
Dismissed
Brecht Van Lommel left a comment
Owner

Mark as requesting changes until impulses socket is removed.

Mark as requesting changes until impulses socket is removed.
Omar Emara added 2 commits 2024-06-14 09:07:22 +02:00
Brecht Van Lommel approved these changes 2024-06-14 13:12:05 +02:00
Brecht Van Lommel left a comment
Owner

Looks great, thanks.

Looks great, thanks.
Sergey Sharybin approved these changes 2024-06-17 16:19:37 +02:00
Sergey Sharybin left a comment
Owner

I just verified it works as expected on macOS. Think you've covered all the code side aspects already.

I just verified it works as expected on macOS. Think you've covered all the code side aspects already.
Omar Emara merged commit 4f51033708 into main 2024-06-19 09:33:43 +02:00
Omar Emara deleted branch gabor-noise 2024-06-19 09:33:46 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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
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#121820
No description provided.