示例#1
0
        public static Quaternion Rotation(uint seed, uint data)
        {
            // James Arvo's classic approach
            var v   = Direction(seed, data);
            var phi = XXHash.Float(seed, data + 0x20000000, 0, TAU);
            var q1  = Quaternion.AngleAxis(phi, Vector3.forward);
            var q2  = Quaternion.FromToRotation(Vector3.forward, v);

            return(q1 * q2);
        }
示例#2
0
        public static Vector3 Direction(uint seed, uint data)
        {
            // http://corysimon.github.io/articles/uniformdistn-on-sphere/
            var theta   = XXHash.Float(seed, data, 0, TAU);
            var phi     = Mathf.Acos(XXHash.Float(seed, data + 0x10000000, -1, 1));
            var sin_phi = Mathf.Sin(phi);
            var x       = sin_phi * Mathf.Cos(theta);
            var y       = sin_phi * Mathf.Sin(theta);
            var z       = Mathf.Cos(phi);

            return(new Vector3(x, y, z));
        }
示例#3
0
        Vector3 GetOutput(Flow flow)
        {
            var seed = flow.GetValue <uint>(Seed);
            var data = flow.GetValue <uint>(Data);
            var min  = flow.GetValue <Vector3>(Min);
            var max  = flow.GetValue <Vector3>(Max);
            var x    = XXHash.Float(seed, data + 0x00000000, min.x, max.x);
            var y    = XXHash.Float(seed, data + 0x10000000, min.y, max.y);
            var z    = XXHash.Float(seed, data + 0x20000000, min.z, max.z);

            return(new Vector3(x, y, z));
        }
示例#4
0
        ControlOutput OnEnter(Flow flow)
        {
            var data = flow.stack.GetElementData <Data>(this);

            var frequency = flow.GetValue <float>(Frequency);
            var octave    = flow.GetValue <uint>(Octave);
            var amplitude = flow.GetValue <float>(Amplitude);
            var seed      = flow.GetValue <uint>(Seed);

            var time = data.Time + Time.deltaTime * frequency;
            var n    = NoiseUtil.Fbm(XXHash.Float(seed, 0u, -1000, 1000), time, octave);

            data.Time  = time;
            data.Value = n * amplitude / 0.75f;

            return(Exit);
        }
示例#5
0
        ControlOutput OnEnter(Flow flow)
        {
            var data = flow.stack.GetElementData <Data>(this);

            var frequency = flow.GetValue <float>(Frequency);
            var octave    = flow.GetValue <uint>(Octave);
            var angles    = flow.GetValue <Vector3>(Angles);
            var seed      = flow.GetValue <uint>(Seed);

            var time = data.Time + Time.deltaTime * frequency;

            var nx = NoiseUtil.Fbm(XXHash.Float(seed, 0u, -1000, 1000), time, octave);
            var ny = NoiseUtil.Fbm(XXHash.Float(seed, 1u, -1000, 1000), time, octave);
            var nz = NoiseUtil.Fbm(XXHash.Float(seed, 2u, -1000, 1000), time, octave);
            var nv = Vector3.Scale(new Vector3(nx, ny, nz), angles) / 0.75f;

            data.Time  = time;
            data.Value = Quaternion.Euler(nv);

            return(Exit);
        }
示例#6
0
 float GetOutput(Flow flow)
 => XXHash.Float(flow.GetValue <uint>(Seed), flow.GetValue <uint>(Data),
                 flow.GetValue <float>(Min), flow.GetValue <float>(Max));