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-09 22:06:55 +0300
committerOmarSquircleArt <omar.squircleart@gmail.com>2019-09-09 22:06:55 +0300
commitf2176b3ff3c5df9ab43d1b0489e3bb350d1015f6 (patch)
treef64f3e8453f4c54de37ecd625f6796b43bccd398 /source/blender/gpu
parentc2d37929b4aaaef87bad1d2e90cc76d0c4765e8d (diff)
Shading: Extend Musgrave node to other dimensions.
This patch extends Musgrave noise to operate in 1D, 2D, 3D, and 4D space. The Color output was also removed because it was identical to the Fac output. Reviewed By: brecht Differential Revision: https://developer.blender.org/D5566
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl821
1 files changed, 750 insertions, 71 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl
index 52332c45c3d..7ecca286acd 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl
@@ -1,4 +1,4 @@
-/* Musgrave fBm
+/* 1D Musgrave fBm
*
* H: fractal increment parameter
* lacunarity: gap between successive frequencies
@@ -7,9 +7,465 @@
* from "Texturing and Modelling: A procedural approach"
*/
-float noise_musgrave_fBm(vec3 p, float H, float lacunarity, float octaves)
+void node_tex_musgrave_fBm_1d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- float rmd;
+ float p = w * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float value = 0.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
+
+ for (int i = 0; i < int(octaves); i++) {
+ value += snoise(p) * pwr;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value += rmd * snoise(p) * pwr;
+ }
+
+ fac = value;
+}
+
+/* 1D Musgrave Multifractal
+ *
+ * H: highest fractal dimension
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ */
+
+void node_tex_musgrave_multi_fractal_1d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ float p = w * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float value = 1.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
+
+ for (int i = 0; i < int(octaves); i++) {
+ value *= (pwr * snoise(p) + 1.0);
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value *= (rmd * pwr * snoise(p) + 1.0); /* correct? */
+ }
+
+ fac = value;
+}
+
+/* 1D Musgrave Heterogeneous Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_hetero_terrain_1d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ float p = w * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ /* first unscaled octave of function; later octaves are scaled */
+ float value = offset + snoise(p);
+ p *= lacunarity;
+
+ for (int i = 1; i < int(octaves); i++) {
+ float increment = (snoise(p) + offset) * pwr * value;
+ value += increment;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float increment = (snoise(p) + offset) * pwr * value;
+ value += rmd * increment;
+ }
+
+ fac = value;
+}
+
+/* 1D Hybrid Additive/Multiplicative Multifractal Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_hybrid_multi_fractal_1d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ float p = w * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ float value = snoise(p) + offset;
+ float weight = gain * value;
+ p *= lacunarity;
+
+ for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
+ if (weight > 1.0) {
+ weight = 1.0;
+ }
+
+ float signal = (snoise(p) + offset) * pwr;
+ pwr *= pwHL;
+ value += weight * signal;
+ weight *= gain * signal;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value += rmd * ((snoise(p) + offset) * pwr);
+ }
+
+ fac = value;
+}
+
+/* 1D Ridged Multifractal Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_ridged_multi_fractal_1d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ float p = w * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ float signal = offset - abs(snoise(p));
+ signal *= signal;
+ float value = signal;
+ float weight = 1.0;
+
+ for (int i = 1; i < int(octaves); i++) {
+ p *= lacunarity;
+ weight = clamp(signal * gain, 0.0, 1.0);
+ signal = offset - abs(snoise(p));
+ signal *= signal;
+ signal *= weight;
+ value += signal * pwr;
+ pwr *= pwHL;
+ }
+
+ fac = value;
+}
+
+/* 2D Musgrave fBm
+ *
+ * H: fractal increment parameter
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ *
+ * from "Texturing and Modelling: A procedural approach"
+ */
+
+void node_tex_musgrave_fBm_2d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec2 p = co.xy * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float value = 0.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
+
+ for (int i = 0; i < int(octaves); i++) {
+ value += snoise(p) * pwr;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value += rmd * snoise(p) * pwr;
+ }
+
+ fac = value;
+}
+
+/* 2D Musgrave Multifractal
+ *
+ * H: highest fractal dimension
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ */
+
+void node_tex_musgrave_multi_fractal_2d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec2 p = co.xy * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float value = 1.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
+
+ for (int i = 0; i < int(octaves); i++) {
+ value *= (pwr * snoise(p) + 1.0);
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value *= (rmd * pwr * snoise(p) + 1.0); /* correct? */
+ }
+
+ fac = value;
+}
+
+/* 2D Musgrave Heterogeneous Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_hetero_terrain_2d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec2 p = co.xy * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ /* first unscaled octave of function; later octaves are scaled */
+ float value = offset + snoise(p);
+ p *= lacunarity;
+
+ for (int i = 1; i < int(octaves); i++) {
+ float increment = (snoise(p) + offset) * pwr * value;
+ value += increment;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float increment = (snoise(p) + offset) * pwr * value;
+ value += rmd * increment;
+ }
+
+ fac = value;
+}
+
+/* 2D Hybrid Additive/Multiplicative Multifractal Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_hybrid_multi_fractal_2d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec2 p = co.xy * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ float value = snoise(p) + offset;
+ float weight = gain * value;
+ p *= lacunarity;
+
+ for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
+ if (weight > 1.0) {
+ weight = 1.0;
+ }
+
+ float signal = (snoise(p) + offset) * pwr;
+ pwr *= pwHL;
+ value += weight * signal;
+ weight *= gain * signal;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value += rmd * ((snoise(p) + offset) * pwr);
+ }
+
+ fac = value;
+}
+
+/* 2D Ridged Multifractal Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_ridged_multi_fractal_2d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec2 p = co.xy * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ float signal = offset - abs(snoise(p));
+ signal *= signal;
+ float value = signal;
+ float weight = 1.0;
+
+ for (int i = 1; i < int(octaves); i++) {
+ p *= lacunarity;
+ weight = clamp(signal * gain, 0.0, 1.0);
+ signal = offset - abs(snoise(p));
+ signal *= signal;
+ signal *= weight;
+ value += signal * pwr;
+ pwr *= pwHL;
+ }
+
+ fac = value;
+}
+
+/* 3D Musgrave fBm
+ *
+ * H: fractal increment parameter
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ *
+ * from "Texturing and Modelling: A procedural approach"
+ */
+
+void node_tex_musgrave_fBm_3d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec3 p = co * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
float value = 0.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
@@ -20,24 +476,36 @@ float noise_musgrave_fBm(vec3 p, float H, float lacunarity, float octaves)
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value += rmd * snoise(p) * pwr;
}
- return value;
+ fac = value;
}
-/* Musgrave Multifractal
+/* 3D Musgrave Multifractal
*
* H: highest fractal dimension
* lacunarity: gap between successive frequencies
* octaves: number of frequencies in the fBm
*/
-float noise_musgrave_multi_fractal(vec3 p, float H, float lacunarity, float octaves)
+void node_tex_musgrave_multi_fractal_3d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- float rmd;
+ vec3 p = co * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
float value = 1.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
@@ -48,15 +516,15 @@ float noise_musgrave_multi_fractal(vec3 p, float H, float lacunarity, float octa
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
value *= (rmd * pwr * snoise(p) + 1.0); /* correct? */
}
- return value;
+ fac = value;
}
-/* Musgrave Heterogeneous Terrain
+/* 3D Musgrave Heterogeneous Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -64,33 +532,45 @@ float noise_musgrave_multi_fractal(vec3 p, float H, float lacunarity, float octa
* offset: raises the terrain from `sea level'
*/
-float noise_musgrave_hetero_terrain(vec3 p, float H, float lacunarity, float octaves, float offset)
+void node_tex_musgrave_hetero_terrain_3d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- float value, increment, rmd;
+ vec3 p = co * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
/* first unscaled octave of function; later octaves are scaled */
- value = offset + snoise(p);
+ float value = offset + snoise(p);
p *= lacunarity;
for (int i = 1; i < int(octaves); i++) {
- increment = (snoise(p) + offset) * pwr * value;
+ float increment = (snoise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
- increment = (snoise(p) + offset) * pwr * value;
+ float increment = (snoise(p) + offset) * pwr * value;
value += rmd * increment;
}
- return value;
+ fac = value;
}
-/* Hybrid Additive/Multiplicative Multifractal Terrain
+/* 3D Hybrid Additive/Multiplicative Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -98,15 +578,26 @@ float noise_musgrave_hetero_terrain(vec3 p, float H, float lacunarity, float oct
* offset: raises the terrain from `sea level'
*/
-float noise_musgrave_hybrid_multi_fractal(
- vec3 p, float H, float lacunarity, float octaves, float offset, float gain)
+void node_tex_musgrave_hybrid_multi_fractal_3d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- float result, signal, weight, rmd;
+ vec3 p = co * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
- result = snoise(p) + offset;
- weight = gain * result;
+ float value = snoise(p) + offset;
+ float weight = gain * value;
p *= lacunarity;
for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
@@ -114,22 +605,22 @@ float noise_musgrave_hybrid_multi_fractal(
weight = 1.0;
}
- signal = (snoise(p) + offset) * pwr;
+ float signal = (snoise(p) + offset) * pwr;
pwr *= pwHL;
- result += weight * signal;
+ value += weight * signal;
weight *= gain * signal;
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ float rmd = octaves - floor(octaves);
if (rmd != 0.0) {
- result += rmd * ((snoise(p) + offset) * pwr);
+ value += rmd * ((snoise(p) + offset) * pwr);
}
- return result;
+ fac = value;
}
-/* Ridged Multifractal Terrain
+/* 3D Ridged Multifractal Terrain
*
* H: fractal dimension of the roughest area
* lacunarity: gap between successive frequencies
@@ -137,17 +628,28 @@ float noise_musgrave_hybrid_multi_fractal(
* offset: raises the terrain from `sea level'
*/
-float noise_musgrave_ridged_multi_fractal(
- vec3 p, float H, float lacunarity, float octaves, float offset, float gain)
+void node_tex_musgrave_ridged_multi_fractal_3d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- float result, signal, weight;
+ vec3 p = co * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
- signal = offset - abs(snoise(p));
+ float signal = offset - abs(snoise(p));
signal *= signal;
- result = signal;
- weight = 1.0;
+ float value = signal;
+ float weight = 1.0;
for (int i = 1; i < int(octaves); i++) {
p *= lacunarity;
@@ -155,54 +657,231 @@ float noise_musgrave_ridged_multi_fractal(
signal = offset - abs(snoise(p));
signal *= signal;
signal *= weight;
- result += signal * pwr;
+ value += signal * pwr;
pwr *= pwHL;
}
- return result;
+ fac = value;
}
-float svm_musgrave(int type,
- float dimension,
- float lacunarity,
- float octaves,
- float offset,
- float intensity,
- float gain,
- vec3 p)
+/* 4D Musgrave fBm
+ *
+ * H: fractal increment parameter
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ *
+ * from "Texturing and Modelling: A procedural approach"
+ */
+
+void node_tex_musgrave_fBm_4d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- if (type == 0 /* NODE_MUSGRAVE_MULTIFRACTAL */) {
- return intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
+ vec4 p = vec4(co, w) * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float value = 0.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
+
+ for (int i = 0; i < int(octaves); i++) {
+ value += snoise(p) * pwr;
+ pwr *= pwHL;
+ p *= lacunarity;
}
- else if (type == 1 /* NODE_MUSGRAVE_FBM */) {
- return intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value += rmd * snoise(p) * pwr;
}
- else if (type == 2 /* NODE_MUSGRAVE_HYBRID_MULTIFRACTAL */) {
- return intensity *
- noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
+
+ fac = value;
+}
+
+/* 4D Musgrave Multifractal
+ *
+ * H: highest fractal dimension
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ */
+
+void node_tex_musgrave_multi_fractal_4d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec4 p = vec4(co, w) * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float value = 1.0;
+ float pwr = 1.0;
+ float pwHL = pow(lacunarity, -H);
+
+ for (int i = 0; i < int(octaves); i++) {
+ value *= (pwr * snoise(p) + 1.0);
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value *= (rmd * pwr * snoise(p) + 1.0); /* correct? */
+ }
+
+ fac = value;
+}
+
+/* 4D Musgrave Heterogeneous Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_hetero_terrain_4d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec4 p = vec4(co, w) * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ /* first unscaled octave of function; later octaves are scaled */
+ float value = offset + snoise(p);
+ p *= lacunarity;
+
+ for (int i = 1; i < int(octaves); i++) {
+ float increment = (snoise(p) + offset) * pwr * value;
+ value += increment;
+ pwr *= pwHL;
+ p *= lacunarity;
+ }
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ float increment = (snoise(p) + offset) * pwr * value;
+ value += rmd * increment;
}
- else if (type == 3 /* NODE_MUSGRAVE_RIDGED_MULTIFRACTAL */) {
- return intensity *
- noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
+
+ fac = value;
+}
+
+/* 4D Hybrid Additive/Multiplicative Multifractal Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_hybrid_multi_fractal_4d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
+{
+ vec4 p = vec4(co, w) * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ float value = snoise(p) + offset;
+ float weight = gain * value;
+ p *= lacunarity;
+
+ for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
+ if (weight > 1.0) {
+ weight = 1.0;
+ }
+
+ float signal = (snoise(p) + offset) * pwr;
+ pwr *= pwHL;
+ value += weight * signal;
+ weight *= gain * signal;
+ p *= lacunarity;
}
- else if (type == 4 /* NODE_MUSGRAVE_HETERO_TERRAIN */) {
- return intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, offset);
+
+ float rmd = octaves - floor(octaves);
+ if (rmd != 0.0) {
+ value += rmd * ((snoise(p) + offset) * pwr);
}
- return 0.0;
+
+ fac = value;
}
-void node_tex_musgrave(vec3 co,
- float scale,
- float detail,
- float dimension,
- float lacunarity,
- float offset,
- float gain,
- float type,
- out vec4 color,
- out float fac)
+/* 4D Ridged Multifractal Terrain
+ *
+ * H: fractal dimension of the roughest area
+ * lacunarity: gap between successive frequencies
+ * octaves: number of frequencies in the fBm
+ * offset: raises the terrain from `sea level'
+ */
+
+void node_tex_musgrave_ridged_multi_fractal_4d(vec3 co,
+ float w,
+ float scale,
+ float detail,
+ float dimension,
+ float lac,
+ float offset,
+ float gain,
+ out float fac)
{
- fac = svm_musgrave(int(type), dimension, lacunarity, detail, offset, 1.0, gain, co *scale);
+ vec4 p = vec4(co, w) * scale;
+ float H = max(dimension, 1e-5);
+ float octaves = clamp(detail, 0.0, 16.0);
+ float lacunarity = max(lac, 1e-5);
+
+ float pwHL = pow(lacunarity, -H);
+ float pwr = pwHL;
+
+ float signal = offset - abs(snoise(p));
+ signal *= signal;
+ float value = signal;
+ float weight = 1.0;
+
+ for (int i = 1; i < int(octaves); i++) {
+ p *= lacunarity;
+ weight = clamp(signal * gain, 0.0, 1.0);
+ signal = offset - abs(snoise(p));
+ signal *= signal;
+ signal *= weight;
+ value += signal * pwr;
+ pwr *= pwHL;
+ }
- color = vec4(fac, fac, fac, 1.0);
+ fac = value;
}