示例#1
0
    public void UpdateTextures()
    {
        if (Width > 0 && Height > 0 && NoisePoints > 0)
        {
            // Destroy if invalid
            if (generatedTexture != null)
            {
                if (generatedTexture.width != Width || generatedTexture.height != Height || generatedTexture.format != Format)
                {
                    generatedTexture = SgtHelper.Destroy(generatedTexture);
                }
            }

            // Create?
            if (generatedTexture == null)
            {
                generatedTexture = SgtHelper.CreateTempTexture2D("Aurora MainTex (Generated)", Width, Height, Format);

                generatedTexture.wrapMode = TextureWrapMode.Repeat;

                UpdateApply();
            }

            SgtHelper.BeginRandomSeed(NoiseSeed);
            {
                noisePoints.Clear();

                for (var i = 0; i < NoisePoints; i++)
                {
                    noisePoints.Add(1.0f - Random.Range(0.0f, NoiseStrength));
                }
            }
            SgtHelper.EndRandomSeed();

            var stepX = 1.0f / (Width - 1);
            var stepY = 1.0f / (Height - 1);

            for (var y = 0; y < Height; y++)
            {
                var v = y * stepY;

                for (var x = 0; x < Width; x++)
                {
                    var u = x * stepX;

                    WriteTexture(u, v, x, y);
                }
            }

            generatedTexture.Apply();
        }
    }
示例#2
0
    protected override int BeginQuads()
    {
        SgtHelper.BeginRandomSeed(Seed);

        if (Thickness != null)
        {
            armStep   = 360.0f * SgtHelper.Reciprocal(ArmCount);
            twistStep = 360.0f * Twist;

            return(StarCount);
        }

        return(0);
    }
示例#3
0
    private void UpdatePlanes()
    {
        planes.RemoveAll(p => p == null);

        if (PlaneCount != planes.Count)
        {
            SgtHelper.ResizeArrayTo(ref planes, PlaneCount, i => SgtProminencePlane.Create(this), p => SgtProminencePlane.Pool(p));
        }

        SgtHelper.BeginRandomSeed(Seed);
        {
            for (var i = planes.Count - 1; i >= 0; i--)
            {
                planes[i].ManualUpdate(mesh, material, Random.rotationUniform);
            }
        }
        SgtHelper.EndRandomSeed();
    }
示例#4
0
    protected override int BeginQuads()
    {
        SgtHelper.BeginRandomSeed(Seed);

        sourceTex2D = SourceTex as Texture2D;

        if (sourceTex2D != null && Samples > 0)
        {
#if UNITY_EDITOR
            SgtHelper.MakeTextureReadable(sourceTex2D);
            SgtHelper.MakeTextureTruecolor(sourceTex2D);
#endif
            halfSize = Size * 0.5f;

            return(StarCount);
        }

        return(0);
    }
    protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool)
    {
        stars = tempStars; tempStars.Clear();
        pool  = true;

        SgtHelper.BeginRandomSeed(Seed);
        {
            for (var i = 0; i < StarCount; i++)
            {
                var star     = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star);
                var x        = Random.Range(-0.5f, 0.5f);
                var y        = Random.Range(-0.5f, 0.5f);
                var z        = Random.Range(Offset * 0.5f, 0.5f);
                var position = default(Vector3);

                if (Random.value >= 0.5f)
                {
                    z = -z;
                }

                switch (Random.Range(0, 3))
                {
                case 0: position = new Vector3(z, x, y); break;

                case 1: position = new Vector3(x, z, y); break;

                case 2: position = new Vector3(x, y, z); break;
                }

                star.Sprite      = GetRandomStarSprite();
                star.Color       = Color.white;
                star.Radius      = Random.Range(StarRadiusMin, StarRadiusMax);
                star.Angle       = Random.Range(0.0f, Mathf.PI * 2.0f);
                star.Position    = Vector3.Scale(position, Extents);
                star.PulseRange  = Random.value * StarPulseMax;
                star.PulseSpeed  = Random.value;
                star.PulseOffset = Random.value;
            }
        }
        SgtHelper.EndRandomSeed();
    }
    protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool)
    {
        stars = tempStars; tempStars.Clear();
        pool  = true;

        SgtHelper.BeginRandomSeed(Seed);
        {
            for (var i = 0; i < StarCount; i++)
            {
                var star     = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star);
                var position = Random.insideUnitSphere;

                position.y *= Symmetry;

                star.Sprite   = GetRandomStarSprite();
                star.Color    = Color.white;
                star.Radius   = Random.Range(StarRadiusMin, StarRadiusMax);
                star.Angle    = Random.Range(0.0f, Mathf.PI * 2.0f);
                star.Position = position.normalized * Radius;
            }
        }
        SgtHelper.EndRandomSeed();
    }
    protected override void CalculateStars(out List <SgtStarfieldStar> stars, out bool pool)
    {
        stars = tempStars; tempStars.Clear();
        pool  = true;

        SgtHelper.BeginRandomSeed(Seed);
        {
            for (var i = 0; i < StarCount; i++)
            {
                var star      = SgtClassPool <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar(); stars.Add(star);
                var position  = Random.insideUnitSphere;
                var magnitude = Offset;

                if (Inverse == true)
                {
                    magnitude += (1.0f - position.magnitude) * (1.0f - Offset);
                }
                else
                {
                    magnitude += position.magnitude * (1.0f - Offset);
                }

                position.y *= Symmetry;

                star.Sprite      = GetRandomStarSprite();
                star.Color       = Color.white;
                star.Radius      = Random.Range(StarRadiusMin, StarRadiusMax);
                star.Angle       = Random.Range(0.0f, Mathf.PI * 2.0f);
                star.Position    = position.normalized * magnitude * Radius;
                star.PulseRange  = Random.value * StarPulseMax;
                star.PulseSpeed  = Random.value;
                star.PulseOffset = Random.value;
            }
        }
        SgtHelper.EndRandomSeed();
    }
示例#8
0
    public void UpdateDebris()
    {
        var size = (long)System.Math.Ceiling(SgtHelper.Divide(HideDistance, (float)CellSize));

        if (Target != null && CellSize > 0.0f && Prefabs != null && DebrisCountTarget > 0 && size > 0)
        {
            var worldPoint = Target.position;
            var centerX    = (long)System.Math.Round(worldPoint.x / CellSize);
            var centerY    = (long)System.Math.Round(worldPoint.y / CellSize);
            var centerZ    = (long)System.Math.Round(worldPoint.z / CellSize);

            var newBounds = new SgtBoundsL(centerX, centerY, centerZ, size);

            if (newBounds != bounds)
            {
                var probability = DebrisCountTarget / (size * size * size);
                var cellMin     = (float)CellSize * (0.5f - CellNoise);
                var cellMax     = (float)CellSize * (0.5f + CellNoise);

                for (var z = newBounds.minZ; z <= newBounds.maxZ; z++)
                {
                    for (var y = newBounds.minY; y <= newBounds.maxY; y++)
                    {
                        for (var x = newBounds.minX; x <= newBounds.maxX; x++)
                        {
                            if (bounds.Contains(x, y, z) == false)
                            {
                                // Calculate seed for this grid cell and try to minimize visible symmetry
                                var seed = Seed ^ (x * (1 << 8)) ^ (y * (1 << 16)) ^ (z * (1 << 24));

                                SgtHelper.BeginRandomSeed((int)(seed % int.MaxValue));
                                {
                                    // Can debris potentially spawn in this cell?
                                    if (Random.value < probability)
                                    {
                                        var debrisX     = x * CellSize + Random.Range(cellMin, cellMax);
                                        var debrisY     = y * CellSize + Random.Range(cellMin, cellMax);
                                        var debrisZ     = z * CellSize + Random.Range(cellMin, cellMax);
                                        var debrisPoint = new Vector3((float)debrisX, (float)debrisY, (float)debrisZ);

                                        // Spawn everywhere, or only inside specified shapes?
                                        if (SpawnInside == null || Random.value < SpawnInside.GetDensity(debrisPoint))
                                        {
                                            Spawn(x, y, z, debrisPoint);
                                        }
                                    }
                                }
                                SgtHelper.EndRandomSeed();
                            }
                        }
                    }
                }

                bounds = newBounds;

                if (Debris != null)
                {
                    for (var i = Debris.Count - 1; i >= 0; i--)
                    {
                        var debris = Debris[i];

                        if (debris == null)
                        {
                            Debris.RemoveAt(i);
                        }
                        else if (bounds.Contains(debris.Cell) == false)
                        {
                            Despawn(debris, i);
                        }
                    }
                }
            }

            UpdateDebrisScale(worldPoint);
        }
        else
        {
            ClearDebris();
        }
    }
示例#9
0
    public void UpdateMesh()
    {
        if (Detail > 2)
        {
            if (generatedMesh == null)
            {
                generatedMesh = SgtHelper.CreateTempMesh("Flare Mesh (Generated)");

                UpdateApply();
            }

            var total     = Detail + 1;
            var positions = new Vector3[total];
            var coords1   = new Vector2[total];
            var indices   = new int[Detail * 3];
            var angleStep = (Mathf.PI * 2.0f) / Detail;
            var noiseStep = 0.0f;

            if (Noise == true && NoisePoints > 0)
            {
                SgtHelper.BeginRandomSeed(NoiseSeed);
                {
                    points.Clear();

                    for (var i = 0; i < NoisePoints; i++)
                    {
                        points.Add(Random.value);
                    }

                    noiseStep = NoisePoints / (float)Detail;
                }
                SgtHelper.EndRandomSeed();
            }

            for (var point = 0; point < Detail; point++)
            {
                var v     = point + 1;
                var angle = angleStep * point;
                var x     = Mathf.Sin(angle);
                var y     = Mathf.Cos(angle);
                var r     = Radius;

                if (Wave == true)
                {
                    var waveAngle = (angle + WavePhase * Mathf.Deg2Rad) * WavePoints;

                    r += Mathf.Pow(Mathf.Cos(waveAngle) * 0.5f + 0.5f, WavePower * WavePower) * WaveStrength;
                }

                if (Noise == true && NoisePoints > 0)
                {
                    //var noise  = Mathf.Repeat(noiseStep * point + NoisePhase, NoisePoints);
                    var noise  = point * noiseStep;
                    var index  = (int)noise;
                    var frac   = noise % 1.0f;
                    var pointA = points[(index + 0) % NoisePoints];
                    var pointB = points[(index + 1) % NoisePoints];
                    var pointC = points[(index + 2) % NoisePoints];
                    var pointD = points[(index + 3) % NoisePoints];

                    r += SgtHelper.CubicInterpolate(pointA, pointB, pointC, pointD, frac) * NoiseStrength;
                }

                positions[v] = new Vector3(x * r, y * r, 0.0f);
                coords1[v]   = new Vector2(1.0f, 0.0f);
            }

            for (var tri = 0; tri < Detail; tri++)
            {
                var i  = tri * 3;
                var v0 = tri + 1;
                var v1 = tri + 2;

                if (v1 >= total)
                {
                    v1 = 1;
                }

                indices[i + 0] = 0;
                indices[i + 1] = v0;
                indices[i + 2] = v1;
            }

            generatedMesh.Clear(false);
            generatedMesh.vertices  = positions;
            generatedMesh.uv        = coords1;
            generatedMesh.triangles = indices;
            generatedMesh.RecalculateNormals();
            generatedMesh.RecalculateBounds();
        }
    }
示例#10
0
    protected override int BeginQuads()
    {
        SgtHelper.BeginRandomSeed(Seed);

        return(StarCount);
    }
示例#11
0
    public void UpdateMeshesAndModels()
    {
        updateMeshesAndModelsCalled = true;

        if (Meshes == null)
        {
            Meshes = new List <Mesh>();
        }

        if (Models == null)
        {
            Models = new List <SgtAuroraModel>();
        }

        if (PathDetail > 0 && PathLengthMin > 0.0f && PathLengthMax > 0.0f)
        {
            var meshCount   = 1;
            var mesh        = GetMesh(0);
            var vertexCount = 0;

            SgtHelper.BeginRandomSeed(Seed);
            {
                for (var i = 0; i < PathCount; i++)
                {
                    AddPath(ref mesh, ref meshCount, ref vertexCount);
                }
            }
            SgtHelper.EndRandomSeed();

            BakeMesh(mesh);

            for (var i = Meshes.Count - 1; i >= meshCount; i--)
            {
                var extraMesh = Meshes[i];

                if (extraMesh != null)
                {
                    extraMesh.Clear(false);

                    SgtObjectPool <Mesh> .Add(extraMesh);
                }

                Meshes.RemoveAt(i);
            }
        }

        for (var i = 0; i < Meshes.Count; i++)
        {
            var model = GetOrAddModel(i);

            model.SetMesh(Meshes[i]);
        }

        // Remove any excess
        if (Models != null)
        {
            var min = Mathf.Max(0, Meshes.Count);

            for (var i = Models.Count - 1; i >= min; i--)
            {
                SgtAuroraModel.Pool(Models[i]);

                Models.RemoveAt(i);
            }
        }
    }