From 763cafc2b101d3258cb62b9a966b6d7e7629eb85 Mon Sep 17 00:00:00 2001 From: Luis Pereira Date: Fri, 26 Aug 2022 15:30:59 +0200 Subject: 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 --- .../material/gpu_shader_material_tex_musgrave.glsl | 68 +++++++++++++--------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'source/blender/gpu/shaders') 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 961fe23e67e..7171c5f2b36 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 @@ -153,13 +153,12 @@ void node_tex_musgrave_hybrid_multi_fractal_1d(vec3 co, 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; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0) { weight = 1.0; } @@ -172,8 +171,12 @@ void node_tex_musgrave_hybrid_multi_fractal_1d(vec3 co, } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001f)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (snoise(p) + offset) * pwr; + value += rmd * weight * signal; } fac = value; @@ -375,13 +378,12 @@ void node_tex_musgrave_hybrid_multi_fractal_2d(vec3 co, 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; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0) { weight = 1.0; } @@ -394,8 +396,12 @@ void node_tex_musgrave_hybrid_multi_fractal_2d(vec3 co, } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001f)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (snoise(p) + offset) * pwr; + value += rmd * weight * signal; } fac = value; @@ -597,13 +603,12 @@ void node_tex_musgrave_hybrid_multi_fractal_3d(vec3 co, 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; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0) { weight = 1.0; } @@ -616,8 +621,12 @@ void node_tex_musgrave_hybrid_multi_fractal_3d(vec3 co, } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001f)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (snoise(p) + offset) * pwr; + value += rmd * weight * signal; } fac = value; @@ -819,13 +828,12 @@ void node_tex_musgrave_hybrid_multi_fractal_4d(vec3 co, 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; + float pwr = 1.0; + float value = 0.0; + float weight = 1.0; - for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0) { weight = 1.0; } @@ -838,8 +846,12 @@ void node_tex_musgrave_hybrid_multi_fractal_4d(vec3 co, } float rmd = octaves - floor(octaves); - if (rmd != 0.0) { - value += rmd * ((snoise(p) + offset) * pwr); + if ((rmd != 0.0) && (weight > 0.001f)) { + if (weight > 1.0) { + weight = 1.0; + } + float signal = (snoise(p) + offset) * pwr; + value += rmd * weight * signal; } fac = value; -- cgit v1.2.3