#Getting correct index inside IJobFor for a flattened array

1 messages · Page 1 of 1 (latest)

idle bone
#

I'm trying to do some simple noise applied to a mesh inside of an IJobFor, but I'm getting a seam and I assume its due to incorrect calculation of x and/or y and the index. Any tips?

public struct HeightmapNoiseForJob : IJobFor
{
      public TerrainData       Data;
      public NativeArray<HeightMap> HeightMap;

      public void Execute(int index)
      {
            var x          = (int)math.floor(index % Data.Size);
            var y          = (int)math.floor(index / Data.Size);
            var offset     = Data.NoiseData.Offset;
            var seed       = Data.NoiseData.Seed;
            var noiseScale = Data.NoiseData.Scale;
            if(math.ceil(noiseScale) != noiseScale)
                  noiseScale += 0.0001f;
            var height   = Data.NoiseData.Height;
            var noiseMod = 1;
            var inputX   = x * noiseScale + seed + offset.x;
            var inputY   = y * noiseScale + seed + offset.y;
                
            var value = Mathf.PerlinNoise(inputX, inputY);
            value *= height;
            HeightMap[index] = value;
      }
rancid spear
#

What are the dimensions?

idle bone
#

dimensions are always Data.Size*Data.Size. its only set during baking(for now) so it shouldnt be a factor during runtime

rancid spear
#

Yea just wanted to know

#

Can take a look a bit later today

tropic mirage
#

How are you getting from heightmap to mesh? Maybe check you're using the same unflattening method there

vagrant terrace
#

completely a side note, any reason you're using Mathf.Perlin over the math library noise.pnoise()?

#

second side note

           if(math.ceil(noiseScale) != noiseScale)
                  noiseScale += 0.0001f;```
seems extremely inefficient to do per index
#

anyway i'm not sure about your actual problem, it's very odd

idle bone
#

was just trying to eliminate the mathematics lib as a variable, and yeah should be doing that prior to the job