diff options
author | Luis Pereira <LuisPereira> | 2022-08-26 16:30:59 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-08-26 18:27:43 +0300 |
commit | 763cafc2b101d3258cb62b9a966b6d7e7629eb85 (patch) | |
tree | c31d77b0dd15c46bb5e318fd2ca3d71de6383a50 /intern/cycles | |
parent | a1c8a17b4d95794ce36ee7db86f98ab818be0ed6 (diff) |
Fix T55284: error in Hybrid MultiFractal Musgrave texture
The calculation was revised to address two issues:
* Discontinuities occurring when detail was a non-integer greater than 2.
* Levels of detail in the interval [0,1) repeating the levels of detail in
the interval [1,2).
This fixes Cycles, Eevee and geometry nodes.
Differential Revision: https://developer.blender.org/D15785
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/osl/shaders/node_musgrave_texture.osl | 68 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/musgrave.h | 69 |
2 files changed, 81 insertions, 56 deletions
diff --git a/intern/cycles/kernel/osl/shaders/node_musgrave_texture.osl b/intern/cycles/kernel/osl/shaders/node_musgrave_texture.osl index 391be8c14d7..fdda1ba9cd1 100644 --- a/intern/cycles/kernel/osl/shaders/node_musgrave_texture.osl +++ b/intern/cycles/kernel/osl/shaders/node_musgrave_texture.osl @@ -114,13 +114,12 @@ float noise_musgrave_hybrid_multi_fractal_1d( { float p = co; float pwHL = pow(lacunarity, -H); - float pwr = pwHL; - float value = safe_snoise(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001) && (i < (int)octaves); i++) { if (weight > 1.0) { weight = 1.0; } @@ -133,8 +132,12 @@ float noise_musgrave_hybrid_multi_fractal_1d( } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((safe_snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (safe_snoise(p) + offset) * pwr; + value += rmd * weight * signal; } return value; @@ -279,13 +282,12 @@ float noise_musgrave_hybrid_multi_fractal_2d( { vector2 p = co; float pwHL = pow(lacunarity, -H); - float pwr = pwHL; - float value = safe_snoise(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001) && (i < (int)octaves); i++) { if (weight > 1.0) { weight = 1.0; } @@ -298,8 +300,12 @@ float noise_musgrave_hybrid_multi_fractal_2d( } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((safe_snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (safe_snoise(p) + offset) * pwr; + value += rmd * weight * signal; } return value; @@ -444,13 +450,12 @@ float noise_musgrave_hybrid_multi_fractal_3d( { vector3 p = co; float pwHL = pow(lacunarity, -H); - float pwr = pwHL; - float value = safe_snoise(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001) && (i < (int)octaves); i++) { if (weight > 1.0) { weight = 1.0; } @@ -463,8 +468,12 @@ float noise_musgrave_hybrid_multi_fractal_3d( } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((safe_snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (safe_snoise(p) + offset) * pwr; + value += rmd * weight * signal; } return value; @@ -609,13 +618,12 @@ float noise_musgrave_hybrid_multi_fractal_4d( { vector4 p = co; float pwHL = pow(lacunarity, -H); - float pwr = pwHL; - float value = safe_snoise(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001) && (i < (int)octaves); i++) { if (weight > 1.0) { weight = 1.0; } @@ -628,8 +636,12 @@ float noise_musgrave_hybrid_multi_fractal_4d( } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((safe_snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (safe_snoise(p) + offset) * pwr; + value += rmd * weight * signal; } return value; diff --git a/intern/cycles/kernel/svm/musgrave.h b/intern/cycles/kernel/svm/musgrave.h index 521c96d9f37..e88da8a17f7 100644 --- a/intern/cycles/kernel/svm/musgrave.h +++ b/intern/cycles/kernel/svm/musgrave.h @@ -119,13 +119,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_1d( { float p = co; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; - float value = snoise_1d(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0f; + float value = 0.0f; + float weight = 1.0f; - for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -138,8 +137,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_1d( } float rmd = octaves - floorf(octaves); - if (rmd != 0.0f) { - value += rmd * ((snoise_1d(p) + offset) * pwr); + if ((rmd != 0.0f) && (weight > 0.001f)) { + if (weight > 1.0f) { + weight = 1.0f; + } + float signal = (snoise_1d(p) + offset) * pwr; + value += rmd * weight * signal; } return value; @@ -290,13 +293,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_2d( { float2 p = co; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; - float value = snoise_2d(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0f; + float value = 0.0f; + float weight = 1.0f; - for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -309,8 +311,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_2d( } float rmd = octaves - floorf(octaves); - if (rmd != 0.0f) { - value += rmd * ((snoise_2d(p) + offset) * pwr); + if ((rmd != 0.0f) && (weight > 0.001f)) { + if (weight > 1.0f) { + weight = 1.0f; + } + float signal = (snoise_2d(p) + offset) * pwr; + value += rmd * weight * signal; } return value; @@ -461,13 +467,13 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_3d( { float3 p = co; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; - float value = snoise_3d(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0f; + float value = 0.0f; + float weight = 1.0f; + - for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -480,8 +486,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_3d( } float rmd = octaves - floorf(octaves); - if (rmd != 0.0f) { - value += rmd * ((snoise_3d(p) + offset) * pwr); + if ((rmd != 0.0f) && (weight > 0.001f)){ + if (weight > 1.0f) { + weight = 1.0f; + } + float signal = (snoise_3d(p) + offset) * pwr; + value += rmd * weight * signal; } return value; @@ -632,13 +642,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_4d( { float4 p = co; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; - float value = snoise_4d(p) + offset; - float weight = gain * value; - p *= lacunarity; + float pwr = 1.0f; + float value = 0.0f; + float weight = 1.0f; - for (int i = 1; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < float_to_int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -651,8 +660,12 @@ ccl_device_noinline_cpu float noise_musgrave_hybrid_multi_fractal_4d( } float rmd = octaves - floorf(octaves); - if (rmd != 0.0f) { - value += rmd * ((snoise_4d(p) + offset) * pwr); + if ((rmd != 0.0f) && (weight > 0.001f)) { + if (weight > 1.0f) { + weight = 1.0f; + } + float signal = (snoise_4d(p) + offset) * pwr; + value += rmd * weight * signal; } return value; |