diff options
author | Brecht Van Lommel <brecht@blender.org> | 2021-07-19 19:39:43 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2021-07-30 19:44:26 +0300 |
commit | 3848507511a7546ab396c80f069b48de3332860f (patch) | |
tree | 86c81ecfa6921b776931b4b952ec0a58a79da68f /source/blender | |
parent | b90887da5a37088d295fe86445cf62c9fc8fdea4 (diff) |
Cleanup: clarify license and origin of voronoi and dithering code
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 16 | ||||
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl | 10 |
2 files changed, 15 insertions, 11 deletions
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. * */ |