Commit: 95a603c607b88f4527c7b8edf4eeacd1ba380867
Author: Lukas Tönne
Date: Wed Jun 8 09:14:07 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB95a603c607b88f4527c7b8edf4eeacd1ba380867
Basic Gabor noise implementation for BLI_noise and blenvm.
This is just the very basic version of the sparse convolution noise
with a Gabor kernel. It does not yet have derivatives or anisotropic
filtering. The only frequency spectrum implemented atm is isotropic
band-limited noise.
===================================================================
M release/scripts/nodes/common_nodes.py
M release/scripts/nodes/geometry_nodes.py
M release/scripts/nodes/instancing_nodes.py
M release/scripts/nodes/texture_nodes.py
M source/blender/blenlib/BLI_noise.h
M source/blender/blenlib/CMakeLists.txt
M source/blender/blenlib/intern/noise.c
A source/blender/blenlib/intern/noise_gabor.c
M source/blender/blenvm/compile/node_graph.cc
M source/blender/blenvm/modules/mod_texture.h
M source/blender/blenvm/util/util_opcode.h
===================================================================
diff --git a/release/scripts/nodes/common_nodes.py
b/release/scripts/nodes/common_nodes.py
index a0e6cc4..9504b64 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -966,6 +966,32 @@ class TextureVoronoiNode(CommonNodeBase, ObjectNode):
compiler.map_output(1, node.outputs["color"])
compiler.map_output(2, node.outputs["normal"])
+
+class TextureGaborNoiseNode(CommonNodeBase, ObjectNode):
+ '''Gabor noise texture'''
+ bl_idname = 'ObjectTextureGaborNoiseNode'
+ bl_label = 'Gabor Noise'
+
+ def draw_buttons(self, context, layout):
+ pass
+
+ def init(self, context):
+ self.inputs.new('NodeSocketVector', "Position")
+ self.inputs.new('NodeSocketFloat', "Size").default_value = 1.0
+ self.inputs.new('NodeSocketFloat', "Impulses").default_value = 10.0
+ self.inputs.new('NodeSocketFloat', "Bandwidth").default_value = 0.5
+ self.inputs.new('NodeSocketFloat', "Frequency").default_value = 1.0
+ self.outputs.new('NodeSocketFloat', "Intensity")
+
+ def compile(self, compiler):
+ node = compiler.add_node("TEX_PROC_GABORNOISE")
+ compiler.map_input(0, node.inputs["position"])
+ compiler.map_input(1, node.inputs["size"])
+ compiler.map_input(2, node.inputs["impulses"])
+ compiler.map_input(3, node.inputs["bandwidth"])
+ compiler.map_input(4, node.inputs["frequency"])
+ compiler.map_output(0, node.outputs["intensity"])
+
###############################################################################
class ImageSampleNode(CommonNodeBase, ObjectNode):
diff --git a/release/scripts/nodes/geometry_nodes.py
b/release/scripts/nodes/geometry_nodes.py
index 35c7d47..9c3b5ad 100644
--- a/release/scripts/nodes/geometry_nodes.py
+++ b/release/scripts/nodes/geometry_nodes.py
@@ -472,6 +472,7 @@ def register():
NodeItem("ImageSampleNode"),
NodeItem("ObjectTextureCloudsNode"),
NodeItem("ObjectTextureDistNoiseNode"),
+ NodeItem("ObjectTextureGaborNoiseNode"),
NodeItem("ObjectTextureMagicNode"),
NodeItem("ObjectTextureMarbleNode"),
NodeItem("ObjectTextureMusgraveNode"),
diff --git a/release/scripts/nodes/instancing_nodes.py
b/release/scripts/nodes/instancing_nodes.py
index 80729a2..5ab4893 100644
--- a/release/scripts/nodes/instancing_nodes.py
+++ b/release/scripts/nodes/instancing_nodes.py
@@ -222,6 +222,7 @@ def register():
InstancingNodeCategory("INS_TEXTURE", "Texture", items=[
NodeItem("ObjectTextureCloudsNode"),
NodeItem("ObjectTextureDistNoiseNode"),
+ NodeItem("ObjectTextureGaborNoiseNode"),
NodeItem("ObjectTextureMagicNode"),
NodeItem("ObjectTextureMarbleNode"),
NodeItem("ObjectTextureMusgraveNode"),
diff --git a/release/scripts/nodes/texture_nodes.py
b/release/scripts/nodes/texture_nodes.py
index 78adad8..dc83d3a 100644
--- a/release/scripts/nodes/texture_nodes.py
+++ b/release/scripts/nodes/texture_nodes.py
@@ -218,6 +218,7 @@ def register():
NodeItem("ImageSampleNode"),
NodeItem("ObjectTextureCloudsNode"),
NodeItem("ObjectTextureDistNoiseNode"),
+ NodeItem("ObjectTextureGaborNoiseNode"),
NodeItem("ObjectTextureMagicNode"),
NodeItem("ObjectTextureMarbleNode"),
NodeItem("ObjectTextureMusgraveNode"),
diff --git a/source/blender/blenlib/BLI_noise.h
b/source/blender/blenlib/BLI_noise.h
index f3292d2..8ff7f73 100644
--- a/source/blender/blenlib/BLI_noise.h
+++ b/source/blender/blenlib/BLI_noise.h
@@ -33,6 +33,8 @@
* \ingroup bli
*/
+#include "BLI_sys_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -59,6 +61,21 @@ void voronoi(float x, float y, float z, float *da, float
*pa, float me, int dtyp
float cellNoise(float x, float y, float z);
void cellNoiseV(float x, float y, float z, float r_ca[3]);
+/* Gabor noise */
+typedef struct GaborNoiseSampler {
+ void (*sample)(struct GaborNoiseSampler *sampler, uint64_t rng,
+ float *r_omega, float *r_phi);
+ void (*free)(struct GaborNoiseSampler *sampler);
+} GaborNoiseSampler;
+float BLI_gabor_noise(float noisesize, float x, float y, float z,
+ float impulses, float bandwidth,
+ struct GaborNoiseSampler *sampler);
+void BLI_gabor_noise_sampler_free(struct GaborNoiseSampler *sampler);
+/* sampler for band-limited isotropic noise */
+struct GaborNoiseSampler *BLI_gabor_noise_sampler_isotropic(float frequency);
+
+extern void *__BLI_noise_linker_hack__;
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/CMakeLists.txt
b/source/blender/blenlib/CMakeLists.txt
index 944ba60..64ec9fb 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -90,6 +90,7 @@ set(SRC
intern/math_vector_inline.c
intern/memory_utils.c
intern/noise.c
+ intern/noise_gabor.c
intern/path_util.c
intern/polyfill2d.c
intern/polyfill2d_beautify.c
diff --git a/source/blender/blenlib/intern/noise.c
b/source/blender/blenlib/intern/noise.c
index c3a0c44..f68e11f 100644
--- a/source/blender/blenlib/intern/noise.c
+++ b/source/blender/blenlib/intern/noise.c
@@ -34,6 +34,9 @@
#include "BLI_noise.h"
+/* XXX stub for preventing linker from stripping functions */
+void *__BLI_noise_linker_hack__ = BLI_gabor_noise;
+
/* local */
static float noise3_perlin(float vec[3]);
//static float turbulence_perlin(const float point[3], float lofreq, float
hifreq);
diff --git a/source/blender/blenlib/intern/noise_gabor.c
b/source/blender/blenlib/intern/noise_gabor.c
new file mode 100644
index 0000000..a8a908b
--- /dev/null
+++ b/source/blender/blenlib/intern/noise_gabor.c
@@ -0,0 +1,288 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/*
+Copyright (c) 2012 Sony Pictures Imageworks Inc., et al.
+All Rights Reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+* Neither the name of Sony Pictures Imageworks nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/** \file blender/blenlib/intern/noise_gabor.c
+ * \ingroup bli
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+#include "BLI_sys_types.h"
+
+#include "BLI_noise.h"
+
+/* ------------------------------------------------------------------------- */
+/* Local RNG definition, to avoid alloc from BLI_rand */
+
+typedef struct RNG {
+ uint64_t X;
+} RNG;
+
+#define MULTIPLIER 0x5DEECE66Dll
+#define MASK 0x0000FFFFFFFFFFFFll
+
+#define ADDEND 0xB
+#define LOWSEED 0x330E
+
+BLI_INLINE void rng_init(RNG *rng, unsigned int seed)
+{
+ rng->X = (((uint64_t) seed) << 16) | LOWSEED;
+}
+
+BLI_INLINE void rng_step(RNG *rng)
+{
+ rng->X = (MULTIPLIER * rng->X + ADDEND) & MASK;
+}
+
+BLI_INLINE int rng_get_int(RNG *rng)
+{
+ rng_step(rng);
+ return (int) (rng->X >> 17);
+}
+
+BLI_INLINE unsigned int rng_get_uint(RNG *rng)
+{
+ rng_step(rng);
+ return (unsigned int) (rng->X >> 17);
+}
+
+BLI_INLINE float rng_get_float(RNG *rng)
+{
+ return (float) rng_get_int(rng) / 0x80000000;
+}
+
+/* ------------------------------------------------------------------------- */
+
+BLI_INLINE unsigned int cell_hash(const int index[3])
+{
+ unsigned int n = index[0] + index[1] * 1301 + index[2] * 314159;
+ n ^= (n << 13);
+ return (n * (n * n * 15731 + 789221) + 1376312589);
+}
+
+/* Poisson distribution generator according to Knuth */
+BLI_INLINE unsigned int poisson_rng(RNG *rng, float lambda)
+{
+ const int maxiter = 100000;
+ const float L = expf(-lambda);
+ float p = 1.0f;
+ for (unsigned int k = 0; k < maxiter; ++k) {
+ p *= rng_get_float(rng);
+ if (p <= L)
+ return k;
+ }
+ return 0;
+}
+
+BLI_INLINE float gabor_kernel(
+ const float v[3],
+ float K, float a,
+ const float omega0[3], float phi0)
+{
+ float envelope = K * expf(-M_PI * a*a * dot_v3v3(v, v))
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs