[Bf-blender-cvs] [3848507511a] master: Cleanup: clarify license and origin of voronoi and dithering code

Brecht Van Lommel noreply at git.blender.org
Fri Jul 30 18:44:42 CEST 2021


Commit: 3848507511a7546ab396c80f069b48de3332860f
Author: Brecht Van Lommel
Date:   Mon Jul 19 18:39:43 2021 +0200
Branches: master
https://developer.blender.org/rB3848507511a7546ab396c80f069b48de3332860f

Cleanup: clarify license and origin of voronoi and dithering code

===================================================================

M	intern/cycles/kernel/shaders/node_voronoi_texture.osl
M	intern/cycles/kernel/svm/svm_voronoi.h
M	source/blender/blenlib/intern/math_color_inline.c
M	source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl

===================================================================

diff --git a/intern/cycles/kernel/shaders/node_voronoi_texture.osl b/intern/cycles/kernel/shaders/node_voronoi_texture.osl
index e184c26aec8..de6c697fc85 100644
--- a/intern/cycles/kernel/shaders/node_voronoi_texture.osl
+++ b/intern/cycles/kernel/shaders/node_voronoi_texture.osl
@@ -54,14 +54,18 @@ vector4 safe_divide(vector4 a, float b)
 }
 
 /*
- * Smooth Voronoi:
+ * Original code is under the MIT License, Copyright (c) 2013 Inigo Quilez.
  *
+ * Smooth Voronoi:
  * - https://wiki.blender.org/wiki/User:OmarSquircleArt/GSoC2019/Documentation/Smooth_Voronoi
  *
- * Distance To Edge:
+ * Distance To Edge based on:
  *
- * - https://www.shadertoy.com/view/llG3zy
+ * - https://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
+ * - https://www.shadertoy.com/view/ldl3W8
  *
+ * With optimization to change -2..2 scan window to -1..1 for better performance,
+ * as explained in https://www.shadertoy.com/view/llG3zy.
  */
 
 /* **** 1D Voronoi **** */
diff --git a/intern/cycles/kernel/svm/svm_voronoi.h b/intern/cycles/kernel/svm/svm_voronoi.h
index 10d17403f65..d0e7db35fab 100644
--- a/intern/cycles/kernel/svm/svm_voronoi.h
+++ b/intern/cycles/kernel/svm/svm_voronoi.h
@@ -17,14 +17,19 @@
 CCL_NAMESPACE_BEGIN
 
 /*
+ * Original code is under the MIT License, Copyright (c) 2013 Inigo Quilez.
+ *
  * Smooth Voronoi:
  *
  * - https://wiki.blender.org/wiki/User:OmarSquircleArt/GSoC2019/Documentation/Smooth_Voronoi
  *
- * Distance To Edge:
+ * Distance To Edge based on:
  *
- * - https://www.shadertoy.com/view/llG3zy
+ * - https://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
+ * - https://www.shadertoy.com/view/ldl3W8
  *
+ * With optimization to change -2..2 scan window to -1..1 for better performance,
+ * as explained in https://www.shadertoy.com/view/llG3zy.
  */
 
 /* **** 1D Voronoi **** */
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index a5a687ef9fe..ad4b844175f 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -322,16 +322,14 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3],
 /* Return triangle noise in [-0.5..1.5[ range */
 MINLINE float dither_random_value(float s, float t)
 {
-  /* Original code from https://www.shadertoy.com/view/4t2SDh */
-  /* The noise reshaping technique does not work on CPU.
-   * We generate and merge two distribution instead */
-  /* Uniform noise in [0..1[ range */
-  float nrnd0 = sinf(s * 12.9898f + t * 78.233f) * 43758.5453f;
-  float nrnd1 = sinf(s * 19.9898f + t * 119.233f) * 43798.5453f;
-  nrnd0 -= floorf(nrnd0);
-  nrnd1 -= floorf(nrnd1);
+  /* Uniform noise in [0..1[ range, using common GLSL hash function.
+   * https://stackoverflow.com/questions/12964279/whats-the-origin-of-this-glsl-rand-one-liner. */
+  float hash0 = sinf(s * 12.9898f + t * 78.233f) * 43758.5453f;
+  float hash1 = sinf(s * 19.9898f + t * 119.233f) * 43798.5453f;
+  hash0 -= floorf(hash0);
+  hash1 -= floorf(hash1);
   /* Convert uniform distribution into triangle-shaped distribution. */
-  return nrnd0 + nrnd1 - 0.5f;
+  return hash0 + hash0 - 0.5f;
 }
 
 MINLINE void float_to_byte_dither_v3(
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl
index 40f76b9cacc..0f69a4b9aa0 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl
@@ -1,11 +1,17 @@
 /*
+ * Original code is under the MIT License, Copyright (c) 2013 Inigo Quilez.
+ *
  * Smooth Voronoi:
  *
  * - https://wiki.blender.org/wiki/User:OmarSquircleArt/GSoC2019/Documentation/Smooth_Voronoi
  *
- * Distance To Edge:
+ * Distance To Edge based on:
+ *
+ * - https://www.iquilezles.org/www/articles/voronoilines/voronoilines.htm
+ * - https://www.shadertoy.com/view/ldl3W8
  *
- * - https://www.shadertoy.com/view/llG3zy
+ * With optimization to change -2..2 scan window to -1..1 for better performance,
+ * as explained in https://www.shadertoy.com/view/llG3zy.
  *
  */



More information about the Bf-blender-cvs mailing list