Noise() public static method

public static Noise ( float x, float y ) : float
x float
y float
return float
Exemplo n.º 1
0
    public Vector3[] CreateTerrain(float seaLevel)
    {
        noise = new Perlin();
        Mesh mesh = transform.GetComponent <MeshFilter>().mesh;

        if (baseVertices == null)         // not sure about the scope of this if. potentional bug
        {
            baseVertices = mesh.vertices;
        }

        Vector3[] vertices = new Vector3[baseVertices.Length];

        for (var i = 0; i < vertices.Length; i++)
        {
            Vector3 vertex = baseVertices[i];

            vertex.x += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;
            vertex.y += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;
            vertex.z += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;

            // flatten out sea
            if (vertex.magnitude < seaLevel)
            {
                vertex = seaLevel * vertex.normalized;
            }
            vertices[i] = vertex;
        }
        return(vertices);
    }
Exemplo n.º 2
0
    private void ShootLightning()
    {
        float timex = Time.time * speed * 0.1365143f;
        float timey = Time.time * speed * 1.21688f;
        float timez = Time.time * speed * 2.5564f;

        for (int i = 0; i < particles.Length; i++)
        {
            Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
            Vector3 offset   = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                           noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                           noise.Noise(timez + position.x, timez + position.y, timez + position.z));
            position += (offset * scale * ((float)i * oneOverZigs));

            particles[i].position = position;
            particles[i].color    = Color.white;
            particles[i].energy   = 1f;
        }

        particleEmitter.particles = particles;

        if (particleEmitter.particleCount >= 2)
        {
            if (startLight)
            {
                startLight.transform.position = particles[0].position;
            }
            if (endLight)
            {
                endLight.transform.position = particles[particles.Length - 1].position;
            }
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        Mesh _mesh = GetComponent <MeshFilter>().mesh;

        if (Base == null)
        {
            Base = new Vector3[_mesh.vertexCount];
            Base = _mesh.vertices;
        }

        Vector3[] Vertices = _mesh.vertices;

        float timeX = Time.time * Velocidad;
        float timeY = Time.time * Velocidad;
        float timeZ = Time.time * Velocidad;

        for (int i = 0; i < Vertices.Length; i++)
        {
            Vector3 Auxiliar = Base[i];

            Auxiliar.x += Perlin_Noise.Noise(timeX + Auxiliar.x, timeX + Auxiliar.y, timeX + Auxiliar.z) * Distorcion;
            Auxiliar.y += Perlin_Noise.Noise(timeY + Auxiliar.x, timeY + Auxiliar.y, timeY + Auxiliar.z) * Distorcion;
            Auxiliar.z += Perlin_Noise.Noise(timeZ + Auxiliar.x, timeZ + Auxiliar.y, timeZ + Auxiliar.z) * Distorcion;

            Vertices[i] = Auxiliar;
        }

        _mesh.vertices = Vertices;
        _mesh.RecalculateNormals();
    }
    public void CrumpleMesh()
    {
        noise = new Perlin();

        if (baseVertices == null)
        {
            baseVertices = mesh.vertices;
        }

        Vector3[] vertices = new Vector3[baseVertices.Length];

        timeX += 0.1365143f;
        timeY += 1.21688f;
        timeZ += 2.5564f;

        for (var i = 0; i < vertices.Length; i++)
        {
            Vector3 vertex = baseVertices [i];

            vertex.x += noise.Noise(timeX + vertex.x, timeX + vertex.y, timeX + vertex.z) * rad;
            vertex.y += noise.Noise(timeY + vertex.x, timeY + vertex.y, timeY + vertex.z) * rad;
            vertex.z += noise.Noise(timeZ + vertex.x, timeZ + vertex.y, timeZ + vertex.z) * rad;

            vertices [i] = vertex;
        }

        mesh.vertices = vertices;
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        mesh.Optimize();
    }
Exemplo n.º 5
0
            public float HybridMultifractal(float x, float y, float offset)
            {
                float weight, signal, remainder, result;

                result = (m_Noise.Noise(x, y) + offset) * m_Exponent[0];
                weight = result;
                x     *= m_Lacunarity;
                y     *= m_Lacunarity;
                int i;

                for (i = 1; i < m_IntOctaves; i++)
                {
                    if (weight > 1.0f)
                    {
                        weight = 1.0f;
                    }
                    signal  = (m_Noise.Noise(x, y) + offset) * m_Exponent[i];
                    result += weight * signal;
                    weight *= signal;
                    x      *= m_Lacunarity;
                    y      *= m_Lacunarity;
                }
                remainder = m_Octaves - m_IntOctaves;
                result   += remainder * m_Noise.Noise(x, y) * m_Exponent[i];

                return(result);
            }
Exemplo n.º 6
0
    public Vector3[] CreateTerrain(float seaLevel)
    {
        noise = new Perlin();
        Mesh mesh = transform.GetComponent<MeshFilter>().mesh;

        if (baseVertices == null) // not sure about the scope of this if. potentional bug
        {
            baseVertices = mesh.vertices;
        }

        Vector3[] vertices = new Vector3[baseVertices.Length];

        for (var i=0;i<vertices.Length;i++)
        {
            Vector3 vertex = baseVertices[i];

            vertex.x += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;
            vertex.y += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;
            vertex.z += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;

            // flatten out sea
            if (vertex.magnitude < seaLevel)
            {
                vertex = seaLevel * vertex.normalized;
            }
            vertices[i] = vertex;

        }
        return vertices;
    }
    void Update()
    {
        var mesh = GetComponent <MeshFilter> ().mesh;

        if (baseVertices == null)
        {
            baseVertices = mesh.vertices;
        }

        var vertices = new Vector3[baseVertices.Length];

        var timex = Time.time * speed + 0.1365143;
        var timey = Time.time * speed + 1.21688;
        var timez = Time.time * speed + 2.5564;

        for (var i = 0; i < vertices.Length; i++)
        {
            var vertex = baseVertices [i];

            vertex.x += noise.Noise((float)timex + vertex.x, (float)timex + vertex.y, (float)timex + vertex.z) * scale;
            vertex.y += noise.Noise((float)timey + vertex.x, (float)timey + vertex.y, (float)timey + vertex.z) * scale;
            vertex.z += noise.Noise((float)timez + vertex.x, (float)timez + vertex.y, (float)timez + vertex.z) * scale;

            vertices [i] = vertex;
        }

        mesh.vertices = vertices;

        if (recalculateNormals)
        {
            mesh.RecalculateNormals();
        }
        mesh.RecalculateBounds();
    }
Exemplo n.º 8
0
    private void DeformMesh()
    {
        float newScale = Random.Range(MinRockSize, MaxRockSize);

        transform.localScale = new Vector3(newScale, newScale, newScale);

        var vertices = new Vector3[baseVertices.Length];

        var timex = Time.time * Speed;
        var timey = Time.time * Speed;
        var timez = Time.time * Speed;

        for (var i = 0; i < vertices.Length; i++)
        {
            var vertex = baseVertices[i];

            vertex.x += noise.Noise(timex + vertex.x, timex + vertex.y, timex + vertex.z) * Scale;
            vertex.y += noise.Noise(timey + vertex.x, timey + vertex.y, timey + vertex.z) * Scale;
            vertex.z += noise.Noise(timez + vertex.x, timez + vertex.y, timez + vertex.z) * Scale;

            vertices[i] = vertex;
        }

        mesh.vertices = vertices;

        if (RecalculateNormals)
        {
            mesh.RecalculateNormals();
        }

        mesh.RecalculateBounds();
        collider.sharedMesh = mesh;
    }
Exemplo n.º 9
0
    void Update()
    {
        int length = particle_system.GetParticles(particles);

        if (noise == null)
        {
            noise = new Perlin();
        }

        float timex = Time.time * speed * 0.1365143f;
        float timey = Time.time * speed * 1.21688f;
        float timez = Time.time * speed * 2.5564f;

        for (int i = 0; i < length; i++)
        {
            Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
            Vector3 offset   = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                           noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                           noise.Noise(timez + position.x, timez + position.y, timez + position.z));
            position += (offset * scale * ((float)i * oneOverZigs));

            particles[i].position = position;
//			particles[i].color = Color.white;
//			particles[i].energy = 1f;
        }

        particle_system.SetParticles(particles, length);
    }
Exemplo n.º 10
0
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.N))
        {
            IsStart = !IsStart;

            GetComponent <ParticleEmitter>().enabled       = IsStart;
            this.GetComponent <ParticleRenderer>().enabled = IsStart;
            if (startLight)
            {
                startLight.enabled = IsStart;
            }
            if (endLight)
            {
                endLight.enabled = IsStart;
            }
        }

        if (!IsStart)
        {
            return;
        }

        if (noise == null)
        {
            noise = new Perlin();
        }

        float timex = Time.time * speed * 0.1365143f;
        float timey = Time.time * speed * 1.21688f;
        float timez = Time.time * speed * 2.5564f;

        for (int i = 0; i < particles.Length; i++)
        {
            Vector3 position = Vector3.Lerp(transform.position, target.position + targetOffset, oneOverZigs * (float)i);

            Vector3 offset = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                         noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                         noise.Noise(timez + position.x, timez + position.y, timez + position.z));
            position += (offset * scale * ((float)i * oneOverZigs));

            particles[i].position = position;
            particles[i].color    = Color.white;
            particles[i].energy   = 1f;
        }

        GetComponent <ParticleEmitter>().particles = particles;

        if (GetComponent <ParticleEmitter>().particleCount >= 2)
        {
            if (startLight)
            {
                startLight.transform.position = particles[0].position;
            }
            if (endLight)
            {
                endLight.transform.position = particles[particles.Length - 1].position;
            }
        }
    }
Exemplo n.º 11
0
    // Deform mesh.
    private void DeformMesh()
    {
        var vertices = new Vector3[baseVertices.Count];

        var timex = Time.time * Speed;
        var timey = Time.time * Speed;
        var timez = Time.time * Speed;

        for (var i = 0; i < vertices.Length; i++)
        {
            var vertex = baseVertices[i];

            vertex.x += noise.Noise(timex + vertex.x, timex + vertex.y, timex + vertex.z) * Scale;
            vertex.y += noise.Noise(timey + vertex.x, timey + vertex.y, timey + vertex.z) * Scale;
            vertex.z += noise.Noise(timez + vertex.x, timez + vertex.y, timez + vertex.z) * Scale;

            vertices[i] = vertex;
        }

        mesh.vertices = vertices;

        if (RecalculateNormals)
        {
            mesh.RecalculateNormals();
        }
        mesh.RecalculateBounds();
        collider.sharedMesh = mesh;
    }
Exemplo n.º 12
0
    void Update()
    {
        Mesh mesh = GetComponent <MeshFilter>().mesh;

        if (baseVertices == null)
        {
            baseVertices = mesh.vertices;
        }

        Vector3[] vertices = new Vector3[baseVertices.Length];

        float timeX = Time.time * speed + 0.1365143f;
        float timeY = Time.time * speed + 1.21688f;
        float timeZ = Time.time * speed + 2.5564f;

        for (int i = 0; i < vertices.Length; i++)
        {
            Vector3 vertex = baseVertices[i];
            vertex.x += noise.Noise(timeX + vertex.x, timeX + vertex.y, timeX + vertex.z) * scale;
            vertex.y += noise.Noise(timeY + vertex.x, timeY + vertex.y, timeY + vertex.z) * scale;
            vertex.z += noise.Noise(timeZ + vertex.x, timeZ + vertex.y, timeZ + vertex.z) * scale;

            vertices[i] = vertex;
        }

        mesh.vertices = vertices;

        if (recalculateNormals)
        {
            mesh.RecalculateNormals();
        }
        mesh.RecalculateBounds();
    }
Exemplo n.º 13
0
        public void step()
        {
            x = (int)((perlin.Noise(tx, 0.1, 0.1) + 0.5f) * width);
            y = (int)((perlin.Noise(ty, 0.1, 0.1) + 0.5f) * height);

            tx += 0.005f;
            ty += 0.005f;
        }
Exemplo n.º 14
0
    void Update()
    {
        if (active)
        {
            audio.mute = false;
            if (noise == null)
            {
                noise = new Perlin();
            }

            float timex = Time.time * speed * 0.1365143f;
            float timey = Time.time * speed * 1.21688f;
            float timez = Time.time * speed * 2.5564f;

            for (int i = 0; i < particles.Length; i++)
            {
                Vector3 position = Vector3.Lerp(transform.position, target, oneOverZigs * (float)i);
                Vector3 offset   = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                               noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                               noise.Noise(timez + position.x, timez + position.y, timez + position.z));

                position += (offset * scale * ((float)i * oneOverZigs));

                particles [i].position = position;
                particles [i].color    = Color.white;
                particles [i].energy   = 1f;
            }

            particleEmitter.particles = particles;

            if (particleEmitter.particleCount >= 2)
            {
                if (startLight)
                {
                    startLight.transform.position = particles [0].position;
                    startLight.range = 0.4f;
                }
                if (endLight)
                {
                    endLight.transform.position = particles [particles.Length - 1].position;
                    endLight.range = 10;
                }
            }
        }
        else
        {
            particleEmitter.particles = null;
            audio.mute = true;
            if (endLight)
            {
                endLight.range = 0;
            }
            if (startLight)
            {
                startLight.range = 0;
            }
        }
    }
Exemplo n.º 15
0
    void Update()
    {
        float   perlinSpeed  = 0.66f;
        float   perlinSize   = 0.15f;
        Vector3 perlinOffset = new Vector3(perlin.Noise(Time.time * perlinSpeed), perlin.Noise(Time.time * perlinSpeed + 124.27f), perlin.Noise(Time.time * perlinSpeed + 254.57f)) * perlinSize;

        transform.position = Vector3.Lerp(transform.position, targetSource.transform.position + targetSource.transform.forward * distanceFromTarget + transform.TransformDirection(perlinOffset), Time.deltaTime * lerpSpeed);
        transform.rotation = targetSource.transform.rotation;
    }
Exemplo n.º 16
0
// private methods ----------------------------
//         unique -----------------------------
    void CalculatePerlinNoise()
    {
        perlinPoint = new Vector2[nodes.Length];
        gradients   = new float[nodes.Length][, ];
        for (int a = 0; a < nodes.Length; a++)
        {
            perlinPoint[a] = new Vector2((float)Pow(-1, rnd.Next(1, 2)) * 500f * (float)rnd.NextDouble(), (float)Pow(-1, rnd.Next(1, 2)) * 500f * (float)rnd.NextDouble());
            gradients [a]  = new float[size, size];
            float maxValue = float.MinValue;
            float minValue = float.MaxValue;
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    float x        = (float)i * 0.39f * 0.39f;
                    float y        = (float)j * 0.39f * 0.39f;
                    float newValue = Abs(perlin.Noise(x + perlinPoint[a].x, y + perlinPoint[a].y));
                    float m        = 1f;
                    for (int k = 0; k < 5; k++)
                    {
                        x        /= 2f;
                        y        /= 2f;
                        m        *= 2.1f;
                        newValue += m * Abs(perlin.Noise(x + perlinPoint[a].x, y + perlinPoint[a].y));
                    }
                    gradients[a][j, i] = newValue;
                    if (newValue > maxValue)
                    {
                        maxValue = newValue;
                    }
                    if (newValue < minValue)
                    {
                        minValue = newValue;
                    }
                }
            }
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    float result = (gradients[a][j, i] - minValue) / (maxValue - minValue);
                    result = result - result % 0.05f;
                    if (result >= 1 - 7 * 0.05f)
                    {
                        result = 0.99f;
                    }
                    if (result <= 7 * 0.05f)
                    {
                        result = 0f;
                    }
                    gradients[a][j, i] = result;
                }
            }
        }
    }
    void Update()
    {
        if (textMeshStr != currentTextMeshStr && textMeshFound)
        {
            Debug.Log("Setting new text to: " + textMeshStr);
            textMesh.text      = textMeshStr;
            currentTextMeshStr = textMeshStr;
        }

        if (noise == null)
        {
            noise = new Perlin();
        }

        float timex = Time.time * speed * 0.1365143f;
        float timey = Time.time * speed * 1.21688f;
        float timez = Time.time * speed * 2.5564f;

        for (int i = 0; i < particles.Length; i++)
        {
            Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
            Vector3 offset   = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                           noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                           noise.Noise(timez + position.x, timez + position.y, timez + position.z));
            position += (offset * scale * ((float)i * oneOverZigs));

            particles[i].position = position;
            particles[i].color    = Color.white;
            particles[i].energy   = 1f;
        }

        particleEmitter.particles = particles;

        if (particleEmitter.particleCount >= 2)
        {
            if (startLight)
            {
                startLight.transform.position = particles[0].position;
            }
            if (endLight)
            {
                endLight.transform.position = particles[particles.Length - 1].position;
            }
        }

        // update textMesh position
        if (textMesh != null)
        {
            Vector3 pos = new Vector3(this.transform.position.x,
                                      this.transform.position.y + 1,
                                      this.transform.position.z);
            textMesh.transform.position = pos;
        }
    }
    /**
     * Retrieves the wind vector at the given location.
     */
    public Vector3 WindVelocityAt(Vector3 position)
    {
        float timeTurbulence = Time.time * turbulenceFrequency;
        float timeX          = timeTurbulence * 0.1365143f;
        float timeY          = timeTurbulence * 1.21688f;
        float timeZ          = timeTurbulence * 2.5564f;

        Vector3 turbulence = new Vector3(perlin.Noise(timeX + position.x, timeX + position.y, timeX + position.z),
                                         perlin.Noise(timeY + position.x, timeY + position.y, timeY + position.z),
                                         perlin.Noise(timeZ + position.x, timeZ + position.y, timeZ + position.z))
                             * turbulenceAmplitude;

        return(windVelocity + turbulence);
    }
Exemplo n.º 19
0
    void Update()
    {
        if (!gameManager.isPaused && !gameManager.isGameOver)
        {
            if (target != null)
            {
                GetComponent <ParticleRenderer>().enabled = true;
                if (noise == null)
                {
                    noise = new Perlin();
                }

                float timex = Time.time * speed * 0.1365143f;
                float timey = Time.time * speed * 1.21688f;
                float timez = Time.time * speed * 2.5564f;

                for (int i = 0; i < particles.Length; i++)
                {
                    Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
                    Vector3 offset   = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                                   noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                                   noise.Noise(timez + position.x, timez + position.y, timez + position.z));
                    position += (offset * 0.3f * scale * ((float)i * oneOverZigs));

                    particles[i].position = position;
                    particles[i].color    = Color.white;
                    particles[i].energy   = 1f;
                }

                GetComponent <ParticleEmitter>().particles = particles;

                if (GetComponent <ParticleEmitter>().particleCount >= 2)
                {
                    if (startLight)
                    {
                        startLight.transform.position = particles[0].position;
                    }
                    if (endLight)
                    {
                        endLight.transform.position = particles[particles.Length - 1].position;
                    }
                }
            }
            else
            {
                GetComponent <ParticleRenderer>().enabled = false;
            }
        }
    }
Exemplo n.º 20
0
    void Update()
    {
        if (noise == null)
        {
            noise = new Perlin();
        }

        float timex = Time.time * speed * 0.1365143f;
        float timey = Time.time * speed * 1.21688f;
        float timez = Time.time * speed * 2.5564f;


        particles = new ParticleSystem.Particle[GetComponent <ParticleSystem>().particleCount];
        int total = GetComponent <ParticleSystem>().GetParticles(particles);

        for (int i = 0; i < particles.Length; i++)
        {
            if (null == target)
            {
                return;
            }
            Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
            Vector3 offset   = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
                                           noise.Noise(timey + position.x, timey + position.y, timey + position.z),
                                           noise.Noise(timez + position.x, timez + position.y, timez + position.z));
            position += (offset * scale * ((float)i * oneOverZigs));


            particles[i].position = position;
            particles[i].color    = Color.white;
//			particles[i].energy = 1f;
        }

        GetComponent <ParticleSystem>().SetParticles(particles, particles.Length);
//		Debug.Log("parsyscount:"+GetComponent<ParticleSystem>().particleCount);
//		Debug.Log("setting particles. nth:"+particles[Random.Range(0,99)].position);

        if (GetComponent <ParticleSystem>().particleCount >= 2)
        {
            if (startLight)
            {
                startLight.transform.position = particles[0].position;
            }
            if (endLight)
            {
                endLight.transform.position = particles[particles.Length - 1].position;
            }
        }
    }
Exemplo n.º 21
0
    void Update()
    {
        if (!target)
        {
            return;
        }
        if (!IsActive)
        {
            return;
        }
        if (_noise == null)
        {
            _noise = new Perlin();
        }

        float timex = Time.time * speed * 0.1365143f;
        float timey = Time.time * speed * 1.21688f;
        float timez = Time.time * speed * 2.5564f;

        for (int i = 0; i < _particles.Length; i++)
        {
            Vector3 position = Vector3.Lerp(transform.position + originOffset, target.position + targetOffset, _oneOverZigs * (float)i);
            float   offsetX  = restrainZigX ? 0 : _noise.Noise(timex + position.x, timex + position.y, timex + position.z);
            float   offsetY  = restrainZigY ? 0 : _noise.Noise(timey + position.x, timey + position.y, timey + position.z);
            float   offsetZ  = restrainZigZ ? 0 : _noise.Noise(timez + position.x, timez + position.y, timez + position.z);
            Vector3 offset   = new Vector3(offsetX, offsetY, offsetZ);

            position += (offset * scale * ((float)i * _oneOverZigs));

            _particles[i].position = position;
            _particles[i].color    = color;
            _particles[i].energy   = 1f;
        }

        GetComponent <ParticleEmitter>().particles = _particles;

        if (GetComponent <ParticleEmitter>().particleCount >= 2)
        {
            if (startLight)
            {
                startLight.transform.position = _particles[0].position;
            }
            if (endLight)
            {
                endLight.transform.position = _particles[_particles.Length - 1].position;
            }
        }
    }
Exemplo n.º 22
0
        public static BitmapVideoFrameWrapper CreateVideoFrame(int index, PixelFormat fmt, int w, int h, float scaleNoise, float offset)
        {
            var bitmap = new Bitmap(w, h, fmt);

            offset = offset * index;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var xf = x / (float)w;
                    var yf = y / (float)h;
                    var nx = x * scaleNoise + offset;
                    var ny = y * scaleNoise + offset;

                    var value = (int)((Perlin.Noise(nx, ny) + 1.0f) / 2.0f * 255);

                    var color = Color.FromArgb((int)(value * xf), (int)(value * yf), value);

                    bitmap.SetPixel(x, y, color);
                }
            }

            return(new BitmapVideoFrameWrapper(bitmap));
        }
Exemplo n.º 23
0
    // Update is called once per frame
    void Update()
    {
        int i = 0;

        for (int x = 0; x < noSpheresX; x++)
        {
            for (int y = 0; y < noSpheresY; y++)
            {
                for (int z = 0; z < noSpheresZ; z++)
                {
                    Vector3 pos = new Vector3(x, y, z);

                    pos.x += ampPerlin * Perlin.Noise(x * freqPerlin + speedPerlin * Time.time, y * freqPerlin, z * freqPerlin);
                    pos.y += ampPerlin * Perlin.Noise(x * freqPerlin + speedPerlin * Time.time, y * freqPerlin, z * freqPerlin + 13.2f);
                    pos.z += ampPerlin * Perlin.Noise(x * freqPerlin + speedPerlin * Time.time, y * freqPerlin, z * freqPerlin + 49.9f);

                    float scaleP = 1f + sizePerlin * Perlin.Noise(x * freqPerlin + speedPerlin * Time.time, y * freqPerlin, z * freqPerlin + 121.3f);

                    pos.x += (0.9f * scaleP + 0.1f) * ampVibrate * (Mathf.Sin(speedVibrate * Time.time + phaseVibrate * i));
                    pos.y += (0.9f * scaleP + 0.1f) * ampVibrate * (Mathf.Cos(speedVibrate * Time.time + phaseVibrate * i));
                    pos.z += (0.9f * scaleP + 0.1f) * ampVibrate * (Mathf.Cos(speedVibrate * Time.time + 0.5f * Mathf.PI + phaseVibrate * i));

                    spheres [i].transform.localPosition = pos;

                    Vector3 scale = new Vector3(size, size, size);
                    scale *= scaleP;

                    spheres [i].transform.localScale = scale;

                    i++;
                }
            }
        }
    }
Exemplo n.º 24
0
    public float Calculate(Vector2 texturePosition, float scaleInput, int x, int y, int z)
    {
        perlin = new Perlin(seed);

        fractal = new FractalNoise(h, lacunarity, octaves, perlin);

        float value = 0;

        switch (noiseType)
        {
        case NoiseType.Brownian:
            value = fractal.BrownianMotion(x * scale * scaleInput + texturePosition.x, y * scale * scaleInput, z * scale * scaleInput + texturePosition.y);
            break;

        case NoiseType.HybridMultifractal:
            value = fractal.HybridMultifractal(x * scale * scaleInput + texturePosition.x, y * scale * scaleInput, z * scale * scaleInput + texturePosition.y, offset);
            break;

        case NoiseType.RidgedMultifractal:
            value = fractal.RidgedMultifractal(x * scale * scaleInput + texturePosition.x, y * scale * scaleInput, z * scale * scaleInput + texturePosition.y, offset, gain);
            break;

        case NoiseType.Perlin:
            value = perlin.Noise(x * scale * scaleInput + texturePosition.x, y * scale * scaleInput, z * scale * scaleInput + texturePosition.y);
            break;
        }

        return(value);
    }
Exemplo n.º 25
0
    void Generate()
    {
        Vector3[] vertices = _meshfilter.mesh.vertices;
        int       zi       = 0;

        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i] += _meshfilter.mesh.normals[i] * ((Perlin.Noise(offset + vertices[i] * noisesScale) / 255f) * roughness);
        }
        _meshfilter.mesh.vertices = vertices;
        _meshfilter.mesh.RecalculateBounds();


        for (int i = 0; i < vertices.Length; i++)
        {
            if (vertices[i].z <= 0.01 && vertices[i].z >= -0.01)
            {
                z_vertices.Add(vertices[i]);
                zi++;
                float height = CalculateHeight(vertices[i]);
                if (height >= 0.5f && height < 2f)
                {
                    seaLevel_index.Add(zi);
                }
            }
        }

        SpawnBuilding();
        SpawnPerson();
    }
Exemplo n.º 26
0
    static void makePerlinElevation(PlanetData planet, IRandomGenerator gen, PlanetGeneratorData.ElevationData.PerlinFactors[] perlinFactors)
    {
        const float maxPerlinOffset = 10000;

        float minValue = float.MaxValue;
        float maxValue = float.MinValue;

        Vector3[] perlinOffset = new Vector3[perlinFactors.Length];
        for (int i = 0; i < perlinOffset.Length; i++)
        {
            perlinOffset[i] = new UniformVector3BoxDistribution(-maxPerlinOffset, maxPerlinOffset, -maxPerlinOffset, maxPerlinOffset, -maxPerlinOffset, maxPerlinOffset).Next(gen);
        }

        for (int i = 0; i < planet.points.Length; i++)
        {
            float scale = 0;
            for (int j = 0; j < perlinFactors.Length; j++)
            {
                scale += Perlin.Noise(perlinOffset[j] + planet.points[i].point * perlinFactors[j].frequency) * perlinFactors[j].amplitude;
            }

            planet.points[i].height = scale;
            minValue = Mathf.Min(minValue, scale);
            maxValue = Mathf.Max(maxValue, scale);
        }
        for (int i = 0; i < planet.points.Length; i++)
        {
            planet.points[i].height = (planet.points[i].height - minValue) / (maxValue - minValue) * 2 - 1; // range [-1,1]
        }
    }
Exemplo n.º 27
0
        public void Perturb(float f, float d)
        {
            int v, u;

            float[,] temp = new float[Size, Size];
            for (int z = 0; z < Size; z++)
            {
                for (int x = 0; x < Size; x++)
                {
                    v = z + (int)(Perlin.Noise(f * z / (float)Size, f * x / (float)Size, 0) * d);
                    u = x + (int)(Perlin.Noise(f * z / (float)Size, f * x / (float)Size, 1) * d);
                    if (v < 0)
                    {
                        v = 0;
                    }
                    if (v >= Size)
                    {
                        v = Size - 1;
                    }
                    if (u < 0)
                    {
                        u = 0;
                    }
                    if (u >= Size)
                    {
                        u = Size - 1;
                    }
                    temp[x, z] = Heights[u, v];
                }
            }
            Heights = temp;
        }
Exemplo n.º 28
0
    /*
     * BiomeHandler's main function
     * Used to assign a biome to a new chunk.
     * Play arround with the seed value in each of the 4 biome features to change the behaviour
     *      of the biome distribution.
     */
    public byte Assign(ChunkPos pos)
    {
        float currentAltitude    = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.ax + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.az + ((dispersionSeed * BiomeHandlerData.sx) % 1000));
        float currentHumidity    = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.bx + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.bz + ((dispersionSeed * BiomeHandlerData.sy) % 1000));
        float currentTemperature = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.cx + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.cz + ((dispersionSeed * BiomeHandlerData.sz) % 1000));
        float currentLightning   = Perlin.Noise(pos.x * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.dx + ((dispersionSeed * BiomeHandlerData.ss) % 1000), pos.z * BiomeHandlerData.featureModificationConstant * BiomeHandlerData.dz + ((dispersionSeed * BiomeHandlerData.sw) % 1000));

        float lowestDistance = 99;
        byte  lowestBiome    = 255;
        float distance;

        float4 currentSettings = new float4(currentAltitude, currentHumidity, currentTemperature, currentLightning);

        for (byte s = 0; s < amountOfBiomes; s++)
        {
            distance = BiomeHandler.Distance(currentSettings, BiomeHandlerData.codeToStats[s]);

            if (distance <= lowestDistance)
            {
                lowestDistance = distance;
                lowestBiome    = s;
            }
        }
        return(lowestBiome);
    }
Exemplo n.º 29
0
    float GetScale(Vector3 position)
    {
        var noffs = Vector3.up * _noiseSpeed * Time.time;
        var s     = Perlin.Noise(position * _noiseFrequency + noffs);

        return(Mathf.Lerp(_minScale, _maxScale, (s + 1) / 2));
    }
Exemplo n.º 30
0
    public TerrainPerlin(GameObject voxel, float voxel_size, float x_offset, float y_offset, float scene_width, float ratio)
    {
        voxels = new Dictionary <string, GameObject>();

        float rx = Random.Range(-1000.0f, 1000.0f);
        float ry = Random.Range(-1000.0f, 1000.0f);

        for (float y = 5; y > -5.0f; y -= voxel_size)
        {
            for (float x = 0; x < scene_width; x += voxel_size)
            {
                if (Perlin.Noise((x + rx) / 2.5f, (y + ry) / 1.8f) > 0.06f)
                {
                    GameObject v = GameObject.Instantiate(voxel);
                    v.transform.position = new Vector3(x + x_offset, y + y_offset, 0.0f);

                    string index = Mathf.Round(x / voxel_size) + "," + Mathf.Round(y / voxel_size);
                    voxels[index] = v;
                }
            }
        }

        float yy = -4.9f;

        for (float x = 0; x < scene_width; x += voxel_size)
        {
            GameObject v = GameObject.Instantiate(voxel);
            v.transform.position = new Vector3(x + x_offset, yy + y_offset, 0.0f);

            string index = Mathf.Round(x / voxel_size) + "," + Mathf.Round(yy / voxel_size);
            voxels[index] = v;
        }
    }
Exemplo n.º 31
0
    private void _CalcVerts()
    {
        List <Vector3> _tempVerts = new List <Vector3>();
        List <Vector2> _tempUVs   = new List <Vector2>();

        for (int i = 0; i <= 8; i++)
        {
            for (int j = 0; j <= 8; j++)
            {
                float X = (float)(originPoint.x + j);
                float Z = (float)(originPoint.z + i);

                Vector3 pos = new Vector3(X, 30 * Perlin.Noise(X / 4, Z / 4) * Perlin.Noise(X / 16.23f, Z / 50.23f), Z);

                //Vector3 pos = new Vector3(X, Mathf.Abs(Perlin.Noise(X/64, Z/64) * 30 * Perlin.Noise(X/8, Z/8)) + Perlin.Noise(X / 16, Z / 16), Z);
                //Debug.Log(pos);
                _tempVerts.Add(pos);
                _tempUVs.Add(new Vector2((float)i / 8, (float)j / 8));
            }
        }

        _vertices = new Vector3[_tempVerts.Count];
        for (int i = 0; i < _vertices.Length; i++)
        {
            _vertices[i] = _tempVerts[i];
        }

        _uvs = new Vector2[_tempUVs.Count];
        for (int i = 0; i < _uvs.Length; i++)
        {
            _uvs[i] = _tempUVs[i];
        }
    }
Exemplo n.º 32
0
    IEnumerator Generation()
    {
        int num = 0;
        speed = Random.Range(0.7f, 1.3f);
        scale = Random.Range(0.4f, 0.7f);
        noise = new Perlin();

        while(num < Random.Range(20,50))
        {
            var vertices = new Vector3[baseVertices.Length];

            float timex = Time.time * speed + 0.1365143f;
            float timey = Time.time * speed + 1.21688f;
            float timez = Time.time * speed + 2.5564f;

            for(int j = 0; j < vertices.Length; j++)
            {
                    var vertex = baseVertices [j];

                    vertex.x += noise.Noise (timex + vertex.x, timex + vertex.y, timex + vertex.z) * scale;
                    vertex.y += noise.Noise (timey + vertex.x, timey + vertex.y, timey + vertex.z) * scale;
                    vertex.z += noise.Noise (timez + vertex.x, timez + vertex.y, timez + vertex.z) * scale;

                    vertices [j] = vertex;
            }

            sourceMesh.vertices = vertices;

            sourceMesh.RecalculateNormals();
            sourceMesh.RecalculateBounds();

            num++;
            yield return new WaitForSeconds (0.01f);
        }

        //sourceMesh.Optimize();
        //workingMesh.vertices = SmoothFilter.hcFilter(sourceMesh.vertices, workingMesh.vertices, workingMesh.triangles, 0.0f, 0.5f);

        Vector2 offset = new Vector2(256, 128);
        int rand = Random.Range(0,6);

        /*switch(rand)
        {
            case 0:
                offset = new Vector2(0, 0);
            break;
            case 1:
                offset = new Vector2(256, 0);
            break;
            case 2:
                offset = new Vector2(512, 0);
            break;
            case 3:
                offset = new Vector2(0, 128);
            break;
            case 4:
                offset = new Vector2(256, 128);
            break;
            case 5:
                offset = new Vector2(512, 128);
            break;
            case 6:
                offset = new Vector2(0, 256);
            break;
            case 7:
                offset = new Vector2(256, 256);
            break;
        }*/

        meshR.material = Resources.Load ("Material/asteroid" + rand) as Material ;
        //meshR.material.SetTexture(rand,SystemGenerator.sprites[rand]);
    }
Exemplo n.º 33
0
    public float[] CreateTerrain(float scale)
    {
        Perlin noise = new Perlin();

            float[] alts = new float[vertices.Length];

            for (var i=0;i<nmbrHexs;i++)
            {
                Vector3 vertex = vertices[i];

                vertex.x += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;
                vertex.y += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;
                vertex.z += noise.Noise(vertex.x, vertex.y, vertex.z) * scale;

                // NOTE: This section needs a bit of work!
                // freeze polar seas!
                if (Mathf.Abs(vertex.y)+0.5f>articCircle)
                {
                    //alts[i] = Mathf.Max(seaLevel+gap, 1+vertex.magnitude);
                }

            }
            return alts;
    }