diff --git a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl index bc59f115cce..7738902f529 100644 --- a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl @@ -35,7 +35,7 @@ float noise(point p, string basis, float distortion, float detail) p += r; } - fac = noise_turbulence(p, basis, (int)detail, hard); + fac = noise_turbulence(p, basis, detail, hard); return fac; diff --git a/intern/cycles/kernel/osl/nodes/node_texture.h b/intern/cycles/kernel/osl/nodes/node_texture.h index d2dbd6db8b3..5f3d4d9f3bf 100644 --- a/intern/cycles/kernel/osl/nodes/node_texture.h +++ b/intern/cycles/kernel/osl/nodes/node_texture.h @@ -212,14 +212,17 @@ float noise_wave(string wave, float a) /* Turbulence */ -float noise_turbulence(point p, string basis, int octaves, int hard) +float noise_turbulence(point p, string basis, float octaves, int hard) { float fscale = 1.0; float amp = 1.0; float sum = 0.0; - int i; + int i, n; + + octaves = clamp(octaves, 0.0, 16.0); + n = (int)octaves; - for (i = 0; i <= octaves; i++) { + for (i = 0; i <= n; i++) { float t = noise_basis(fscale * p, basis); if (hard) @@ -229,10 +232,26 @@ float noise_turbulence(point p, string basis, int octaves, int hard) amp *= 0.5; fscale *= 2.0; } + + float rmd = octaves - floor(octaves); - sum *= ((float)(1 << octaves) / (float)((1 << (octaves + 1)) - 1)); + if(rmd != 0.0) { + float t = noise_basis(fscale*p, basis); - return sum; + 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 */ diff --git a/intern/cycles/kernel/osl/nodes/node_wave_texture.osl b/intern/cycles/kernel/osl/nodes/node_wave_texture.osl index 83f55631f98..693f09ae24c 100644 --- a/intern/cycles/kernel/osl/nodes/node_wave_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_wave_texture.osl @@ -38,7 +38,7 @@ float wave(point p, float scale, string type, float detail, float distortion, fl } if(distortion != 0.0) { - n = n +(distortion * noise_turbulence(p*dscale, "Perlin", (int)detail, 0)); + n = n +(distortion * noise_turbulence(p*dscale, "Perlin", detail, 0)); } result = noise_wave("Sine", n);