#Optimization of a job

1 messages · Page 1 of 1 (latest)

cosmic badger
#

I have this job made out of diferent variations, I would like to find a better way to do this, since I find it pretty ugly.

#

let's see

#

To explain a bit, the jobs array contains all of the variaitons of the job, to shcedule them i do something like this

#
        NoiseSettings moistureSettings = MoistureMap.settings;
        JobHandle MoistureValues = Displace.jobs[(int)moistureSettings.noiseType](vertices, moisture, 
            moistureSettings, MoistureMapCurve, 
            config.Offset, config.MeshSettings, dependancy);
#

Inside the execute, there's the GetFractalNoise, which looks like this:

#
[MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static float4 GetFractalNoise<N>(float4x3 position, int seed, float4 persistance, NoiseSettings settings, SampledAnimationCurve curve) where N : struct, INoise{
        var hash = SmallXXHash4.Seed(seed);
        int frequency = 1;
        float4 amplitude = 1f, amplitudeSum = 0f;
        float4 sum = default;
        
        float4 dotProduct = 0;
        position = settings.Matrix.TransformVectors(position);
        for (int o = 0; o < settings.octaves; o++) {
            float4 noiseValue = default(N).GetNoise4(position, hash+o, frequency, settings.SmoothVoronoi);
            sum += noiseValue*amplitude;
            frequency *= settings.lacunarity;
            amplitude *= persistance;
            amplitudeSum += pow(settings.persistence, o);
        }    

        float4 value = lerp(settings.minmaxValue.x, settings.minmaxValue.y,curve.EvaluateLerp(sum/amplitudeSum));
        
        return value;
    }
#

And then there's the default(N).GetNoise, which, for example looks like this:

#
public struct Perlin2D<G> : INoise where G : struct, IGradient {

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public float4 GetNoise4 (float4x3 positions, SmallXXHash4 hash, float frequency, float smoothness) {
            LatticeSpan4
                x = GetLatticeSpan4(positions.c0, frequency),
                z = GetLatticeSpan4(positions.c2, frequency);

            SmallXXHash4 h0 = hash.Eat(x.p0);
            SmallXXHash4 h1 = hash.Eat(x.p1);
        
            var g = default(G);
            float4
                a = g.Evaluate(h0.Eat(z.p0), x.g0, z.g0),
                b = g.Evaluate(h0.Eat(z.p1), x.g0, z.g1),
                c = g.Evaluate(h1.Eat(z.p0), x.g1, z.g0),
                d = g.Evaluate(h1.Eat(z.p1), x.g1, z.g1);
            
            return (lerp(lerp(a, b, z.t), lerp(c, d, z.t), x.t)+1f)/2f;
        }
    }
#

And finally, (yeah a long way)

#

We have the diferent gradients

#
    public struct Perlin : IGradient {

        public float4 Evaluate (SmallXXHash4 hash, float4 x, float4 y) =>
            BaseGradients.Square(hash, x, y) * (2f / 0.53528f);
    }
#

and

#
        public static float4 Square (SmallXXHash4 hash, float4 x, float4 y) {
            float4x2 v = SquareVectors(hash);
            return v.c0 * x + v.c1 * y;
        }
#

Im not sure how to rework all of this so that its simpler

#

Maybe you have an idea @lucid epoch

#

This all comes mainly from CatLikeCoding

lucid epoch
#

not really sure tbh

#

doesn't look /that/ bad