# Any way to use an external noise function in a job struct?

Discussion in 'Data Oriented Technology Stack' started by TheGameNewBie, Nov 20, 2020.

1. ### TheGameNewBie

Joined:
Jul 27, 2017
Posts:
86
I'm recently starting to look into the job system.
I wanted to use jobs to create a mesh from noise.
Modify the vertices array in the job, then copy those vertices to the mesh outside the job.
The problem is, I'm using an external noise Library (Libnoise). It has it's own 'GetValue' function and I cannot use that in the job.
Unity.Mathematics does have a noise function but it does not meet my needs.
How am I supposed to do this?

2. ### brunocoimbra

Joined:
Sep 2, 2015
Posts:
557
TheGameNewBie likes this.

Joined:
Sep 10, 2017
Posts:
51
4. ### iamarugin

Joined:
Dec 17, 2014
Posts:
569
TheGameNewBie and florianhanke like this.
5. ### TheGameNewBie

Joined:
Jul 27, 2017
Posts:
86
That was very helpful. Thanks. I used it as a base to convert the noise functions into static ones.

Yep, Ended up doing just that,, not in a very elegant way, But it works for me.

Thanks, will take a look into it.

Here's the modified function if anyone wants to take a look at it, It's pretty much the same as the one in the library mentioned by @Baggers_
(You still need to install the Libnoise library for this to work)
Code (CSharp):
1. public static double GetRidgedMultiFractalValue (double x, double y, double z,  double _frequency, double _lacunarity, int _octaveCount, int _seed)
2.     {
3.         double exponent = 1.0;
4.         double gain = 2.0;
5.         double offset = 1.0;
6.
7.         var value = 0.0;
8.         var weight = 1.0;
9.
10.         x *= _frequency;
11.         y *= _frequency;
12.         z *= _frequency;
13.         var f = 1.0;
14.
15.         for (var i = 0; i < _octaveCount; i++)
16.         {
17.             var nx = LibNoise.Utils.MakeInt32Range(x);
18.             var ny = LibNoise.Utils.MakeInt32Range(y);
19.             var nz = LibNoise.Utils.MakeInt32Range(z);
20.             int seed = _seed + i;
21.             var signal = LibNoise.Utils.GradientCoherentNoise3D(nx, ny, nz, seed, LibNoise.QualityMode.High);
22.             signal = System.Math.Abs(signal);
23.             signal = offset - signal;
24.             signal *= signal;
25.             signal *= weight;
26.             weight = signal * gain;
27.             weight = Mathf.Clamp((float)weight, 0, 1);
28.
29.             value += (signal * System.Math.Pow(f, -exponent));
30.             f *= _lacunarity;
31.
32.             x *= _lacunarity;
33.             y *= _lacunarity;
34.             z *= _lacunarity;
35.         }
36.         return (value * 1.25) - 1.0;
37.     }
Thanks for the help.

Baggers_ likes this. unityunity