Beispiel #1
0
    private void ExecuteJob(Vector3[] vertices)
    {
        var jobHandles  = new List <JobHandle>();
        var vertexArray = new NativeArray <Vector3>(vertices, Allocator.TempJob);

        for (int i = 0; i < waterProfile.wavesAttributes.Count; i++)
        {
            var job = new NoiseJob
            {
                v             = vertexArray,
                nType         = waterProfile.wavesAttributes[i].noiseType,
                curPos        = transform.position,
                waveScale     = waterProfile.wavesAttributes[i].waveScale,
                waveSpeed     = waterProfile.wavesAttributes[i].waveSpeed,
                waveIntensity = waterProfile.wavesAttributes[i].waveIntensity,
                heightOffset  = waterProfile.wavesAttributes[i].heightOffset,
                t             = Time.timeSinceLevelLoad
            };

            if (i == 0)
            {
                jobHandles.Add(job.Schedule(vertices.Length, 250));
            }
            else
            {
                jobHandles.Add(job.Schedule(vertices.Length, 250, jobHandles[i - 1]));
            }
        }
        jobHandles.Last().Complete();

        vertexArray.CopyTo(vertices);
        vertexArray.Dispose();
    }
Beispiel #2
0
 private void Update()
 {
     if (useJobs)
     {
         JobHandle handle = default(JobHandle);
         for (int i = 0; i < layers.Length; i++)
         {
             var layer = layers[i];
             var job   = new NoiseJob()
             {
                 vertices = verticesNative,
                 layer    = layer,
                 t        = Time.time,
                 add      = i > 0
             };
             if (i == 0)
             {
                 handle = job.Schedule(vertices.Length, vertices.Length / 6);
             }
             else
             {
                 handle = job.Schedule(vertices.Length, vertices.Length / 6, handle);
             }
         }
         handle.Complete();
         verticesNative.CopyTo(vertices);
     }
     else
     {
         var t = Time.time;
         for (int i = 0; i < layers.Length; i++)
         {
             var layer  = layers[i];
             var vCount = vertices.Length;
             for (int j = 0; j < vCount; j++)
             {
                 var vertex = vertices[j];
                 var noise  = Mathf.PerlinNoise((vertex.x * layer.frequency) + t, (vertex.z * layer.frequency) + t) * layer.waveSize;
                 if (i > 0)
                 {
                     vertex.y += noise;
                 }
                 else
                 {
                     vertex.y = noise;
                 }
                 vertices[j] = vertex;
             }
         }
     }
     mesh.vertices = vertices;
     mesh.RecalculateNormals();
 }
    // Update is called once per frame
    void Update()
    {
        tt += prefab.GetComponent <NoiseEffect>().speed *Time.deltaTime;
        var job = new NoiseJob()
        {
            t       = tt
            , scale = prefab.GetComponent <NoiseEffect>().scale
        };

        jh = job.Schedule(transforms);
    }
    public static NativeArray <float> CreateNoiseMap(uint seed, int mapSize, NoiseSettings[] noiseList)
    {
        NativeArray <float> noiseMap = new NativeArray <float>(mapSize * mapSize, Allocator.TempJob);

        Unity.Mathematics.Random generator = new Unity.Mathematics.Random(seed);

        float2 viewPoint = float2(generator.NextFloat(0, 999999), generator.NextFloat(0, 999999));
        float2 offset    = float2(-mapSize / 2, -mapSize / 2);

        int n = noiseList.Length;

        JobHandle[] jobHandles = new JobHandle[n];

        for (int i = 0; i < n; i++)
        {
            NoiseSettings noise    = noiseList[i];
            NoiseJob      noiseJob = new NoiseJob()
            {
                noiseMap       = noiseMap,
                mapSize        = mapSize,
                noiseType      = noise.type,
                noiseOperation = noise.operation,
                scale          = noise.scale,
                viewPoint      = viewPoint,
                offset         = offset
            };

            if (i == 0)
            {
                jobHandles[i] = noiseJob.Schedule(noiseMap.Length, 64);
            }
            else
            {
                jobHandles[i] = noiseJob.Schedule(noiseMap.Length, 64, jobHandles[i - 1]);
            }
        }

        jobHandles[n - 1].Complete();

        return(noiseMap);
    }
Beispiel #5
0
    void Update()
    {
        var job = new NoiseJob {
            type   = _noiseType,
            scale  = _frequency / kResolution,
            offset = CalculateOffset(),
            pixels = _pixels
        };

        job.Schedule(_pixels.Length, 64).Complete();

        _texture.LoadRawTextureData(_pixels);
        _texture.Apply();
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var nj = new NoiseJob()
        {
            dt = Time.deltaTime
            ,
            noiseScale = fb.noiseScale
            ,
            lower = fb.lower
            ,
            upper = fb.upper
            ,
            offset = this.offset
        };

        offset += Time.deltaTime * fb.speed;
        return(nj.Schedule(this, inputDeps));
    }
Beispiel #7
0
    void Update()
    {
        var job = new NoiseJob {
            periodic   = _periodic,
            derivative = _derivative,
            rotation   = _rotation,
            frequency  = _frequency,
            period     = _period,
            offset     = _offset,
            time       = Time.time,
            pixels     = _pixels
        };

        job.Schedule(_pixels.Length, 64).Complete();

        _texture.LoadRawTextureData(_pixels);
        _texture.Apply();
    }
Beispiel #8
0
        public void ComputeNoise(Octree node)
        {
            int size = (int)node.bounds.size.x;
            //size = 2;

            NativeArray <float4> result = new NativeArray <float4>(size * size * size, Allocator.TempJob);

            NoiseJob jobData = new NoiseJob();

            jobData.size       = size;
            jobData.noiseScale = 10f;
            jobData.minCorner  = node.bounds.min;
            jobData.noiseData  = result;

            JobHandle handle = jobData.Schedule();

            handle.Complete();
            //Debug.Log(string.Join(",", result.ToArray()));
            Debug.Log(result.Length);
            result.Dispose();
        }
    public void Generate(float3 pos)
    {
        noiseJob.Complete();
        this.pos = pos;
        matrix   = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one);
        myMat.SetMatrix("model", matrix);
        myMat.SetBuffer("indices", computeInstance.GetIndexBuffer());
        myMat.SetBuffer("vertices", computeInstance.GetVertexBuffer());
        var noise = new NoiseJob()
        {
            noiseMap     = noiseMap,
            surfaceLevel = 50f,
            freq         = 0.01f,
            ampl         = 1.5f,
            oct          = 6,
            offset       = pos,
            size         = mapSize + 1,
            seed         = 0
        };

        noiseJob   = noise.Schedule((mapSize + 1) * (mapSize + 1) * (mapSize + 1), 64);
        generating = true;
    }