Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmarSquircleArt <omar.squircleart@gmail.com>2019-09-04 18:54:32 +0300
committerOmarSquircleArt <omar.squircleart@gmail.com>2019-09-04 18:54:32 +0300
commit23564583a4988778b4c43496fd21818b286f6ba1 (patch)
tree3dc149c4e5c26ea2aac460ed582cb31def988470 /intern/cycles/kernel/shaders
parent45d4c925799e94c6d442a9a9066af2d3305724e1 (diff)
Shading: Extend Noise node to other dimenstions.
This patch extends perlin noise to operate in 1D, 2D, 3D, and 4D space. The noise code has also been refactored to be more readable. The Color output and distortion patterns changed, so this patch breaks backward compatibility. This is due to the fact that we now use random offsets as noise seeds, as opposed to swizzling and constants offsets. Reviewers: brecht, JacquesLucke Differential Revision: https://developer.blender.org/D5560
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r--intern/cycles/kernel/shaders/CMakeLists.txt4
-rw-r--r--intern/cycles/kernel/shaders/node_brick_texture.osl1
-rw-r--r--intern/cycles/kernel/shaders/node_checker_texture.osl1
-rw-r--r--intern/cycles/kernel/shaders/node_gradient_texture.osl1
-rw-r--r--intern/cycles/kernel/shaders/node_ies_light.osl1
-rw-r--r--intern/cycles/kernel/shaders/node_magic_texture.osl1
-rw-r--r--intern/cycles/kernel/shaders/node_musgrave_texture.osl26
-rw-r--r--intern/cycles/kernel/shaders/node_noise.h198
-rw-r--r--intern/cycles/kernel/shaders/node_noise_texture.osl128
-rw-r--r--intern/cycles/kernel/shaders/node_texture.h165
-rw-r--r--intern/cycles/kernel/shaders/node_voronoi_texture.osl10
-rw-r--r--intern/cycles/kernel/shaders/node_wave_texture.osl4
-rw-r--r--intern/cycles/kernel/shaders/vector2.h291
-rw-r--r--intern/cycles/kernel/shaders/vector4.h327
14 files changed, 951 insertions, 207 deletions
diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt
index c50bffe27b2..a45c43e01ed 100644
--- a/intern/cycles/kernel/shaders/CMakeLists.txt
+++ b/intern/cycles/kernel/shaders/CMakeLists.txt
@@ -97,10 +97,12 @@ set(SRC_OSL
set(SRC_OSL_HEADERS
node_color.h
node_fresnel.h
+ node_noise.h
node_ramp_util.h
- node_texture.h
stdosl.h
oslutil.h
+ vector2.h
+ vector4.h
)
set(SRC_OSO
diff --git a/intern/cycles/kernel/shaders/node_brick_texture.osl b/intern/cycles/kernel/shaders/node_brick_texture.osl
index 0abc3574c48..30644ef2ff3 100644
--- a/intern/cycles/kernel/shaders/node_brick_texture.osl
+++ b/intern/cycles/kernel/shaders/node_brick_texture.osl
@@ -15,7 +15,6 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
/* Brick */
diff --git a/intern/cycles/kernel/shaders/node_checker_texture.osl b/intern/cycles/kernel/shaders/node_checker_texture.osl
index e068f7952ed..e05cf20099f 100644
--- a/intern/cycles/kernel/shaders/node_checker_texture.osl
+++ b/intern/cycles/kernel/shaders/node_checker_texture.osl
@@ -15,7 +15,6 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
/* Checker */
diff --git a/intern/cycles/kernel/shaders/node_gradient_texture.osl b/intern/cycles/kernel/shaders/node_gradient_texture.osl
index 52bf466673d..5cc81d367f2 100644
--- a/intern/cycles/kernel/shaders/node_gradient_texture.osl
+++ b/intern/cycles/kernel/shaders/node_gradient_texture.osl
@@ -15,7 +15,6 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
/* Gradient */
diff --git a/intern/cycles/kernel/shaders/node_ies_light.osl b/intern/cycles/kernel/shaders/node_ies_light.osl
index ce0173451da..6e9181cde40 100644
--- a/intern/cycles/kernel/shaders/node_ies_light.osl
+++ b/intern/cycles/kernel/shaders/node_ies_light.osl
@@ -15,7 +15,6 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
/* IES Light */
diff --git a/intern/cycles/kernel/shaders/node_magic_texture.osl b/intern/cycles/kernel/shaders/node_magic_texture.osl
index aa700e575ef..26e7d57278b 100644
--- a/intern/cycles/kernel/shaders/node_magic_texture.osl
+++ b/intern/cycles/kernel/shaders/node_magic_texture.osl
@@ -15,7 +15,6 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
/* Magic */
diff --git a/intern/cycles/kernel/shaders/node_musgrave_texture.osl b/intern/cycles/kernel/shaders/node_musgrave_texture.osl
index a7877c43d46..0bf462e2103 100644
--- a/intern/cycles/kernel/shaders/node_musgrave_texture.osl
+++ b/intern/cycles/kernel/shaders/node_musgrave_texture.osl
@@ -15,7 +15,7 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
+#include "node_noise.h"
/* Musgrave fBm
*
@@ -36,14 +36,14 @@ float noise_musgrave_fBm(point ip, float H, float lacunarity, float octaves)
point p = ip;
for (i = 0; i < (int)octaves; i++) {
- value += safe_noise(p, "signed") * pwr;
+ value += safe_noise(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
rmd = octaves - floor(octaves);
if (rmd != 0.0)
- value += rmd * safe_noise(p, "signed") * pwr;
+ value += rmd * safe_noise(p) * pwr;
return value;
}
@@ -65,14 +65,14 @@ float noise_musgrave_multi_fractal(point ip, float H, float lacunarity, float oc
point p = ip;
for (i = 0; i < (int)octaves; i++) {
- value *= (pwr * safe_noise(p, "signed") + 1.0);
+ value *= (pwr * safe_noise(p) + 1.0);
pwr *= pwHL;
p *= lacunarity;
}
rmd = octaves - floor(octaves);
if (rmd != 0.0)
- value *= (rmd * pwr * safe_noise(p, "signed") + 1.0); /* correct? */
+ value *= (rmd * pwr * safe_noise(p) + 1.0); /* correct? */
return value;
}
@@ -95,11 +95,11 @@ float noise_musgrave_hetero_terrain(
point p = ip;
/* first unscaled octave of function; later octaves are scaled */
- value = offset + safe_noise(p, "signed");
+ value = offset + safe_noise(p);
p *= lacunarity;
for (i = 1; i < (int)octaves; i++) {
- increment = (safe_noise(p, "signed") + offset) * pwr * value;
+ increment = (safe_noise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
@@ -107,7 +107,7 @@ float noise_musgrave_hetero_terrain(
rmd = octaves - floor(octaves);
if (rmd != 0.0) {
- increment = (safe_noise(p, "signed") + offset) * pwr * value;
+ increment = (safe_noise(p) + offset) * pwr * value;
value += rmd * increment;
}
@@ -131,7 +131,7 @@ float noise_musgrave_hybrid_multi_fractal(
int i;
point p = ip;
- result = safe_noise(p, "signed") + offset;
+ result = safe_noise(p) + offset;
weight = gain * result;
p *= lacunarity;
@@ -139,7 +139,7 @@ float noise_musgrave_hybrid_multi_fractal(
if (weight > 1.0)
weight = 1.0;
- signal = (safe_noise(p, "signed") + offset) * pwr;
+ signal = (safe_noise(p) + offset) * pwr;
pwr *= pwHL;
result += weight * signal;
weight *= gain * signal;
@@ -148,7 +148,7 @@ float noise_musgrave_hybrid_multi_fractal(
rmd = octaves - floor(octaves);
if (rmd != 0.0)
- result += rmd * ((safe_noise(p, "signed") + offset) * pwr);
+ result += rmd * ((safe_noise(p) + offset) * pwr);
return result;
}
@@ -170,7 +170,7 @@ float noise_musgrave_ridged_multi_fractal(
int i;
point p = ip;
- signal = offset - fabs(safe_noise(p, "signed"));
+ signal = offset - fabs(safe_noise(p));
signal *= signal;
result = signal;
weight = 1.0;
@@ -178,7 +178,7 @@ float noise_musgrave_ridged_multi_fractal(
for (i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = clamp(signal * gain, 0.0, 1.0);
- signal = offset - fabs(safe_noise(p, "signed"));
+ signal = offset - fabs(safe_noise(p));
signal *= signal;
signal *= weight;
result += signal * pwr;
diff --git a/intern/cycles/kernel/shaders/node_noise.h b/intern/cycles/kernel/shaders/node_noise.h
new file mode 100644
index 00000000000..23d1987a00e
--- /dev/null
+++ b/intern/cycles/kernel/shaders/node_noise.h
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "vector2.h"
+#include "vector4.h"
+
+#define vector3 point
+
+float safe_noise(float p)
+{
+ float f = noise("noise", p);
+ if (isinf(f))
+ return 0.5;
+ return f;
+}
+
+float safe_noise(vector2 p)
+{
+ float f = noise("noise", p.x, p.y);
+ if (isinf(f))
+ return 0.5;
+ return f;
+}
+
+float safe_noise(vector3 p)
+{
+ float f = noise("noise", p);
+ if (isinf(f))
+ return 0.5;
+ return f;
+}
+
+float safe_noise(vector4 p)
+{
+ float f = noise("noise", vector3(p.x, p.y, p.z), p.w);
+ if (isinf(f))
+ return 0.5;
+ return f;
+}
+
+float safe_snoise(float p)
+{
+ float f = noise("snoise", p);
+ if (isinf(f))
+ return 0.0;
+ return f;
+}
+
+float safe_snoise(vector2 p)
+{
+ float f = noise("snoise", p.x, p.y);
+ if (isinf(f))
+ return 0.0;
+ return f;
+}
+
+float safe_snoise(vector3 p)
+{
+ float f = noise("snoise", p);
+ if (isinf(f))
+ return 0.0;
+ return f;
+}
+
+float safe_snoise(vector4 p)
+{
+ float f = noise("snoise", vector3(p.x, p.y, p.z), p.w);
+ if (isinf(f))
+ return 0.0;
+ return f;
+}
+
+/* The fractal_noise functions are all exactly the same except for the input type. */
+float fractal_noise(float p, float details)
+{
+ float fscale = 1.0;
+ float amp = 1.0;
+ float sum = 0.0;
+ float octaves = clamp(details, 0.0, 16.0);
+ int n = (int)octaves;
+ for (int i = 0; i <= n; i++) {
+ float t = safe_noise(fscale * p);
+ sum += t * amp;
+ amp *= 0.5;
+ fscale *= 2.0;
+ }
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float t = safe_noise(fscale * p);
+ float sum2 = sum + t * amp;
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ return (1.0 - rmd) * sum + rmd * sum2;
+ }
+ else {
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ return sum;
+ }
+}
+
+/* The fractal_noise functions are all exactly the same except for the input type. */
+float fractal_noise(vector2 p, float details)
+{
+ float fscale = 1.0;
+ float amp = 1.0;
+ float sum = 0.0;
+ float octaves = clamp(details, 0.0, 16.0);
+ int n = (int)octaves;
+ for (int i = 0; i <= n; i++) {
+ float t = safe_noise(fscale * p);
+ sum += t * amp;
+ amp *= 0.5;
+ fscale *= 2.0;
+ }
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float t = safe_noise(fscale * p);
+ float sum2 = sum + t * amp;
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ return (1.0 - rmd) * sum + rmd * sum2;
+ }
+ else {
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ return sum;
+ }
+}
+
+/* The fractal_noise functions are all exactly the same except for the input type. */
+float fractal_noise(vector3 p, float details)
+{
+ float fscale = 1.0;
+ float amp = 1.0;
+ float sum = 0.0;
+ float octaves = clamp(details, 0.0, 16.0);
+ int n = (int)octaves;
+ for (int i = 0; i <= n; i++) {
+ float t = safe_noise(fscale * p);
+ sum += t * amp;
+ amp *= 0.5;
+ fscale *= 2.0;
+ }
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float t = safe_noise(fscale * p);
+ float sum2 = sum + t * amp;
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ return (1.0 - rmd) * sum + rmd * sum2;
+ }
+ else {
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ return sum;
+ }
+}
+
+/* The fractal_noise functions are all exactly the same except for the input type. */
+float fractal_noise(vector4 p, float details)
+{
+ float fscale = 1.0;
+ float amp = 1.0;
+ float sum = 0.0;
+ float octaves = clamp(details, 0.0, 16.0);
+ int n = (int)octaves;
+ for (int i = 0; i <= n; i++) {
+ float t = safe_noise(fscale * p);
+ sum += t * amp;
+ amp *= 0.5;
+ fscale *= 2.0;
+ }
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float t = safe_noise(fscale * p);
+ float sum2 = sum + t * amp;
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
+ return (1.0 - rmd) * sum + rmd * sum2;
+ }
+ else {
+ sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
+ return sum;
+ }
+}
+
+#undef vector3
diff --git a/intern/cycles/kernel/shaders/node_noise_texture.osl b/intern/cycles/kernel/shaders/node_noise_texture.osl
index 2cbd571e206..242a7e33f60 100644
--- a/intern/cycles/kernel/shaders/node_noise_texture.osl
+++ b/intern/cycles/kernel/shaders/node_noise_texture.osl
@@ -15,46 +15,134 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
+#include "vector2.h"
+#include "vector4.h"
+#include "node_noise.h"
-/* Noise */
+#define vector3 point
-float noise(point ip, float distortion, float detail, output color Color)
+/* The following offset functions generate random offsets to be added to texture
+ * coordinates to act as a seed since the noise functions don't have seed values.
+ * A seed value is needed for generating distortion textures and color outputs.
+ * The offset's components are in the range [100, 200], not too high to cause
+ * bad precision and not to small to be noticeable. We use float seed because
+ * OSL only support float hashes.
+ */
+
+float random_float_offset(float seed)
+{
+ return 100.0 + noise("hash", seed) * 100.0;
+}
+
+vector2 random_vector2_offset(float seed)
+{
+ return vector2(100.0 + noise("hash", seed, 0.0) * 100.0,
+ 100.0 + noise("hash", seed, 1.0) * 100.0);
+}
+
+vector3 random_vector3_offset(float seed)
{
- point r;
- point p = ip;
- int hard = 0;
+ return vector3(100.0 + noise("hash", seed, 0.0) * 100.0,
+ 100.0 + noise("hash", seed, 1.0) * 100.0,
+ 100.0 + noise("hash", seed, 2.0) * 100.0);
+}
+
+vector4 random_vector4_offset(float seed)
+{
+ return vector4(100.0 + noise("hash", seed, 0.0) * 100.0,
+ 100.0 + noise("hash", seed, 1.0) * 100.0,
+ 100.0 + noise("hash", seed, 2.0) * 100.0,
+ 100.0 + noise("hash", seed, 3.0) * 100.0);
+}
+float noise_texture(float co, float detail, float distortion, output color Color)
+{
+ float p = co;
if (distortion != 0.0) {
- r[0] = safe_noise(p + point(13.5), "unsigned") * distortion;
- r[1] = safe_noise(p, "unsigned") * distortion;
- r[2] = safe_noise(p - point(13.5), "unsigned") * distortion;
+ p += safe_noise(p + random_float_offset(0.0)) * distortion;
+ }
+
+ float value = fractal_noise(p, detail);
+ Color = color(value,
+ fractal_noise(p + random_float_offset(1.0), detail),
+ fractal_noise(p + random_float_offset(2.0), detail));
+ return value;
+}
- p += r;
+float noise_texture(vector2 co, float detail, float distortion, output color Color)
+{
+ vector2 p = co;
+ if (distortion != 0.0) {
+ p += vector2(safe_noise(p + random_vector2_offset(0.0)) * distortion,
+ safe_noise(p + random_vector2_offset(1.0)) * distortion);
}
- float fac = noise_turbulence(p, detail, hard);
+ float value = fractal_noise(p, detail);
+ Color = color(value,
+ fractal_noise(p + random_vector2_offset(2.0), detail),
+ fractal_noise(p + random_vector2_offset(3.0), detail));
+ return value;
+}
- Color = color(fac,
- noise_turbulence(point(p[1], p[0], p[2]), detail, hard),
- noise_turbulence(point(p[1], p[2], p[0]), detail, hard));
+float noise_texture(vector3 co, float detail, float distortion, output color Color)
+{
+ vector3 p = co;
+ if (distortion != 0.0) {
+ p += vector3(safe_noise(p + random_vector3_offset(0.0)) * distortion,
+ safe_noise(p + random_vector3_offset(1.0)) * distortion,
+ safe_noise(p + random_vector3_offset(2.0)) * distortion);
+ }
- return fac;
+ float value = fractal_noise(p, detail);
+ Color = color(value,
+ fractal_noise(p + random_vector3_offset(3.0), detail),
+ fractal_noise(p + random_vector3_offset(4.0), detail));
+ return value;
+}
+
+float noise_texture(vector4 co, float detail, float distortion, output color Color)
+{
+ vector4 p = co;
+ if (distortion != 0.0) {
+ p += vector4(safe_noise(p + random_vector4_offset(0.0)) * distortion,
+ safe_noise(p + random_vector4_offset(1.0)) * distortion,
+ safe_noise(p + random_vector4_offset(2.0)) * distortion,
+ safe_noise(p + random_vector4_offset(3.0)) * distortion);
+ }
+
+ float value = fractal_noise(p, detail);
+ Color = color(value,
+ fractal_noise(p + random_vector4_offset(4.0), detail),
+ fractal_noise(p + random_vector4_offset(5.0), detail));
+ return value;
}
shader node_noise_texture(int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
- float Distortion = 0.0,
+ string dimensions = "3D",
+ vector3 Vector = vector3(0, 0, 0),
+ float W = 0.0,
float Scale = 5.0,
float Detail = 2.0,
- point Vector = P,
+ float Distortion = 0.0,
output float Fac = 0.0,
output color Color = 0.0)
{
- point p = Vector;
-
+ vector3 p = Vector;
if (use_mapping)
p = transform(mapping, p);
+
+ p *= Scale;
+ float w = W * Scale;
- Fac = noise(p * Scale, Distortion, Detail, Color);
+ if (dimensions == "1D")
+ Fac = noise_texture(w, Detail, Distortion, Color);
+ else if (dimensions == "2D")
+ Fac = noise_texture(vector2(p[0], p[1]), Detail, Distortion, Color);
+ else if (dimensions == "3D")
+ Fac = noise_texture(p, Detail, Distortion, Color);
+ else if (dimensions == "4D")
+ Fac = noise_texture(vector4(p[0], p[1], p[2], w), Detail, Distortion, Color);
+ else
+ error("Unknown dimension!");
}
diff --git a/intern/cycles/kernel/shaders/node_texture.h b/intern/cycles/kernel/shaders/node_texture.h
deleted file mode 100644
index e1f3b900ee5..00000000000
--- a/intern/cycles/kernel/shaders/node_texture.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2011-2013 Blender Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Voronoi / Worley like */
-
-color cellnoise_color(point p)
-{
- float r = cellnoise(p);
- float g = cellnoise(point(p[1], p[0], p[2]));
- float b = cellnoise(point(p[1], p[2], p[0]));
-
- return color(r, g, b);
-}
-
-void voronoi(point p, float e, float da[4], point pa[4])
-{
- /* returns distances in da and point coords in pa */
- int xx, yy, zz, xi, yi, zi;
-
- xi = (int)floor(p[0]);
- yi = (int)floor(p[1]);
- zi = (int)floor(p[2]);
-
- da[0] = 1e10;
- da[1] = 1e10;
- da[2] = 1e10;
- da[3] = 1e10;
-
- for (xx = xi - 1; xx <= xi + 1; xx++) {
- 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 pd = p - (vp + ip);
- float d = dot(pd, pd);
-
- vp += point(xx, yy, zz);
-
- if (d < da[0]) {
- da[3] = da[2];
- da[2] = da[1];
- da[1] = da[0];
- da[0] = d;
-
- pa[3] = pa[2];
- pa[2] = pa[1];
- pa[1] = pa[0];
- pa[0] = vp;
- }
- else if (d < da[1]) {
- da[3] = da[2];
- da[2] = da[1];
- da[1] = d;
-
- pa[3] = pa[2];
- pa[2] = pa[1];
- pa[1] = vp;
- }
- else if (d < da[2]) {
- da[3] = da[2];
- da[2] = d;
-
- pa[3] = pa[2];
- pa[2] = vp;
- }
- else if (d < da[3]) {
- da[3] = d;
- pa[3] = vp;
- }
- }
- }
- }
-}
-
-/* Noise Bases */
-
-float safe_noise(point p, string type)
-{
- float f = 0.0;
-
- /* Perlin noise in range -1..1 */
- if (type == "signed")
- f = noise("perlin", p);
-
- /* Perlin noise in range 0..1 */
- else
- f = noise(p);
-
- /* can happen for big coordinates, things even out to 0.5 then anyway */
- if (!isfinite(f))
- return 0.5;
-
- return f;
-}
-
-/* Turbulence */
-
-float noise_turbulence(point p, float details, int hard)
-{
- float fscale = 1.0;
- float amp = 1.0;
- float sum = 0.0;
- int i, n;
-
- float octaves = clamp(details, 0.0, 16.0);
- n = (int)octaves;
-
- for (i = 0; i <= n; i++) {
- float t = safe_noise(fscale * p, "unsigned");
-
- if (hard)
- t = fabs(2.0 * t - 1.0);
-
- sum += t * amp;
- amp *= 0.5;
- fscale *= 2.0;
- }
-
- float rmd = octaves - floor(octaves);
-
- if (rmd != 0.0) {
- float t = safe_noise(fscale * p, "unsigned");
-
- if (hard)
- t = fabs(2.0 * t - 1.0);
-
- float sum2 = sum + t * amp;
-
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- sum2 *= ((float)(1 << (n + 1)) / (float)((1 << (n + 2)) - 1));
-
- return (1.0 - rmd) * sum + rmd * sum2;
- }
- else {
- sum *= ((float)(1 << n) / (float)((1 << (n + 1)) - 1));
- return sum;
- }
-}
-
-/* Utility */
-
-float nonzero(float f, float eps)
-{
- float r;
-
- if (abs(f) < eps)
- r = sign(f) * eps;
- else
- r = f;
-
- return r;
-}
diff --git a/intern/cycles/kernel/shaders/node_voronoi_texture.osl b/intern/cycles/kernel/shaders/node_voronoi_texture.osl
index 34c86d5b98d..0d547b4b615 100644
--- a/intern/cycles/kernel/shaders/node_voronoi_texture.osl
+++ b/intern/cycles/kernel/shaders/node_voronoi_texture.osl
@@ -15,7 +15,15 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
+
+color cellnoise_color(point p)
+{
+ float r = cellnoise(p);
+ float g = cellnoise(point(p[1], p[0], p[2]));
+ float b = cellnoise(point(p[1], p[2], p[0]));
+
+ return color(r, g, b);
+}
void voronoi_m(point p, string metric, float e, float da[4], point pa[4])
{
diff --git a/intern/cycles/kernel/shaders/node_wave_texture.osl b/intern/cycles/kernel/shaders/node_wave_texture.osl
index dfc2dbfb800..60591b79b33 100644
--- a/intern/cycles/kernel/shaders/node_wave_texture.osl
+++ b/intern/cycles/kernel/shaders/node_wave_texture.osl
@@ -15,7 +15,7 @@
*/
#include "stdosl.h"
-#include "node_texture.h"
+#include "node_noise.h"
/* Wave */
@@ -31,7 +31,7 @@ float wave(point p, string type, string profile, float detail, float distortion,
}
if (distortion != 0.0) {
- n = n + (distortion * noise_turbulence(p * dscale, detail, 0));
+ n = n + (distortion * fractal_noise(p * dscale, detail));
}
if (profile == "sine") {
diff --git a/intern/cycles/kernel/shaders/vector2.h b/intern/cycles/kernel/shaders/vector2.h
new file mode 100644
index 00000000000..c524735d892
--- /dev/null
+++ b/intern/cycles/kernel/shaders/vector2.h
@@ -0,0 +1,291 @@
+// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
+// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
+
+#pragma once
+#define VECTOR2_H
+
+// vector2 is a 2D vector
+struct vector2 {
+ float x;
+ float y;
+};
+
+//
+// For vector2, define math operators to match vector
+//
+
+vector2 __operator__neg__(vector2 a)
+{
+ return vector2(-a.x, -a.y);
+}
+
+vector2 __operator__add__(vector2 a, vector2 b)
+{
+ return vector2(a.x + b.x, a.y + b.y);
+}
+
+vector2 __operator__add__(vector2 a, int b)
+{
+ return a + vector2(b, b);
+}
+
+vector2 __operator__add__(vector2 a, float b)
+{
+ return a + vector2(b, b);
+}
+
+vector2 __operator__add__(int a, vector2 b)
+{
+ return vector2(a, a) + b;
+}
+
+vector2 __operator__add__(float a, vector2 b)
+{
+ return vector2(a, a) + b;
+}
+
+vector2 __operator__sub__(vector2 a, vector2 b)
+{
+ return vector2(a.x - b.x, a.y - b.y);
+}
+
+vector2 __operator__sub__(vector2 a, int b)
+{
+ return a - vector2(b, b);
+}
+
+vector2 __operator__sub__(vector2 a, float b)
+{
+ return a - vector2(b, b);
+}
+
+vector2 __operator__sub__(int a, vector2 b)
+{
+ return vector2(a, a) - b;
+}
+
+vector2 __operator__sub__(float a, vector2 b)
+{
+ return vector2(a, a) - b;
+}
+
+vector2 __operator__mul__(vector2 a, vector2 b)
+{
+ return vector2(a.x * b.x, a.y * b.y);
+}
+
+vector2 __operator__mul__(vector2 a, int b)
+{
+ return a * vector2(b, b);
+}
+
+vector2 __operator__mul__(vector2 a, float b)
+{
+ return a * vector2(b, b);
+}
+
+vector2 __operator__mul__(int a, vector2 b)
+{
+ return b * vector2(a, a);
+}
+
+vector2 __operator__mul__(float a, vector2 b)
+{
+ return b * vector2(a, a);
+}
+
+vector2 __operator__div__(vector2 a, vector2 b)
+{
+ return vector2(a.x / b.x, a.y / b.y);
+}
+
+vector2 __operator__div__(vector2 a, int b)
+{
+ float b_inv = 1 / b;
+ return a * vector2(b_inv, b_inv);
+}
+
+vector2 __operator__div__(vector2 a, float b)
+{
+ float b_inv = 1 / b;
+ return a * vector2(b_inv, b_inv);
+}
+
+vector2 __operator__div__(int a, vector2 b)
+{
+ return vector2(a, a) / b;
+}
+
+vector2 __operator__div__(float a, vector2 b)
+{
+ return vector2(a, a) / b;
+}
+
+int __operator__eq__(vector2 a, vector2 b)
+{
+ return (a.x == b.x) && (a.y == b.y);
+}
+
+int __operator__ne__(vector2 a, vector2 b)
+{
+ return (a.x != b.x) || (a.y != b.y);
+}
+
+//
+// For vector2, define most of the stdosl functions to match vector
+//
+
+vector2 abs(vector2 a)
+{
+ return vector2(abs(a.x), abs(a.y));
+}
+
+vector2 ceil(vector2 a)
+{
+ return vector2(ceil(a.x), ceil(a.y));
+}
+
+vector2 floor(vector2 a)
+{
+ return vector2(floor(a.x), floor(a.y));
+}
+
+vector2 sqrt(vector2 a)
+{
+ return vector2(sqrt(a.x), sqrt(a.y));
+}
+
+vector2 exp(vector2 a)
+{
+ return vector2(exp(a.x), exp(a.y));
+}
+
+vector2 log(vector2 a)
+{
+ return vector2(log(a.x), log(a.y));
+}
+
+vector2 log2(vector2 a)
+{
+ return vector2(log2(a.x), log2(a.y));
+}
+
+vector2 mix(vector2 a, vector2 b, float x)
+{
+ return vector2(mix(a.x, b.x, x), mix(a.y, b.y, x));
+}
+
+float dot(vector2 a, vector2 b)
+{
+ return (a.x * b.x + a.y * b.y);
+}
+
+float length(vector2 a)
+{
+ return hypot(a.x, a.y);
+}
+
+vector2 smoothstep(vector2 low, vector2 high, vector2 in)
+{
+ return vector2(smoothstep(low.x, high.x, in.x), smoothstep(low.y, high.y, in.y));
+}
+
+vector2 smoothstep(float low, float high, vector2 in)
+{
+ return vector2(smoothstep(low, high, in.x), smoothstep(low, high, in.y));
+}
+
+vector2 clamp(vector2 in, vector2 low, vector2 high)
+{
+ return vector2(clamp(in.x, low.x, high.x), clamp(in.y, low.y, high.y));
+}
+
+vector2 clamp(vector2 in, float low, float high)
+{
+ return clamp(in, vector2(low, low), vector2(high, high));
+}
+
+vector2 max(vector2 a, vector2 b)
+{
+ return vector2(max(a.x, b.x), max(a.y, b.y));
+}
+
+vector2 max(vector2 a, float b)
+{
+ return max(a, vector2(b, b));
+}
+
+vector2 normalize(vector2 a)
+{
+ return a / length(a);
+}
+
+vector2 min(vector2 a, vector2 b)
+{
+ return vector2(min(a.x, a.x), min(b.y, b.y));
+}
+
+vector2 min(vector2 a, float b)
+{
+ return min(a, vector2(b, b));
+}
+
+vector2 fmod(vector2 a, vector2 b)
+{
+ return vector2(fmod(a.x, b.x), fmod(a.y, b.y));
+}
+
+vector2 fmod(vector2 a, float b)
+{
+ return fmod(a, vector2(b, b));
+}
+
+vector2 pow(vector2 in, vector2 amount)
+{
+ return vector2(pow(in.x, amount.x), pow(in.y, amount.y));
+}
+
+vector2 pow(vector2 in, float amount)
+{
+ return pow(in, vector2(amount, amount));
+}
+
+vector2 sign(vector2 a)
+{
+ return vector2(sign(a.x), sign(a.y));
+}
+
+vector2 sin(vector2 a)
+{
+ return vector2(sin(a.x), sin(a.y));
+}
+
+vector2 cos(vector2 a)
+{
+ return vector2(cos(a.x), cos(a.y));
+}
+
+vector2 tan(vector2 a)
+{
+ return vector2(tan(a.x), tan(a.y));
+}
+
+vector2 asin(vector2 a)
+{
+ return vector2(asin(a.x), asin(a.y));
+}
+
+vector2 acos(vector2 a)
+{
+ return vector2(acos(a.x), acos(a.y));
+}
+
+vector2 atan2(vector2 a, float f)
+{
+ return vector2(atan2(a.x, f), atan2(a.y, f));
+}
+
+vector2 atan2(vector2 a, vector2 b)
+{
+ return vector2(atan2(a.x, b.x), atan2(a.y, b.y));
+}
diff --git a/intern/cycles/kernel/shaders/vector4.h b/intern/cycles/kernel/shaders/vector4.h
new file mode 100644
index 00000000000..58e1b3c2e23
--- /dev/null
+++ b/intern/cycles/kernel/shaders/vector4.h
@@ -0,0 +1,327 @@
+// Open Shading Language : Copyright (c) 2009-2017 Sony Pictures Imageworks Inc., et al.
+// https://github.com/imageworks/OpenShadingLanguage/blob/master/LICENSE
+
+#pragma once
+#define VECTOR4_H
+
+// vector4 is a 4D vector
+struct vector4 {
+ float x;
+ float y;
+ float z;
+ float w;
+};
+
+//
+// For vector4, define math operators to match vector
+//
+
+vector4 __operator__neg__(vector4 a)
+{
+ return vector4(-a.x, -a.y, -a.z, -a.w);
+}
+
+vector4 __operator__add__(vector4 a, vector4 b)
+{
+ return vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
+}
+
+vector4 __operator__add__(vector4 a, int b)
+{
+ return a + vector4(b, b, b, b);
+}
+
+vector4 __operator__add__(vector4 a, float b)
+{
+ return a + vector4(b, b, b, b);
+}
+
+vector4 __operator__add__(int a, vector4 b)
+{
+ return vector4(a, a, a, a) + b;
+}
+
+vector4 __operator__add__(float a, vector4 b)
+{
+ return vector4(a, a, a, a) + b;
+}
+
+vector4 __operator__sub__(vector4 a, vector4 b)
+{
+ return vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
+}
+
+vector4 __operator__sub__(vector4 a, int b)
+{
+ return a - vector4(b, b, b, b);
+}
+
+vector4 __operator__sub__(vector4 a, float b)
+{
+ return a - vector4(b, b, b, b);
+}
+
+vector4 __operator__sub__(int a, vector4 b)
+{
+ return vector4(a, a, a, a) - b;
+}
+
+vector4 __operator__sub__(float a, vector4 b)
+{
+ return vector4(a, a, a, a) - b;
+}
+
+vector4 __operator__mul__(vector4 a, vector4 b)
+{
+ return vector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
+}
+
+vector4 __operator__mul__(vector4 a, int b)
+{
+ return a * vector4(b, b, b, b);
+}
+
+vector4 __operator__mul__(vector4 a, float b)
+{
+ return a * vector4(b, b, b, b);
+}
+
+vector4 __operator__mul__(int a, vector4 b)
+{
+ return vector4(a, a, a, a) * b;
+}
+
+vector4 __operator__mul__(float a, vector4 b)
+{
+ return vector4(a, a, a, a) * b;
+}
+
+vector4 __operator__div__(vector4 a, vector4 b)
+{
+ return vector4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
+}
+
+vector4 __operator__div__(vector4 a, int b)
+{
+ float b_inv = 1 / b;
+ return a * vector4(b_inv, b_inv, b_inv, b_inv);
+}
+
+vector4 __operator__div__(vector4 a, float b)
+{
+ float b_inv = 1 / b;
+ return a * vector4(b_inv, b_inv, b_inv, b_inv);
+}
+
+vector4 __operator__div__(int a, vector4 b)
+{
+ return vector4(a, a, a, a) / b;
+}
+
+vector4 __operator__div__(float a, vector4 b)
+{
+ return vector4(a, a, a, a) / b;
+}
+
+int __operator__eq__(vector4 a, vector4 b)
+{
+ return (a.x == b.x) && (a.y == b.y) && (a.z == b.z) && (a.w == b.w);
+}
+
+int __operator__ne__(vector4 a, vector4 b)
+{
+ return (a.x != b.x) || (a.y != b.y) || (a.z != b.z) || (a.w != b.w);
+}
+
+//
+// For vector4, define most of the stdosl functions to match vector
+//
+
+vector4 abs(vector4 in)
+{
+ return vector4(abs(in.x), abs(in.y), abs(in.z), abs(in.w));
+}
+
+vector4 ceil(vector4 in)
+{
+ return vector4(ceil(in.x), ceil(in.y), ceil(in.z), ceil(in.w));
+}
+
+vector4 floor(vector4 in)
+{
+ return vector4(floor(in.x), floor(in.y), floor(in.z), floor(in.w));
+}
+
+vector4 sqrt(vector4 in)
+{
+ return vector4(sqrt(in.x), sqrt(in.y), sqrt(in.z), sqrt(in.w));
+}
+
+vector4 exp(vector4 in)
+{
+ return vector4(exp(in.x), exp(in.y), exp(in.z), exp(in.w));
+}
+
+vector4 log(vector4 in)
+{
+ return vector4(log(in.x), log(in.y), log(in.z), log(in.w));
+}
+
+vector4 log2(vector4 in)
+{
+ return vector4(log2(in.x), log2(in.y), log2(in.z), log2(in.w));
+}
+
+vector4 mix(vector4 value1, vector4 value2, float x)
+{
+ return vector4(mix(value1.x, value2.x, x),
+ mix(value1.y, value2.y, x),
+ mix(value1.z, value2.z, x),
+ mix(value1.w, value2.w, x));
+}
+
+vector vec4ToVec3(vector4 v)
+{
+ return vector(v.x, v.y, v.z) / v.w;
+}
+
+float dot(vector4 a, vector4 b)
+{
+ return ((a.x * b.x) + (a.y * b.y) + (a.z * b.z) + (a.w * b.w));
+}
+
+float length(vector4 a)
+{
+ return sqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
+}
+
+vector4 smoothstep(vector4 low, vector4 high, vector4 in)
+{
+ return vector4(smoothstep(low.x, high.x, in.x),
+ smoothstep(low.y, high.y, in.y),
+ smoothstep(low.z, high.z, in.z),
+ smoothstep(low.w, high.w, in.w));
+}
+
+vector4 smoothstep(float low, float high, vector4 in)
+{
+ return vector4(smoothstep(low, high, in.x),
+ smoothstep(low, high, in.y),
+ smoothstep(low, high, in.z),
+ smoothstep(low, high, in.w));
+}
+
+vector4 clamp(vector4 in, vector4 low, vector4 high)
+{
+ return vector4(clamp(in.x, low.x, high.x),
+ clamp(in.y, low.y, high.y),
+ clamp(in.z, low.z, high.z),
+ clamp(in.w, low.w, high.w));
+}
+
+vector4 clamp(vector4 in, float low, float high)
+{
+ return vector4(clamp(in.x, low, high),
+ clamp(in.y, low, high),
+ clamp(in.z, low, high),
+ clamp(in.w, low, high));
+}
+
+vector4 max(vector4 a, vector4 b)
+{
+ return vector4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), max(a.w, b.w));
+}
+
+vector4 max(vector4 a, float b)
+{
+ return max(a, vector4(b, b, b, b));
+}
+
+vector4 normalize(vector4 a)
+{
+ return a / length(a);
+}
+
+vector4 min(vector4 a, vector4 b)
+{
+ return vector4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w));
+}
+
+vector4 min(vector4 a, float b)
+{
+ return min(a, vector4(b, b, b, b));
+}
+
+vector4 fmod(vector4 a, vector4 b)
+{
+ return vector4(fmod(a.x, b.x), fmod(a.y, b.y), fmod(a.z, b.z), fmod(a.w, b.w));
+}
+
+vector4 fmod(vector4 a, float b)
+{
+ return fmod(a, vector4(b, b, b, b));
+}
+
+vector4 pow(vector4 in, vector4 amount)
+{
+ return vector4(
+ pow(in.x, amount.x), pow(in.y, amount.y), pow(in.z, amount.z), pow(in.w, amount.w));
+}
+
+vector4 pow(vector4 in, float amount)
+{
+ return vector4(pow(in.x, amount), pow(in.y, amount), pow(in.z, amount), pow(in.w, amount));
+}
+
+vector4 sign(vector4 a)
+{
+ return vector4(sign(a.x), sign(a.y), sign(a.z), sign(a.w));
+}
+
+vector4 sin(vector4 a)
+{
+ return vector4(sin(a.x), sin(a.y), sin(a.z), sin(a.w));
+}
+
+vector4 cos(vector4 a)
+{
+ return vector4(cos(a.x), cos(a.y), cos(a.z), cos(a.w));
+}
+
+vector4 tan(vector4 a)
+{
+ return vector4(tan(a.x), tan(a.y), tan(a.z), tan(a.w));
+}
+
+vector4 asin(vector4 a)
+{
+ return vector4(asin(a.x), asin(a.y), asin(a.z), asin(a.w));
+}
+
+vector4 acos(vector4 a)
+{
+ return vector4(acos(a.x), acos(a.y), acos(a.z), acos(a.w));
+}
+
+vector4 atan2(vector4 a, float f)
+{
+ return vector4(atan2(a.x, f), atan2(a.y, f), atan2(a.z, f), atan2(a.w, f));
+}
+
+vector4 atan2(vector4 a, vector4 b)
+{
+ return vector4(atan2(a.x, b.x), atan2(a.y, b.y), atan2(a.z, b.z), atan2(a.w, b.w));
+}
+
+vector4 transform(matrix M, vector4 p)
+{
+ return vector4(M[0][0] * p.x + M[0][1] * p.y + M[0][2] * p.z + M[0][2] * p.w,
+ M[1][0] * p.x + M[1][1] * p.y + M[1][2] * p.z + M[1][2] * p.w,
+ M[2][0] * p.x + M[2][1] * p.y + M[2][2] * p.z + M[2][2] * p.w,
+ M[3][0] * p.x + M[3][1] * p.y + M[3][2] * p.z + M[3][2] * p.w);
+}
+
+vector4 transform(string fromspace, string tospace, vector4 p)
+{
+ return transform(matrix(fromspace, tospace), p);
+}