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:
authorBrecht Van Lommel <brecht@blender.org>2021-11-02 20:27:54 +0300
committerBrecht Van Lommel <brecht@blender.org>2021-11-02 20:56:25 +0300
commit48e2a15160d276c8080cd8d4f6dc0ba752dbb410 (patch)
tree5552f66d7fa217a12bbdd4fbe0c1e9691c4fb36e /source/blender/blenlib/intern/noise.cc
parent978f2cb900b75110a3bc9dbcec9d4aeae5df4565 (diff)
Fix T77681, T92634: noise texture artifacts with high detail
We run into float precision issues here, clamp the number of octaves to one less, which has little to no visual difference. This was empirically determined to work up to 16 before, but with additional inputs like roughness only 15 appears to work. Also adds misisng clamp for the geometry nodes implementation.
Diffstat (limited to 'source/blender/blenlib/intern/noise.cc')
-rw-r--r--source/blender/blenlib/intern/noise.cc94
1 files changed, 72 insertions, 22 deletions
diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc
index bc78ded63a0..959385bff31 100644
--- a/source/blender/blenlib/intern/noise.cc
+++ b/source/blender/blenlib/intern/noise.cc
@@ -582,7 +582,7 @@ template<typename T> float perlin_fractal_template(T position, float octaves, fl
float amp = 1.0f;
float maxamp = 0.0f;
float sum = 0.0f;
- octaves = CLAMPIS(octaves, 0.0f, 16.0f);
+ octaves = CLAMPIS(octaves, 0.0f, 15.0f);
int n = static_cast<int>(octaves);
for (int i = 0; i <= n; i++) {
float t = perlin(fscale * position);
@@ -771,12 +771,16 @@ float3 perlin_float3_fractal_distorted(float4 position,
* from "Texturing and Modelling: A procedural approach"
*/
-float musgrave_fBm(const float co, const float H, const float lacunarity, const float octaves)
+float musgrave_fBm(const float co,
+ const float H,
+ const float lacunarity,
+ const float octaves_unclamped)
{
float p = co;
float value = 0.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
for (int i = 0; i < (int)octaves; i++) {
value += perlin_signed(p) * pwr;
@@ -802,12 +806,13 @@ float musgrave_fBm(const float co, const float H, const float lacunarity, const
float musgrave_multi_fractal(const float co,
const float H,
const float lacunarity,
- const float octaves)
+ const float octaves_unclamped)
{
float p = co;
float value = 1.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * perlin_signed(p) + 1.0f);
@@ -831,12 +836,16 @@ float musgrave_multi_fractal(const float co,
* offset: raises the terrain from `sea level'
*/
-float musgrave_hetero_terrain(
- const float co, const float H, const float lacunarity, const float octaves, const float offset)
+float musgrave_hetero_terrain(const float co,
+ const float H,
+ const float lacunarity,
+ const float octaves_unclamped,
+ const float offset)
{
float p = co;
const float pwHL = powf(lacunarity, -H);
float pwr = pwHL;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
/* first unscaled octave of function; later octaves are scaled */
float value = offset + perlin_signed(p);
@@ -869,7 +878,7 @@ float musgrave_hetero_terrain(
float musgrave_hybrid_multi_fractal(const float co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -881,6 +890,8 @@ float musgrave_hybrid_multi_fractal(const float co,
float weight = gain * value;
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; (weight > 0.001f) && (i < (int)octaves); i++) {
if (weight > 1.0f) {
weight = 1.0f;
@@ -912,7 +923,7 @@ float musgrave_hybrid_multi_fractal(const float co,
float musgrave_ridged_multi_fractal(const float co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -925,6 +936,8 @@ float musgrave_ridged_multi_fractal(const float co,
float value = signal;
float weight = 1.0f;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = CLAMPIS(signal * gain, 0.0f, 1.0f);
@@ -947,12 +960,16 @@ float musgrave_ridged_multi_fractal(const float co,
* from "Texturing and Modelling: A procedural approach"
*/
-float musgrave_fBm(const float2 co, const float H, const float lacunarity, const float octaves)
+float musgrave_fBm(const float2 co,
+ const float H,
+ const float lacunarity,
+ const float octaves_unclamped)
{
float2 p = co;
float value = 0.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
for (int i = 0; i < (int)octaves; i++) {
value += perlin_signed(p) * pwr;
@@ -978,12 +995,13 @@ float musgrave_fBm(const float2 co, const float H, const float lacunarity, const
float musgrave_multi_fractal(const float2 co,
const float H,
const float lacunarity,
- const float octaves)
+ const float octaves_unclamped)
{
float2 p = co;
float value = 1.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * perlin_signed(p) + 1.0f);
@@ -1010,7 +1028,7 @@ float musgrave_multi_fractal(const float2 co,
float musgrave_hetero_terrain(const float2 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset)
{
float2 p = co;
@@ -1021,6 +1039,8 @@ float musgrave_hetero_terrain(const float2 co,
float value = offset + perlin_signed(p);
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
float increment = (perlin_signed(p) + offset) * pwr * value;
value += increment;
@@ -1048,7 +1068,7 @@ float musgrave_hetero_terrain(const float2 co,
float musgrave_hybrid_multi_fractal(const float2 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -1060,6 +1080,8 @@ float musgrave_hybrid_multi_fractal(const float2 co,
float weight = gain * value;
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; (weight > 0.001f) && (i < (int)octaves); i++) {
if (weight > 1.0f) {
weight = 1.0f;
@@ -1091,7 +1113,7 @@ float musgrave_hybrid_multi_fractal(const float2 co,
float musgrave_ridged_multi_fractal(const float2 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -1104,6 +1126,8 @@ float musgrave_ridged_multi_fractal(const float2 co,
float value = signal;
float weight = 1.0f;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = CLAMPIS(signal * gain, 0.0f, 1.0f);
@@ -1126,13 +1150,18 @@ float musgrave_ridged_multi_fractal(const float2 co,
* from "Texturing and Modelling: A procedural approach"
*/
-float musgrave_fBm(const float3 co, const float H, const float lacunarity, const float octaves)
+float musgrave_fBm(const float3 co,
+ const float H,
+ const float lacunarity,
+ const float octaves_unclamped)
{
float3 p = co;
float value = 0.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 0; i < (int)octaves; i++) {
value += perlin_signed(p) * pwr;
pwr *= pwHL;
@@ -1157,13 +1186,15 @@ float musgrave_fBm(const float3 co, const float H, const float lacunarity, const
float musgrave_multi_fractal(const float3 co,
const float H,
const float lacunarity,
- const float octaves)
+ const float octaves_unclamped)
{
float3 p = co;
float value = 1.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * perlin_signed(p) + 1.0f);
pwr *= pwHL;
@@ -1189,7 +1220,7 @@ float musgrave_multi_fractal(const float3 co,
float musgrave_hetero_terrain(const float3 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset)
{
float3 p = co;
@@ -1200,6 +1231,8 @@ float musgrave_hetero_terrain(const float3 co,
float value = offset + perlin_signed(p);
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
float increment = (perlin_signed(p) + offset) * pwr * value;
value += increment;
@@ -1227,7 +1260,7 @@ float musgrave_hetero_terrain(const float3 co,
float musgrave_hybrid_multi_fractal(const float3 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -1239,6 +1272,8 @@ float musgrave_hybrid_multi_fractal(const float3 co,
float weight = gain * value;
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; (weight > 0.001f) && (i < (int)octaves); i++) {
if (weight > 1.0f) {
weight = 1.0f;
@@ -1270,7 +1305,7 @@ float musgrave_hybrid_multi_fractal(const float3 co,
float musgrave_ridged_multi_fractal(const float3 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -1283,6 +1318,8 @@ float musgrave_ridged_multi_fractal(const float3 co,
float value = signal;
float weight = 1.0f;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = CLAMPIS(signal * gain, 0.0f, 1.0f);
@@ -1305,13 +1342,18 @@ float musgrave_ridged_multi_fractal(const float3 co,
* from "Texturing and Modelling: A procedural approach"
*/
-float musgrave_fBm(const float4 co, const float H, const float lacunarity, const float octaves)
+float musgrave_fBm(const float4 co,
+ const float H,
+ const float lacunarity,
+ const float octaves_unclamped)
{
float4 p = co;
float value = 0.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 0; i < (int)octaves; i++) {
value += perlin_signed(p) * pwr;
pwr *= pwHL;
@@ -1336,13 +1378,15 @@ float musgrave_fBm(const float4 co, const float H, const float lacunarity, const
float musgrave_multi_fractal(const float4 co,
const float H,
const float lacunarity,
- const float octaves)
+ const float octaves_unclamped)
{
float4 p = co;
float value = 1.0f;
float pwr = 1.0f;
const float pwHL = powf(lacunarity, -H);
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 0; i < (int)octaves; i++) {
value *= (pwr * perlin_signed(p) + 1.0f);
pwr *= pwHL;
@@ -1368,7 +1412,7 @@ float musgrave_multi_fractal(const float4 co,
float musgrave_hetero_terrain(const float4 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset)
{
float4 p = co;
@@ -1379,6 +1423,8 @@ float musgrave_hetero_terrain(const float4 co,
float value = offset + perlin_signed(p);
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
float increment = (perlin_signed(p) + offset) * pwr * value;
value += increment;
@@ -1406,7 +1452,7 @@ float musgrave_hetero_terrain(const float4 co,
float musgrave_hybrid_multi_fractal(const float4 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -1418,6 +1464,8 @@ float musgrave_hybrid_multi_fractal(const float4 co,
float weight = gain * value;
p *= lacunarity;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; (weight > 0.001f) && (i < (int)octaves); i++) {
if (weight > 1.0f) {
weight = 1.0f;
@@ -1449,7 +1497,7 @@ float musgrave_hybrid_multi_fractal(const float4 co,
float musgrave_ridged_multi_fractal(const float4 co,
const float H,
const float lacunarity,
- const float octaves,
+ const float octaves_unclamped,
const float offset,
const float gain)
{
@@ -1462,6 +1510,8 @@ float musgrave_ridged_multi_fractal(const float4 co,
float value = signal;
float weight = 1.0f;
+ const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f);
+
for (int i = 1; i < (int)octaves; i++) {
p *= lacunarity;
weight = CLAMPIS(signal * gain, 0.0f, 1.0f);