Voronoi texture cells biased towards mapping coordinates #50658

Closed
opened 2017-02-12 03:46:38 +01:00 by gandalf3 · 17 comments
Member

System Information
Archlinux

Blender Version
Broken: 2.78a

Short description of error

When subtracting (.5, .5, .5) from the output of a high frequency Voronoi cell texture, a pattern which looks suspiciously like the input coordinates emerges:

examp072.gif

This might be related to the rather unexpected tendency for Voronoi-cell-modified-normals to cause square reflections of round light sources when used in a glossy shader.
The two phenomena occur together, but beyond that I have no idea why either happens or why one would cause the other.

Exact steps for others to reproduce the error

  1. Open voronoi_not_random.blend
  2. Switch to rendered viewport shading
  3. Take note of pattern which appears to correspond to input coordinates (takes a fare number of samples to really become apparent)
  4. Connect glossy shader output to material surface input.
  5. Note the "square" reflection of the round sun lamp.
**System Information** Archlinux **Blender Version** Broken: 2.78a **Short description of error** When subtracting `(.5, .5, .5)` from the output of a high frequency Voronoi cell texture, a pattern which looks suspiciously like the input coordinates emerges: ![examp072.gif](https://archive.blender.org/developer/F483687/examp072.gif) This *might* be related to the rather unexpected tendency for Voronoi-cell-modified-normals to cause square reflections of round light sources when used in a glossy shader. The two phenomena occur together, but beyond that I have no idea why either happens or why one would cause the other. **Exact steps for others to reproduce the error** 1. Open [voronoi_not_random.blend](https://archive.blender.org/developer/F483694/voronoi_not_random.blend) 2. Switch to rendered viewport shading 3. Take note of pattern which appears to correspond to input coordinates (takes a fare number of samples to really become apparent) 4. Connect glossy shader output to material surface input. 5. Note the "square" reflection of the round sun lamp.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @gandalf3

Added subscriber: @gandalf3

Added subscriber: @GiantCowFIlms

Added subscriber: @GiantCowFIlms

Added subscribers: @brecht, @Sergey

Added subscribers: @brecht, @Sergey
Sergey Sharybin self-assigned this 2017-02-16 17:59:34 +01:00

While this isn't really a bug but like a limitation of current hashing function this is an interesting phenomena to investigate.

Think correlation is coming from the order of coordinate components we use to hash r, g and b components:

  x, y, z
  y, x, z
  y, z, x

Would need to plot our hash() function to see if there's something intrinsicly wrong in there, but such a quick experiment solves the correlation issue:

P446: Snippet for #50658

diff --git a/intern/cycles/kernel/svm/svm_noise.h b/intern/cycles/kernel/svm/svm_noise.h
index 3f75ae5c04e..71cfaf2134f 100644
--- a/intern/cycles/kernel/svm/svm_noise.h
+++ b/intern/cycles/kernel/svm/svm_noise.h
@@ -316,9 +316,9 @@ ccl_device_noinline float cellnoise(float3 p)
 
 ccl_device float3 cellnoise_color(float3 p)
 {
-	float r = cellnoise(p);
-	float g = cellnoise(make_float3(p.y, p.x, p.z));
-	float b = cellnoise(make_float3(p.y, p.z, p.x));
+	float r = cellnoise(make_float3(p.y, p.x, p.z*p.y));
+	float g = cellnoise(make_float3(p.y*p.x, p.x, p.z));
+	float b = cellnoise(make_float3(p.y, p.z*p.y, p.x));
 
 	return make_float3(r, g, b);
 }

Note that patch is only working on GPU, CPU would need SSE-optimized version.

That's the math aspect of the issue. Now let's talk about practical aspect. Don't really think Voronoi was intended to have same randomness entropy as a white noise and if you need white noise just use a dedicated function for that. Surely solving correlation issues will be nice, but that's not possible without changing behavior of the voronoi noise. Which means, it'll break all existing files which are using this texture.

Maybe we can do it in 2.8 branch, but only if it's indeed something important to solve.

@brecht, wouldn't mind hearing your opinion on this issue.

While this isn't really a bug but like a limitation of current hashing function this is an interesting phenomena to investigate. Think correlation is coming from the order of coordinate components we use to hash r, g and b components: ``` x, y, z y, x, z y, z, x ``` Would need to plot our `hash()` function to see if there's something intrinsicly wrong in there, but such a quick experiment solves the correlation issue: [P446: Snippet for #50658](https://archive.blender.org/developer/P446.txt) ``` diff --git a/intern/cycles/kernel/svm/svm_noise.h b/intern/cycles/kernel/svm/svm_noise.h index 3f75ae5c04e..71cfaf2134f 100644 --- a/intern/cycles/kernel/svm/svm_noise.h +++ b/intern/cycles/kernel/svm/svm_noise.h @@ -316,9 +316,9 @@ ccl_device_noinline float cellnoise(float3 p) ccl_device float3 cellnoise_color(float3 p) { - float r = cellnoise(p); - float g = cellnoise(make_float3(p.y, p.x, p.z)); - float b = cellnoise(make_float3(p.y, p.z, p.x)); + float r = cellnoise(make_float3(p.y, p.x, p.z*p.y)); + float g = cellnoise(make_float3(p.y*p.x, p.x, p.z)); + float b = cellnoise(make_float3(p.y, p.z*p.y, p.x)); return make_float3(r, g, b); } ``` Note that patch is only working on GPU, CPU would need SSE-optimized version. That's the math aspect of the issue. Now let's talk about practical aspect. Don't really think Voronoi was intended to have same randomness entropy as a white noise and if you need white noise just use a dedicated function for that. Surely solving correlation issues will be nice, but that's not possible without changing behavior of the voronoi noise. Which means, it'll break all existing files which are using this texture. Maybe we can do it in 2.8 branch, but only if it's indeed something important to solve. @brecht, wouldn't mind hearing your opinion on this issue.

Perhaps changing the order to this helps? So there is no repetition in the rows or columns.

x, y, z
z, x, y
y, z, x

Whatever solves the issue, seems ok to fix in 2.8.

Perhaps changing the order to this helps? So there is no repetition in the rows or columns. ``` x, y, z z, x, y y, z, x ``` Whatever solves the issue, seems ok to fix in 2.8.
Member

Added subscriber: @LazyDodo

Added subscriber: @LazyDodo
Member

Not sure diverging from what OSL is doing is that good of an idea, even for 2.8, We either have to re-implement cellnoise+Voronoi in osl scripts which will be significantly slower, or patch osl while we're building it to keep consistent results between SVM and OSL. Is it really a problem worth solving?

Not sure diverging from what OSL is doing is that good of an idea, even for 2.8, We either have to re-implement cellnoise+Voronoi in osl scripts which will be significantly slower, or patch osl while we're building it to keep consistent results between SVM and OSL. Is it really a problem worth solving?

@brecht, woops. After days of bugfix hunting didn't think of such a simple shuffle :) Seems promising since that's simple to implement on SSE.

@LazyDodo, not sure why that would diverge for OSL. We just need to update kernel/shaders/node_texture.h. OSL does not implement Voronoi on their side.

@brecht, woops. After days of bugfix hunting didn't think of such a simple shuffle :) Seems promising since that's simple to implement on SSE. @LazyDodo, not sure why that would diverge for OSL. We just need to update `kernel/shaders/node_texture.h`. OSL does not implement Voronoi on their side.
Member

My bad, i could have sworn we used the internal noise functions from osl. I stand corrected.

My bad, i could have sworn we used the internal noise functions from osl. I stand corrected.
Author
Member

Maybe we can do it in 2.8 branch, but only if it's indeed something important to solve.

My particular use-case is using detailed voronoi cells to modify normals to simulate aluminum flakes in car paint

> Maybe we can do it in 2.8 branch, but only if it's indeed something important to solve. My particular use-case is using detailed voronoi cells to modify normals to simulate [aluminum flakes in car paint ](https://en.wikipedia.org/wiki/Metallic_paint)

@LazyDodo, we use noise while voronoi is a "wrapper" on top noise. That being said, we use perlin noise from OS for example.

@gandalf3, why not to use regular noise if the scale to be so small?

@brecht, tested that shuffle patch from you. Unfortunately, it does not solve the issue. So guess our noise() function isn't really good in terms doesn't give nice distribution when shuffling arguments around. This is still to be confirmed tho. Will give it a deeper later.

@LazyDodo, we use noise while voronoi is a "wrapper" on top noise. That being said, we use perlin noise from OS for example. @gandalf3, why not to use regular noise if the scale to be so small? @brecht, tested that shuffle patch from you. Unfortunately, it does not solve the issue. So guess our `noise()` function isn't really good in terms doesn't give nice distribution when shuffling arguments around. This is still to be confirmed tho. Will give it a deeper later.

@Sergey, it is easier to get distinct faces using the vorinoi texture. Using noise often results in less distinct pieces. Further, for certain camera angles the scale is not as small as one might believe. Some paints have pretty large flecks.

@Sergey, it is easier to get distinct faces using the vorinoi texture. Using noise often results in less distinct pieces. Further, for certain camera angles the scale is not as small as one might believe. Some paints have pretty large flecks.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

Was trying various things here. The cell-noise itself is not biased by the looks of it, and in fact it matches implementation from OIIO/OSL. it is something combined with the way how we do cells and then hashing the coordinate which gives distribution issues.

Since there is no way to fix that without introducing regressions and because it's not a bug in implementation considering it a TODO for 2.8 projects there: https://wiki.blender.org/index.php/Dev:Source/Render/Cycles/ToDo

@GiantCowFIlms, doubt you'll see bias with larger flecks tbh.

Was trying various things here. The cell-noise itself is not biased by the looks of it, and in fact it matches implementation from OIIO/OSL. it is something combined with the way how we do cells and then hashing the coordinate which gives distribution issues. Since there is no way to fix that without introducing regressions and because it's not a bug in implementation considering it a TODO for 2.8 projects there: https://wiki.blender.org/index.php/Dev:Source/Render/Cycles/ToDo @GiantCowFIlms, doubt you'll see bias with larger flecks tbh.

Added subscriber: @sivert3

Added subscriber: @sivert3

This is actually cased by a bug in the implementation of quick_floor in OSL, which has been faithfully reproduced in Cycles's own version in util/util_math.h. The gist is that quick_floor_to_int(-1.0) == -2 instead of the correct value of -1, and this manifests itself in the voronoi shader which floors input coordinates correctly before passing them to cellnoise, which in turn uses the broken quick floor function.

See imageworks/OpenShadingLanguage#912 for a detailed description

Confirmed to be the case with P781: Snippet for #50658

diff --git a/intern/cycles/kernel/shaders/node_voronoi_texture.osl b/intern/cycles/kernel/shaders/node_voronoi_texture.osl
index 2e47d74a414..0017f2a2426 100644
--- a/intern/cycles/kernel/shaders/node_voronoi_texture.osl
+++ b/intern/cycles/kernel/shaders/node_voronoi_texture.osl
@@ -40,7 +40,8 @@ void voronoi_m(point p, string metric, float e, float da- [x], point pa[4])
 		for (yy = yi - 1; yy <= yi + 1; yy++) {
 			for (zz = zi - 1; zz <= zi + 1; zz++) {
 				point ip = point(xx, yy, zz);
-				point vp = (point)cellnoise_color(ip);
+				point cp = point(xx+0.5, yy+0.5, zz+0.5);
+				point vp = (point)cellnoise_color(cp);
 				point pd = p - (vp + ip);
 
 				float d = 0.0;
This is actually cased by a bug in the implementation of quick_floor in OSL, which has been faithfully reproduced in Cycles's own version in util/util_math.h. The gist is that `quick_floor_to_int(-1.0) == -2` instead of the correct value of -1, and this manifests itself in the voronoi shader which floors input coordinates correctly before passing them to cellnoise, which in turn uses the broken quick floor function. [See imageworks/OpenShadingLanguage#912 for a detailed description ](https://github.com/imageworks/OpenShadingLanguage/pull/912) Confirmed to be the case with [P781: Snippet for #50658](https://archive.blender.org/developer/P781.txt) ``` diff --git a/intern/cycles/kernel/shaders/node_voronoi_texture.osl b/intern/cycles/kernel/shaders/node_voronoi_texture.osl index 2e47d74a414..0017f2a2426 100644 --- a/intern/cycles/kernel/shaders/node_voronoi_texture.osl +++ b/intern/cycles/kernel/shaders/node_voronoi_texture.osl @@ -40,7 +40,8 @@ void voronoi_m(point p, string metric, float e, float da- [x], point pa[4]) for (yy = yi - 1; yy <= yi + 1; yy++) { for (zz = zi - 1; zz <= zi + 1; zz++) { point ip = point(xx, yy, zz); - point vp = (point)cellnoise_color(ip); + point cp = point(xx+0.5, yy+0.5, zz+0.5); + point vp = (point)cellnoise_color(cp); point pd = p - (vp + ip); float d = 0.0; ```
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
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
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#50658
No description provided.