Unity-Technologies / Unity.Mathematics

The C# math library used in Unity providing vector types and math functions with a shader like syntax
Other
1.38k stars 156 forks source link

3D snoise artifact on x=y=z #71

Open rbnelr opened 5 years ago

rbnelr commented 5 years ago

The "snoise(float3 v)" function has artefacts in a line exactly at x=y=z. This artefact seems to repeat in multiple places (always along the line x=y=z relative to a noise cell maybe?).

This produces obvious artefacts when used in my voxel engine in Unity3D, which currently uses marching cubes to display the isosurface at value 0 of the 3d noise.

bug_img01

The relevant code is this: valueForMarchingCubes = Unity.Mathematics.noise.snoise(pos3d / 100f) + 0.42f;

A reproduceable Unity3D script:

using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;

public class NoiseBugRepro : MonoBehaviour {
    // Start is called before the first frame update
    void Start () {
        string output = "";
        for (int i = 0; i<20; ++i) {
            float x = lerp(1.8f, 2.2f, i / 20f);
            float3 pos = float3(x, 2f, 2f);

            float val = noise.snoise(pos / 20f);

            output += string.Format("noise.snoise({0:F2}, {1:F2}, {2:F2}) -> {3:F6}\n", pos.x, pos.y, pos.z, val);
        }

        Debug.Log(output);
    }
}

Output that shows the artefact when exactly on the x=y=z line:

noise.snoise(1.80, 2.00, 2.00) -> -0.373848
noise.snoise(1.82, 2.00, 2.00) -> -0.372971
noise.snoise(1.84, 2.00, 2.00) -> -0.372090
noise.snoise(1.86, 2.00, 2.00) -> -0.371204
noise.snoise(1.88, 2.00, 2.00) -> -0.370314
noise.snoise(1.90, 2.00, 2.00) -> -0.369420
noise.snoise(1.92, 2.00, 2.00) -> -0.368521
noise.snoise(1.94, 2.00, 2.00) -> -0.367619
noise.snoise(1.96, 2.00, 2.00) -> -0.366712
noise.snoise(1.98, 2.00, 2.00) -> -0.365801
noise.snoise(2.00, 2.00, 2.00) -> -0.571772
noise.snoise(2.02, 2.00, 2.00) -> -0.363966
noise.snoise(2.04, 2.00, 2.00) -> -0.363043
noise.snoise(2.06, 2.00, 2.00) -> -0.362115
noise.snoise(2.08, 2.00, 2.00) -> -0.361184
noise.snoise(2.10, 2.00, 2.00) -> -0.360248
noise.snoise(2.12, 2.00, 2.00) -> -0.359309
noise.snoise(2.14, 2.00, 2.00) -> -0.358365
noise.snoise(2.16, 2.00, 2.00) -> -0.357418
noise.snoise(2.18, 2.00, 2.00) -> -0.356467
alexis-coulombe commented 4 years ago

We really need a fix for this one. Or an equivalent without artifacts.