protected virtual void Update()
        {
            if (target == null)
            {
                ClearDebris(); return;
            }

            var followerDensity = GetFollowerDensity();

            if (followerDensity > 0.0f)
            {
                var debrisCount = debris != null ? debris.Count : 0;

                if (debrisCount < spawnLimit)
                {
                    spawnCooldown -= Time.deltaTime;

                    while (spawnCooldown <= 0.0f)
                    {
                        spawnCooldown += Random.Range(spawnRateMin, spawnRateMax);

                        SpawnDebris(false);

                        debrisCount += 1;

                        if (debrisCount >= spawnLimit)
                        {
                            break;
                        }
                    }
                }
            }

            followerPosition = target.position;

            if (debris != null)
            {
                var distanceRange = hideDistance - showDistance;

                for (var i = debris.Count - 1; i >= 0; i--)
                {
                    var debris = this.debris[i];

                    if (debris != null)
                    {
                        var targetScale = default(float);
                        var distance    = Vector3.Distance(followerPosition, debris.transform.position);

                        // Fade its size in
                        var factor = SgtHelper.DampenFactor(showSpeed, Time.deltaTime, 0.1f);

                        debris.Show = Mathf.Lerp(debris.Show, 1.0f, factor);

                        if (distance < showDistance)
                        {
                            targetScale = 1.0f;
                        }
                        else if (distance > hideDistance)
                        {
                            targetScale = 0.0f;
                        }
                        else
                        {
                            targetScale = 1.0f - SgtHelper.Divide(distance - showDistance, distanceRange);
                        }

                        debris.transform.localScale = debris.Scale * debris.Show * Mathf.Max(minScale, targetScale);

                        if (targetScale <= 0.0f)
                        {
                            Despawn(debris, i);
                        }
                    }
                    else
                    {
                        this.debris.RemoveAt(i);
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnInspector()
        {
            var updateMaterial = false;
            var updateModels   = false;

            DrawDefault("Color", ref updateMaterial, "The base color will be multiplied by this.");
            BeginError(Any(t => t.Brightness < 0.0f));
            DrawDefault("Brightness", ref updateMaterial, "The Color.rgb values are multiplied by this, allowing you to quickly adjust the overall brightness.");
            EndError();
            DrawDefault("RenderQueue", ref updateMaterial, "This allows you to adjust the render queue of the ring material. You can normally adjust the render queue in the material settings, but since this material is procedurally generated your changes will be lost.");

            Separator();

            BeginError(Any(t => t.MainTex == null));
            DrawDefault("MainTex", ref updateMaterial, "The texture applied to the ring, where the left side is the inside, and the right side is the outside.");
            EndError();

            BeginError(Any(t => t.Segments < 1));
            DrawDefault("Segments", ref updateModels, ref updateModels, "This allows you to set how many copies of the Mesh are required to complete the ring. For example, if the Mesh is 1/4 of the ring, then Segments should be set to 4.");
            EndError();
            BeginError(Any(t => t.Mesh == null));
            DrawDefault("Mesh", ref updateModels, "This allows you to set the mesh used to render the ring.");
            EndError();

            Separator();

            DrawDefault("Detail", ref updateMaterial, "Should the ring have a detail texture? For example, dust noise when you get close.");

            if (Any(t => t.Detail == true))
            {
                BeginIndent();
                BeginError(Any(t => t.DetailTex == null));
                DrawDefault("DetailTex", ref updateMaterial, "This allows you to set the detail texture that gets repeated on the ring surface.");
                EndError();
                BeginError(Any(t => t.DetailScaleX < 0.0f));
                DrawDefault("DetailScaleX", ref updateMaterial, "The detail texture horizontal tiling.");
                EndError();
                BeginError(Any(t => t.DetailScaleY < 1));
                DrawDefault("DetailScaleY", ref updateMaterial, "The detail texture vertical tiling.");
                EndError();
                DrawDefault("DetailOffset", ref updateMaterial, "The UV offset of the detail texture.");
                DrawDefault("DetailSpeed", ref updateMaterial, "The scroll speed of the detail texture UV offset.");
                DrawDefault("DetailTwist", ref updateMaterial, "The amount the detail texture is twisted around the ring.");
                BeginError(Any(t => t.DetailTwistBias < 1.0f));
                DrawDefault("DetailTwistBias", ref updateMaterial, "The amount the twisting is pushed to the outer edge.");
                EndError();
                EndIndent();
            }

            Separator();

            DrawDefault("Near", ref updateMaterial, "Enable this if you want the ring to fade out as the camera approaches.");

            if (Any(t => t.Near == true))
            {
                BeginIndent();
                BeginError(Any(t => t.NearTex == null));
                DrawDefault("NearTex", ref updateMaterial, "The lookup table used to calculate the fade opacity based on distance, where the left side is used when the camera is close, and the right side is used when the camera is far.");
                EndError();
                BeginError(Any(t => t.NearDistance <= 0.0f));
                DrawDefault("NearDistance", ref updateMaterial, "The distance the fading begins from in world space.");
                EndError();
                EndIndent();
            }

            Separator();

            DrawDefault("Lit", ref updateMaterial, "If you enable this then nearby SgtLight and SgtShadow casters will be found and applied to the lighting calculations.");

            if (Any(t => t.Lit == true))
            {
                if (SgtLight.InstanceCount == 0)
                {
                    EditorGUILayout.HelpBox("You need to add the SgtLight component to your scene lights for them to work with SGT.", MessageType.Warning);
                }

                BeginIndent();
                BeginError(Any(t => t.LightingTex == null));
                DrawDefault("LightingTex", ref updateMaterial, "The look up table associating light angle with surface color. The left side is used on the dark side, the middle is used on the horizon, and the right side is used on the light side.");
                EndError();
                DrawDefault("AmbientColor", ref updateMaterial, "The ring will always be lit by this amount.");
                DrawDefault("Scattering", ref updateMaterial, "If you enable this then light will scatter through the ring atmosphere. This means light entering the eye will come from all angles, especially around the light point.");

                if (Any(t => t.Scattering == true))
                {
                    BeginIndent();
                    BeginError(Any(t => t.ScatteringMie <= 0.0f));
                    DrawDefault("ScatteringMie", ref updateMaterial, "The mie scattering term, allowing you to adjust the distribution of front scattered light.");
                    EndError();
                    Draw("ScatteringStrength", "The scattering is multiplied by this value, allowing you to easily adjust the brightness of the effect.");                                     // Updated in LateUpdate
                    EndIndent();
                }
                EndIndent();
            }

            if (Any(t => t.Mesh == null && t.GetComponent <SgtRingMesh>() == null))
            {
                Separator();

                if (Button("Add Mesh") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtRingMesh>(t.gameObject));
                }
            }

            if (Any(t => t.Near == true && t.NearTex == null && t.GetComponent <SgtRingNearTex>() == null))
            {
                Separator();

                if (Button("Add NearTex") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtRingNearTex>(t.gameObject));
                }
            }

            if (Any(t => t.Lit == true && t.LightingTex == null && t.GetComponent <SgtRingLightingTex>() == null))
            {
                Separator();

                if (Button("Add LightingTex") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtRingLightingTex>(t.gameObject));
                }
            }

            if (updateMaterial == true)
            {
                DirtyEach(t => t.UpdateMaterial());
            }
            if (updateModels == true)
            {
                DirtyEach(t => t.UpdateModels());
            }
        }
Exemplo n.º 3
0
        private void Build(SgtTerrain terrain, Vector3 bestPoint)
        {
            if (meshCollider == null)
            {
                var gameObject = new GameObject("Plane");
        #if UNITY_EDITOR
                gameObject.hideFlags = HideFlags.DontSave;
        #endif
                meshCollider = gameObject.AddComponent <MeshCollider>();
            }

            if (mesh == null)
            {
                mesh = SgtObjectPool <Mesh> .Pop() ?? new Mesh();

        #if UNITY_EDITOR
                mesh.hideFlags = HideFlags.DontSave;
        #endif
                mesh.name = "Plane";
            }

            var sideE        = Detail;
            var sideP        = Detail + 1;
            var vertexCount  = sideP * sideP;
            var indexCount   = sideE * sideE * 6;
            var rotation     = Quaternion.Inverse(terrain.transform.rotation) * Quaternion.LookRotation(bestPoint);
            var distance     = bestPoint.magnitude;
            var uniformScale = SgtHelper.UniformScale(terrain.transform.lossyScale);
            var size         = Size * SgtHelper.Reciprocal(uniformScale);
            var step         = (size * 2.0f) / Detail;

            if (positions == null || positions.Length != vertexCount)
            {
                positions = new Vector3[vertexCount];
            }

            for (var y = 0; y <= Detail; y++)
            {
                for (var x = 0; x <= Detail; x++)
                {
                    var index = x + y * sideP;
                    var point = rotation * new Vector3(x * step - size, y * step - size, distance);

                    positions[index] = (Vector3)terrain.GetLocalPoint(new SgtVector3D(point));
                }
            }

            // Regen indices?
            if (indices == null || indices.Length != indexCount)
            {
                indices = new int[indexCount];

                for (var y = 0; y < sideE; y++)
                {
                    for (var x = 0; x < sideE; x++)
                    {
                        var index  = (x + y * sideE) * 6;
                        var vertex = x + y * sideP;

                        indices[index + 0] = vertex;
                        indices[index + 1] = vertex + 1;
                        indices[index + 2] = vertex + sideP;
                        indices[index + 3] = vertex + sideP + 1;
                        indices[index + 4] = vertex + sideP;
                        indices[index + 5] = vertex + 1;
                    }
                }

                mesh.Clear();
            }

            mesh.vertices  = positions;
            mesh.triangles = indices;

            meshCollider.sharedMesh = mesh;

            meshCollider.transform.SetParent(terrain.transform, false);
        }
Exemplo n.º 4
0
        protected override void OnInspector()
        {
            var dirtyMaterial = false;

            Draw("color", ref dirtyMaterial, "The base color will be multiplied by this.");
            BeginError(Any(t => t.Brightness <= 0.0f));
            Draw("brightness", ref dirtyMaterial, "The Color.rgb values are multiplied by this, allowing you to quickly adjust the overall brightness.");
            EndError();
            Draw("renderQueue", ref dirtyMaterial, "This allows you to adjust the render queue of the cloudsphere material. You can normally adjust the render queue in the material settings, but since this material is procedurally generated your changes will be lost.");

            Separator();

            BeginError(Any(t => t.MainTex == null));
            Draw("mainTex", ref dirtyMaterial, "The cube map applied to the cloudsphere surface.");
            EndError();
            BeginError(Any(t => t.DepthTex == null));
            Draw("depthTex", ref dirtyMaterial, "The look up table associating optical depth with cloud color. The left side is used when the depth is thin (e.g. edge of the cloudsphere when looking from space). The right side is used when the depth is thick (e.g. center of the cloudsphere when looking from space).");
            EndError();
            BeginError(Any(t => t.Radius < 0.0f));
            Draw("radius", "This allows you to set the radius of the cloudsphere in local space.");
            EndError();
            Draw("cameraOffset", "This allows you to offset the camera distance in world space when rendering the cloudsphere, giving you fine control over the render order.");             // Updated automatically

            Separator();

            Draw("softness", ref dirtyMaterial, "Should the stars fade out if they're intersecting solid geometry?");

            if (Any(t => t.Softness > 0.0f))
            {
                foreach (var camera in Camera.allCameras)
                {
                    if (SgtHelper.Enabled(camera) == true && camera.depthTextureMode == DepthTextureMode.None)
                    {
                        if ((camera.cullingMask & (1 << Target.gameObject.layer)) != 0)
                        {
                            if (HelpButton("You have enabled soft particles, but the '" + camera.name + "' camera does not write depth textures.", MessageType.Error, "Fix", 50.0f) == true)
                            {
                                var dtm = SgtHelper.GetOrAddComponent <SgtDepthTextureMode>(camera.gameObject);

                                dtm.DepthMode = DepthTextureMode.Depth;

                                dtm.UpdateDepthMode();

                                Selection.activeObject = dtm;
                            }
                        }
                    }
                }
            }

            Separator();

            Draw("lit", ref dirtyMaterial, "If you enable this then nearby SgtLight and SgtShadow casters will be found and applied to the lighting calculations.");

            if (Any(t => t.Lit == true))
            {
                if (SgtLight.InstanceCount == 0)
                {
                    EditorGUILayout.HelpBox("You need to add the SgtLight component to your scene lights for them to work with SGT.", MessageType.Warning);
                }

                BeginIndent();
                BeginError(Any(t => t.LightingTex == null));
                Draw("lightingTex", ref dirtyMaterial, "The look up table associating light angle with surface color. The left side is used on the dark side, the middle is used on the horizon, and the right side is used on the light side.");
                EndError();
                Draw("ambientColor", ref dirtyMaterial, "The cloudsphere will always be lit by this amount.");
                EndIndent();
            }

            Separator();

            Draw("near", ref dirtyMaterial, "Enable this if you want the cloudsphere to fade out as the camera approaches.");

            if (Any(t => t.Near == true))
            {
                BeginIndent();
                BeginError(Any(t => t.NearTex == null));
                Draw("nearTex", ref dirtyMaterial, "The lookup table used to calculate the fade opacity based on distance, where the left side is used when the camera is close, and the right side is used when the camera is far.");
                EndError();
                BeginError(Any(t => t.NearDistance <= 0.0f));
                Draw("nearDistance", ref dirtyMaterial, "The distance the fading begins from in world space.");
                EndError();
                EndIndent();
            }

            Separator();

            Draw("detail", ref dirtyMaterial, "");

            if (Any(t => t.Detail == true))
            {
                BeginIndent();
                BeginError(Any(t => t.DetailTex == null));
                Draw("detailTex", ref dirtyMaterial, "");
                EndError();
                BeginError(Any(t => t.DetailScale <= 0.0f));
                Draw("detailScale", ref dirtyMaterial, "");
                EndError();
                BeginError(Any(t => t.DetailTiling <= 0.0f));
                Draw("detailTiling", ref dirtyMaterial, "");
                EndError();
                EndIndent();
            }

            Separator();

            BeginError(Any(t => t.Mesh == null));
            Draw("mesh", "This allows you to set the mesh used to render the cloudsphere. This should be a sphere.");
            EndError();
            BeginError(Any(t => t.MeshRadius <= 0.0f));
            Draw("meshRadius", "This allows you to set the radius of the Mesh. If this is incorrectly set then the cloudsphere will render incorrectly.");
            EndError();

            if (Any(t => t.DepthTex == null && t.GetComponent <SgtCloudsphereDepthTex>() == null))
            {
                Separator();

                if (Button("Add InnerDepthTex & OuterDepthTex") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtCloudsphereDepthTex>(t.gameObject));
                }
            }

            if (Any(t => t.Lit == true && t.LightingTex == null && t.GetComponent <SgtCloudsphereLightingTex>() == null))
            {
                Separator();

                if (Button("Add LightingTex") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtCloudsphereLightingTex>(t.gameObject));
                }
            }

            if (Any(t => t.Near == true && t.NearTex == null && t.GetComponent <SgtCloudsphereNearTex>() == null))
            {
                Separator();

                if (Button("Add NearTex") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtCloudsphereNearTex>(t.gameObject));
                }
            }

            if (Any(t => SetMeshAndMeshRadius(t, false)))
            {
                Separator();

                if (Button("Set Mesh & Mesh Radius") == true)
                {
                    Each(t => SetMeshAndMeshRadius(t, true));
                }
            }

            if (dirtyMaterial == true)
            {
                DirtyEach(t => t.DirtyMaterial());
            }
        }
Exemplo n.º 5
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(generatedInnerTexture);
     SgtHelper.Destroy(generatedOuterTexture);
 }
Exemplo n.º 6
0
        protected bool Button(string text)
        {
            var rect = SgtHelper.Reserve();

            return(GUI.Button(rect, text));
        }
Exemplo n.º 7
0
        private void Spawn(long x, long y, long z, Vector3 point)
        {
            var index  = Random.Range(0, prefabs.Count);
            var prefab = prefabs[index];

            if (prefab != null)
            {
                var debris = Spawn(prefab);

                debris.Cell = new SgtLong3(x, y, z);

                debris.transform.position = point;

                if (randomRotation == true)
                {
                    debris.transform.localRotation = Random.rotation;
                }
                else
                {
                    debris.transform.localRotation = prefab.transform.rotation;
                }

                debris.State = SgtDebris.StateType.Fade;
                debris.Scale = prefab.transform.localScale * Mathf.Lerp(scaleMin, scaleMax, SgtHelper.Sharpness(Random.value, scaleBias));

                debris.InvokeOnSpawn();

                spawnedDebris.Add(debris);
            }
        }
        private void Spawn(long x, long y, long z, Vector3 point)
        {
            var index  = Random.Range(0, Prefabs.Count);
            var prefab = Prefabs[index];

            if (prefab != null)
            {
                var debris = Spawn(prefab);

                debris.Cell.x = x;
                debris.Cell.y = y;
                debris.Cell.z = z;

                debris.transform.position = point;

                if (RandomRotation == true)
                {
                    debris.transform.localRotation = Random.rotation;
                }
                else
                {
                    debris.transform.localRotation = prefab.transform.rotation;
                }

                debris.State = SgtDebris.StateType.Fade;
                debris.Scale = prefab.transform.localScale * Mathf.Lerp(ScaleMin, ScaleMax, SgtHelper.Sharpness(Random.value, ScaleBias));

                if (debris.OnSpawn != null)
                {
                    debris.OnSpawn();
                }

                this.debris.Add(debris);
            }
        }
Exemplo n.º 9
0
        protected virtual void OnDestroy()
        {
            SgtSingularityModel.MarkForDestruction(model);

            SgtHelper.Destroy(material);
        }
Exemplo n.º 10
0
        protected override void OnInspector()
        {
            var dirtyMaterial = false;
            var dirtyMesh     = false;

            DrawMaterial(ref dirtyMaterial);

            Separator();

            DrawMainTex(ref dirtyMaterial);
            DrawLayout(ref dirtyMesh);

            Separator();

            Draw("softness", ref dirtyMaterial, "Should the stars fade out if they're intersecting solid geometry?");

            if (Any(t => t.Softness > 0.0f))
            {
                foreach (var camera in Camera.allCameras)
                {
                    if (SgtHelper.Enabled(camera) == true && camera.depthTextureMode == DepthTextureMode.None)
                    {
                        if ((camera.cullingMask & (1 << Target.gameObject.layer)) != 0)
                        {
                            if (HelpButton("You have enabled soft particles, but the '" + camera.name + "' camera does not write depth textures.", MessageType.Error, "Fix", 50.0f) == true)
                            {
                                var dtm = SgtHelper.GetOrAddComponent <SgtDepthTextureMode>(camera.gameObject);

                                dtm.DepthMode = DepthTextureMode.Depth;

                                dtm.UpdateDepthMode();

                                Selection.activeObject = dtm;
                            }
                        }
                    }
                }
            }

            DrawPointMaterial(ref dirtyMaterial);

            Draw("far", ref dirtyMaterial, "Should the stars fade out when the camera gets too far away?");

            if (Any(t => t.Far == true))
            {
                BeginIndent();
                BeginError(Any(t => t.FarTex == null));
                Draw("farTex", ref dirtyMaterial, "The lookup table used to calculate the fading amount based on the distance.");
                EndError();
                BeginError(Any(t => t.FarRadius < 0.0f));
                Draw("farRadius", ref dirtyMaterial, "The radius of the fading effect in world space.");
                EndError();
                BeginError(Any(t => t.FarThickness <= 0.0f));
                Draw("farThickness", ref dirtyMaterial, "The thickness of the fading effect in world space.");
                EndError();
                EndIndent();
            }

            Separator();

            Draw("seed", ref dirtyMesh, "This allows you to set the random seed used during procedural generation.");
            BeginError(Any(t => t.Size.x <= 0.0f || t.Size.y <= 0.0f || t.Size.z <= 0.0f));
            Draw("size", ref dirtyMesh, ref dirtyMaterial, "The radius of the starfield.");
            EndError();

            Separator();

            BeginError(Any(t => t.StarCount < 0));
            Draw("starCount", ref dirtyMesh, "The amount of stars that will be generated in the starfield.");
            EndError();
            Draw("starColors", ref dirtyMesh, "Each star is given a random color from this gradient.");
            BeginError(Any(t => t.StarRadiusMin <0.0f || t.StarRadiusMin> t.StarRadiusMax));
            Draw("starRadiusMin", ref dirtyMesh, "The minimum radius of stars in the starfield.");
            EndError();
            BeginError(Any(t => t.StarRadiusMax <0.0f || t.StarRadiusMin> t.StarRadiusMax));
            Draw("starRadiusMax", ref dirtyMesh, "The maximum radius of stars in the starfield.");
            EndError();
            BeginError(Any(t => t.StarRadiusBias < 1.0f));
            Draw("starRadiusBias", ref dirtyMesh, "How likely the size picking will pick smaller stars over larger ones (1 = default/linear).");
            EndError();
            Draw("starPulseMax", ref dirtyMesh, "The maximum amount a star's size can pulse over time. A value of 1 means the star can potentially pulse between its maximum size, and 0.");

            RequireCamera();

            serializedObject.ApplyModifiedProperties();

            if (dirtyMaterial == true)
            {
                DirtyEach(t => t.DirtyMaterial());
            }
            if (dirtyMesh == true)
            {
                DirtyEach(t => t.DirtyMesh());
            }

            if (Any(t => t.Far == true && t.FarTex == null && t.GetComponent <SgtStarfieldInfiniteFarTex>() == null))
            {
                Separator();

                if (Button("Add FarTex") == true)
                {
                    Each(t => SgtHelper.GetOrAddComponent <SgtStarfieldInfiniteFarTex>(t.gameObject));
                }
            }

            if (Any(t => t.GetComponentInParent <SgtFloatingObject>()))
            {
                EditorGUILayout.HelpBox("SgtStarfieldInfinite automatically snaps with the floating origin system, using SgtFloatingObject may cause issues with this GameObject.", MessageType.Warning);
            }

            if (SgtFloatingCamera.Instances.Count > 0 && Any(t => t.transform.rotation != Quaternion.identity))
            {
                EditorGUILayout.HelpBox("This transform is rotated, this may cause issues with the floating origin system.", MessageType.Warning);
            }

            if (SgtFloatingCamera.Instances.Count > 0 && Any(t => IsUniform(t.transform) == false))
            {
                EditorGUILayout.HelpBox("This transform is non-uniformly scaled, this may cause issues with the floating origin system.", MessageType.Warning);
            }
        }
        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 - transform.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)
                                {
                                    SgtHelper.BeginRandomSeed(Seed, x, y, z);
                                    {
                                        // 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 = this.debris[i];

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

                UpdateDebrisScale(worldPoint);
            }
            else
            {
                ClearDebris();
            }
        }
Exemplo n.º 12
0
        protected override float DoCalculate(Vector3 eye, Vector3 target)
        {
            var coverage = 0.0f;

            if (Resolution > 0 && Size > 0.0f)
            {
                if (renderTexture != null)
                {
                    if (renderTexture.width != Resolution || renderTexture.height != Resolution)
                    {
                        renderTexture = SgtHelper.Destroy(renderTexture);
                    }
                }

                if (renderTexture == null)
                {
                    renderTexture = new RenderTexture(Resolution, Resolution, 16);
                }

                if (readTexture != null)
                {
                    if (readTexture.width != Resolution || readTexture.height != Resolution)
                    {
                        readTexture = SgtHelper.Destroy(readTexture);
                    }
                }

                if (readTexture == null)
                {
                    readTexture = new Texture2D(Resolution, Resolution);
                }

                var oldPosition = transform.localPosition;
                var oldRotation = transform.localRotation;

                // Render
                UpdateCamera();

                cachedCamera.farClipPlane = Vector3.Distance(eye, target);

                cachedCamera.transform.position = eye;

                cachedCamera.transform.LookAt(target);

                cachedCamera.targetTexture = renderTexture;

                cachedCamera.Render();

                // Copy
                RenderTexture.active = renderTexture;

                readTexture.ReadPixels(new Rect(0.0f, 0.0f, Resolution, Resolution), 0, 0);

                // Clear
                RenderTexture.active = null;

                cachedCamera.targetTexture = null;

                transform.localPosition = oldPosition;
                transform.localRotation = oldRotation;

                // Calculate
                for (var y = 0; y < Resolution; y++)
                {
                    for (var x = 0; x < Resolution; x++)
                    {
                        var pixel = readTexture.GetPixel(x, y);

                        coverage += Mathf.Clamp01(pixel.a);
                    }
                }

                // Divide alpha coverage by square of resolution to get 0..1
                coverage /= Resolution * Resolution;
            }

            return(coverage);
        }
Exemplo n.º 13
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(renderTexture);
     SgtHelper.Destroy(readTexture);
 }
        public void RebuildMesh()
        {
            generatedMesh = SgtHelper.Destroy(generatedMesh);

            if (OriginalMesh != null)
            {
                // Duplicate original
                generatedMesh = Instantiate(OriginalMesh);
#if UNITY_EDITOR
                generatedMesh.hideFlags = HideFlags.DontSave;
#endif
                generatedMesh.name = OriginalMesh.name + " (Planet)";

                // Displace vertices
                var uv        = OriginalMesh.uv;
                var positions = OriginalMesh.vertices;
                var tangents  = OriginalMesh.tangents;
                var coords    = new List <Vector2>();

                for (var i = 0; i < uv.Length; i++)
                {
                    var position = positions[i];
                    var tangent  = tangents[i];
                    var coord    = default(Vector2);

                    if (position.y > 0.0f)
                    {
                        coord.x = -position.x;
                        coord.y = position.z;
                    }
                    else
                    {
                        coord.x = position.x;
                        coord.y = position.z;
                    }

                    /*
                     * position.y = 0.0f;
                     *
                     * if (position.sqrMagnitude < 0.0001f)
                     * {
                     *      var pos = position.normalized;
                     *      tangent = new Vector4(pos.x, pos.y, pos.z, -1.0f);
                     * }
                     */

                    coords.Add(coord * CapScale);
                    tangents[i] = tangent;
                }

                generatedMesh.SetUVs(1, coords);
                generatedMesh.tangents = tangents;
            }

            if (meshFilterSet == false)
            {
                meshFilter    = GetComponent <MeshFilter>();
                meshFilterSet = true;
            }

            meshFilter.sharedMesh = generatedMesh;
        }
Exemplo n.º 15
0
        protected override void BuildMesh(Mesh mesh, int asteroidIndex, int asteroidCount)
        {
            var positions = new Vector3[asteroidCount * 4];
            var colors    = new Color[asteroidCount * 4];
            var normals   = new Vector3[asteroidCount * 4];
            var tangents  = new Vector4[asteroidCount * 4];
            var coords1   = new Vector2[asteroidCount * 4];
            var coords2   = new Vector2[asteroidCount * 4];
            var indices   = new int[asteroidCount * 6];
            var maxWidth  = 0.0f;
            var maxHeight = 0.0f;

            for (var i = 0; i < asteroidCount; i++)
            {
                NextQuad(ref SgtBeltAsteroid.Temp, asteroidIndex + i);

                var offV     = i * 4;
                var offI     = i * 6;
                var radius   = SgtBeltAsteroid.Temp.Radius;
                var distance = SgtBeltAsteroid.Temp.OrbitDistance;
                var height   = SgtBeltAsteroid.Temp.Height;
                var uv       = tempCoords[SgtHelper.Mod(SgtBeltAsteroid.Temp.Variant, tempCoords.Count)];

                maxWidth  = Mathf.Max(maxWidth, distance + radius);
                maxHeight = Mathf.Max(maxHeight, height + radius);

                positions[offV + 0]             =
                    positions[offV + 1]         =
                        positions[offV + 2]     =
                            positions[offV + 3] = new Vector3(SgtBeltAsteroid.Temp.OrbitAngle, distance, SgtBeltAsteroid.Temp.OrbitSpeed);

                colors[offV + 0]             =
                    colors[offV + 1]         =
                        colors[offV + 2]     =
                            colors[offV + 3] = SgtBeltAsteroid.Temp.Color;

                normals[offV + 0] = new Vector3(-1.0f, 1.0f, 0.0f);
                normals[offV + 1] = new Vector3(1.0f, 1.0f, 0.0f);
                normals[offV + 2] = new Vector3(-1.0f, -1.0f, 0.0f);
                normals[offV + 3] = new Vector3(1.0f, -1.0f, 0.0f);

                tangents[offV + 0]             =
                    tangents[offV + 1]         =
                        tangents[offV + 2]     =
                            tangents[offV + 3] = new Vector4(SgtBeltAsteroid.Temp.Angle / Mathf.PI, SgtBeltAsteroid.Temp.Spin / Mathf.PI, 0.0f, 0.0f);

                coords1[offV + 0] = new Vector2(uv.x, uv.y);
                coords1[offV + 1] = new Vector2(uv.z, uv.y);
                coords1[offV + 2] = new Vector2(uv.x, uv.w);
                coords1[offV + 3] = new Vector2(uv.z, uv.w);

                coords2[offV + 0]             =
                    coords2[offV + 1]         =
                        coords2[offV + 2]     =
                            coords2[offV + 3] = new Vector2(radius, height);

                indices[offI + 0] = offV + 0;
                indices[offI + 1] = offV + 1;
                indices[offI + 2] = offV + 2;
                indices[offI + 3] = offV + 3;
                indices[offI + 4] = offV + 2;
                indices[offI + 5] = offV + 1;
            }

            mesh.vertices  = positions;
            mesh.colors    = colors;
            mesh.normals   = normals;
            mesh.tangents  = tangents;
            mesh.uv        = coords1;
            mesh.uv2       = coords2;
            mesh.triangles = indices;
            mesh.bounds    = new Bounds(Vector3.zero, new Vector3(maxWidth * 2.0f, maxHeight * 2.0f, maxWidth * 2.0f));
        }
Exemplo n.º 16
0
        public void UpdateMaterial()
        {
            if (material == null)
            {
                material = SgtHelper.CreateTempMaterial("Prominence (Generated)", SgtHelper.ShaderNamePrefix + "Prominence");

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

                        if (model != null)
                        {
                            model.SetMaterial(material);
                        }
                    }
                }
            }

            var color = SgtHelper.Premultiply(SgtHelper.Brighten(Color, Brightness));

            material.renderQueue = RenderQueue;

            material.SetTexture(SgtShader._MainTex, MainTex);
            material.SetColor(SgtShader._Color, color);
            material.SetVector(SgtShader._WorldPosition, transform.position);

            SgtHelper.SetTempMaterial(material);

            if (FadeEdge == true)
            {
                SgtHelper.EnableKeyword("SGT_A");

                material.SetFloat(SgtShader._FadePower, FadePower);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_A");
            }

            if (ClipNear == true)
            {
                SgtHelper.EnableKeyword("SGT_B");

                material.SetFloat(SgtShader._ClipPower, ClipPower);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_B");
            }

            if (Distort == true)
            {
                SgtHelper.EnableKeyword("SGT_C", material);                 // Distort

                material.SetTexture(SgtShader._DistortTex, DistortTex);
                material.SetVector(SgtShader._DistortScale, new Vector2(DistortScaleX, DistortScaleY));
                material.SetFloat(SgtShader._DistortStrength, DistortStrength);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_C", material);                 // Distort
            }

            if (Detail == true)
            {
                SgtHelper.EnableKeyword("SGT_D", material);                 // Detail

                material.SetTexture(SgtShader._DetailTex, DetailTex);
                material.SetVector(SgtShader._DetailScale, new Vector2(DetailScaleX, DetailScaleY));
                material.SetFloat(SgtShader._DetailStrength, DetailStrength);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_D", material);                 // Detail
            }
        }
Exemplo n.º 17
0
        private void AddToDelta()
        {
            // Get delta from fingers
            var fingers = SgtInputManager.GetFingers(true);
            var deltaXY = SgtInputManager.GetScaledDelta(fingers) * PanSensitivity;
            var deltaZ  = (SgtInputManager.GetPinchScale(fingers, WheelSensitivity) - 1.0f) * PinchSensitivity;

            if (fingers.Count < 2)
            {
                deltaXY = Vector2.zero;
            }

            // Add delta from keyboard
            deltaXY.x += Input.GetAxisRaw("Horizontal") * KeySensitivity * Time.deltaTime;
            deltaZ    += Input.GetAxisRaw("Vertical") * KeySensitivity * Time.deltaTime;

            if (SlowOnProximity == true)
            {
                var distance = float.PositiveInfinity;

                if (SgtHelper.OnCalculateDistance != null)
                {
                    SgtHelper.OnCalculateDistance(transform.position, ref distance);
                }

                if (distance < SlowDistanceMax)
                {
                    var distance01 = Mathf.InverseLerp(SlowDistanceMin, SlowDistanceMax, distance);
                    var multiplier = Mathf.Lerp(SlowMultiplier, 1.0f, distance01);

                    deltaXY *= multiplier;
                    deltaZ  *= multiplier;
                }
            }

            // Store old position
            var oldPosition = transform.position;

            // Translate
            transform.Translate(deltaXY.x, deltaXY.y, deltaZ, Space.Self);

            // Add to remaining
            var acceleration = transform.position - oldPosition;

            remainingDelta += acceleration;

            // Revert position
            transform.position = oldPosition;

            // Rotate to acceleration?
            if (Target != null && TargetRotation != RotationType.None && acceleration != Vector3.zero)
            {
                var factor   = SgtHelper.DampenFactor(TargetDampening, Time.deltaTime);
                var rotation = Target.transform.rotation;

                switch (TargetRotation)
                {
                case RotationType.Acceleration:
                {
                    rotation = Quaternion.FromToRotation(Target.transform.forward, acceleration);
                }
                break;

                case RotationType.MainCamera:
                {
                    var camera = Camera.main;

                    if (camera != null)
                    {
                        rotation = camera.transform.rotation;
                    }
                }
                break;
                }

                Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, rotation, factor);
                Target.angularVelocity    = Vector3.Lerp(Target.angularVelocity, Vector3.zero, factor);
            }
        }
Exemplo n.º 18
0
        public void UpdateMaterial()
        {
            if (material == null)
            {
                material = SgtHelper.CreateTempMaterial("Prominence (Generated)", SgtHelper.ShaderNamePrefix + "Prominence");
            }

            material.renderQueue = renderQueue;

            material.SetTexture(SgtShader._MainTex, mainTex);
            material.SetColor(SgtShader._Color, SgtHelper.Premultiply(SgtHelper.Brighten(this.color, brightness)));
            material.SetVector(SgtShader._WorldPosition, transform.position);

            SgtHelper.SetTempMaterial(material);

            if (fadeEdge == true)
            {
                SgtHelper.EnableKeyword("SGT_A");

                material.SetFloat(SgtShader._FadePower, fadePower);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_A");
            }

            if (clipNear == true)
            {
                SgtHelper.EnableKeyword("SGT_B");

                material.SetFloat(SgtShader._ClipPower, clipPower);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_B");
            }

            if (distort == true)
            {
                SgtHelper.EnableKeyword("SGT_C", material);                 // Distort

                material.SetTexture(SgtShader._DistortTex, distortTex);
                material.SetVector(SgtShader._DistortScale, new Vector2(distortScaleX, distortScaleY));
                material.SetFloat(SgtShader._DistortStrength, distortStrength);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_C", material);                 // Distort
            }

            if (detail == true)
            {
                SgtHelper.EnableKeyword("SGT_D", material);                 // Detail

                material.SetTexture(SgtShader._DetailTex, detailTex);
                material.SetVector(SgtShader._DetailScale, new Vector2(detailScaleX, detailScaleY));
                material.SetFloat(SgtShader._DetailStrength, detailStrength);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_D", material);                 // Detail
            }
        }
Exemplo n.º 19
0
        public void UpdateDebris()
        {
            if (target != null && cellCount > 0.0f && prefabs != null && debrisCountTarget > 0)
            {
                var cellSize   = (long)System.Math.Ceiling(hideDistance / cellCount);
                var worldPoint = target.position - transform.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 SgtLongBounds(centerX, centerY, centerZ, cellCount);

                if (newBounds != bounds)
                {
                    var probability = debrisCountTarget / (cellSize * cellSize * cellSize);
                    var cellMin     = cellSize * (0.5f - cellNoise);
                    var cellMax     = 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)
                                {
                                    SgtHelper.BeginRandomSeed(seed, x, y, z);
                                    {
                                        // Can debris potentially spawn in this cell?
                                        if (Random.value < probability)
                                        {
                                            var debrisPoint = default(Vector3);

                                            debrisPoint.x = x * cellSize + Random.Range(cellMin, cellMax);
                                            debrisPoint.y = y * cellSize + Random.Range(cellMin, cellMax);
                                            debrisPoint.z = z * cellSize + Random.Range(cellMin, cellMax);

                                            // 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 (spawnedDebris != null)
                    {
                        for (var i = spawnedDebris.Count - 1; i >= 0; i--)
                        {
                            var debris = spawnedDebris[i];

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

                UpdateDebrisScale(target.position);
            }
            else
            {
                ClearDebris();
            }
        }
Exemplo n.º 20
0
        public void UpdateMesh()
        {
            if (mesh == null)
            {
                mesh = SgtHelper.CreateTempMesh("Plane");
            }
            else
            {
                mesh.Clear(false);
            }

            if (planeDetail >= 2)
            {
                var detail    = Mathf.Min(planeDetail, SgtHelper.QuadsPerMesh / 2);                 // Limit the amount of vertices that get made
                var positions = new Vector3[detail * 2 + 2];
                var normals   = new Vector3[detail * 2 + 2];
                var coords1   = new Vector2[detail * 2 + 2];
                var coords2   = new Vector2[detail * 2 + 2];
                var indices   = new int[detail * 6];
                var angleStep = SgtHelper.Divide(Mathf.PI * 2.0f, detail);
                var coordStep = SgtHelper.Reciprocal(detail);

                for (var i = 0; i <= detail; i++)
                {
                    var coord = coordStep * i;
                    var angle = angleStep * i;
                    var sin   = Mathf.Sin(angle);
                    var cos   = Mathf.Cos(angle);
                    var offV  = i * 2;

                    positions[offV + 0] = new Vector3(sin * radiusMin, 0.0f, cos * radiusMin);
                    positions[offV + 1] = new Vector3(sin * radiusMax, 0.0f, cos * radiusMax);

                    normals[offV + 0] = Vector3.up;
                    normals[offV + 1] = Vector3.up;

                    coords1[offV + 0] = new Vector2(0.0f, coord * radiusMin);
                    coords1[offV + 1] = new Vector2(1.0f, coord * radiusMax);

                    coords2[offV + 0] = new Vector2(radiusMin, 0.0f);
                    coords2[offV + 1] = new Vector2(radiusMax, 0.0f);
                }

                for (var i = 0; i < detail; i++)
                {
                    var offV = i * 2;
                    var offI = i * 6;

                    indices[offI + 0] = offV + 0;
                    indices[offI + 1] = offV + 1;
                    indices[offI + 2] = offV + 2;
                    indices[offI + 3] = offV + 3;
                    indices[offI + 4] = offV + 2;
                    indices[offI + 5] = offV + 1;
                }

                mesh.vertices  = positions;
                mesh.normals   = normals;
                mesh.uv        = coords1;
                mesh.uv2       = coords2;
                mesh.triangles = indices;
            }
        }
Exemplo n.º 21
0
 protected virtual void Start()
 {
     // Upgrade scene
     // NOTE: This must be done in Start because when done in OnEnable this fails to dirty the scene
     SgtHelper.DestroyOldGameObjects(transform, "Cloudsphere Model");
 }
        public void UpdateMesh()
        {
            if (Segments > 0 && SegmentDetail > 0 && RadiusDetail > 0)
            {
                if (generatedMesh == null)
                {
                    generatedMesh = SgtHelper.CreateTempMesh("Ring Mesh (Generated)");

                    ApplyMesh();
                }

                var slices    = SegmentDetail + 1;
                var rings     = RadiusDetail + 1;
                var total     = slices * rings * 2;
                var positions = new Vector3[total];
                var coords1   = new Vector2[total];
                var coords2   = new Vector2[total];
                var colors    = new Color[total];
                var indices   = new int[SegmentDetail * RadiusDetail * 6];
                var yawStep   = (Mathf.PI * 2.0f) / Segments / SegmentDetail;
                var sliceStep = 1.0f / SegmentDetail;
                var ringStep  = 1.0f / RadiusDetail;

                for (var slice = 0; slice < slices; slice++)
                {
                    var a = yawStep * slice;
                    var x = Mathf.Sin(a);
                    var z = Mathf.Cos(a);

                    for (var ring = 0; ring < rings; ring++)
                    {
                        var v       = rings * slice + ring;
                        var slice01 = sliceStep * slice;
                        var ring01  = ringStep * ring;
                        var radius  = Mathf.Lerp(RadiusMin, RadiusMax, ring01);

                        positions[v] = new Vector3(x * radius, 0.0f, z * radius);
                        colors[v]    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                        coords1[v]   = new Vector2(ring01, slice01);
                        coords2[v]   = new Vector2(radius, slice01 * radius);
                    }
                }

                for (var slice = 0; slice < SegmentDetail; slice++)
                {
                    for (var ring = 0; ring < RadiusDetail; ring++)
                    {
                        var i  = (slice * RadiusDetail + ring) * 6;
                        var v0 = slice * rings + ring;
                        var v1 = v0 + rings;

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

                generatedMesh.Clear(false);
                generatedMesh.vertices  = positions;
                generatedMesh.colors    = colors;
                generatedMesh.uv        = coords1;
                generatedMesh.uv2       = coords2;
                generatedMesh.triangles = indices;
                generatedMesh.RecalculateNormals();
                generatedMesh.RecalculateBounds();

                var bounds = generatedMesh.bounds;

                generatedMesh.bounds = SgtHelper.NewBoundsCenter(bounds, bounds.center + bounds.center.normalized * BoundsShift);
            }

            if (Shadow != null)
            {
                Shadow.RadiusMin = RadiusMin;
                Shadow.RadiusMax = RadiusMax;
            }
        }
Exemplo n.º 23
0
 protected override void EndQuads()
 {
     SgtHelper.EndRandomSeed();
 }
        protected override void NextQuad(ref SgtBeltAsteroid asteroid, int asteroidIndex)
        {
            var distance01 = SgtHelper.Sharpness(Random.value * Random.value, RadiusBias);

            asteroid.Variant       = Random.Range(int.MinValue, int.MaxValue);
            asteroid.Color         = AsteroidColors.Evaluate(Random.value);
            asteroid.Radius        = Mathf.Lerp(AsteroidRadiusMin, AsteroidRadiusMax, SgtHelper.Sharpness(Random.value, AsteroidRadiusBias));
            asteroid.Height        = Mathf.Pow(Random.value, ThicknessBias) * Thickness * (Random.value < 0.5f ? -0.5f : 0.5f);
            asteroid.Angle         = Random.Range(0.0f, Mathf.PI * 2.0f);
            asteroid.Spin          = Random.Range(-AsteroidSpin, AsteroidSpin);
            asteroid.OrbitAngle    = Random.Range(0.0f, Mathf.PI * 2.0f);
            asteroid.OrbitSpeed    = Mathf.Lerp(InnerSpeed, OuterSpeed, distance01);
            asteroid.OrbitDistance = Mathf.Lerp(InnerRadius, OuterRadius, distance01);

            asteroid.OrbitSpeed += Random.Range(-SpeedSpread, SpeedSpread) * asteroid.OrbitSpeed;
        }
Exemplo n.º 25
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(generatedMesh);
 }
Exemplo n.º 26
0
        public void Draw(SgtFloatingOrbit orbit)
        {
            if (cachedMeshFilterSet == false)
            {
                cachedMeshFilter    = GetComponent <MeshFilter>();
                cachedMeshFilterSet = true;
            }

            if (visualMesh == null)
            {
                visualMesh = cachedMeshFilter.sharedMesh = SgtHelper.CreateTempMesh("Orbit Visual");
            }

            positions.Clear();
            coords.Clear();
            colors.Clear();
            indices.Clear();

            var camera = default(SgtFloatingCamera);

            if (SgtFloatingCamera.TryGetCamera(gameObject.layer, ref camera) == true)
            {
                var position = camera.CalculatePosition(ref orbit.ParentPoint.Position);
                var rotation = orbit.ParentPoint.transform.rotation * Quaternion.Euler(orbit.Tilt);
                var r1       = orbit.Radius;
                var r2       = orbit.Radius * (1.0f - orbit.Oblateness);
                var i1       = r1 - Thickness * 0.5;
                var i2       = r2 - Thickness * 0.5;
                var o1       = i1 + Thickness;
                var o2       = i2 + Thickness;
                var step     = 360.0 / Points;
                var stepI    = 1.0f / (Points - 1);

                for (var i = 0; i < Points; i++)
                {
                    var angle = (orbit.Angle - i * step) * Mathf.Deg2Rad;
                    var sin   = System.Math.Sin(angle);
                    var cos   = System.Math.Cos(angle);

                    // Inner
                    {
                        var point   = position;
                        var offsetX = sin * i1;
                        var offsetY = 0.0;
                        var offsetZ = cos * i2;

                        SgtFloatingOrbit.Rotate(rotation, ref offsetX, ref offsetY, ref offsetZ);

                        point.x += (float)offsetX;
                        point.y += (float)offsetY;
                        point.z += (float)offsetZ;

                        point = transform.InverseTransformPoint(point);

                        positions.Add(point);
                    }

                    // Outer
                    {
                        var point   = position;
                        var offsetX = sin * o1;
                        var offsetY = 0.0;
                        var offsetZ = cos * o2;

                        SgtFloatingOrbit.Rotate(rotation, ref offsetX, ref offsetY, ref offsetZ);

                        point.x += (float)offsetX;
                        point.y += (float)offsetY;
                        point.z += (float)offsetZ;

                        point = transform.InverseTransformPoint(point);

                        positions.Add(point);
                    }

                    var u     = stepI * i;
                    var color = Colors.Evaluate(u);

                    coords.Add(new Vector2(u, 0.0f));
                    coords.Add(new Vector2(u, 1.0f));

                    colors.Add(color);
                    colors.Add(color);
                }

                for (var i = 0; i < Points; i++)
                {
                    var indexA = i * 2 + 0;
                    var indexB = i * 2 + 1;
                    var indexC = i * 2 + 2; indexC %= Points * 2;
                    var indexD = i * 2 + 3; indexD %= Points * 2;

                    indices.Add(indexA);
                    indices.Add(indexB);
                    indices.Add(indexC);
                    indices.Add(indexD);
                    indices.Add(indexC);
                    indices.Add(indexB);
                }

                visualMesh.SetVertices(positions);
                visualMesh.SetTriangles(indices, 0);
                visualMesh.SetUVs(0, coords);
                visualMesh.SetColors(colors);
                visualMesh.RecalculateBounds();
            }
        }
Exemplo n.º 27
0
        public virtual void UpdateMaterial()
        {
            if (material == null)
            {
                material = SgtHelper.CreateTempMaterial("Ring (Generated)", SgtHelper.ShaderNamePrefix + "Ring");

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

                        if (model != null)
                        {
                            model.SetMaterial(material);
                        }
                    }
                }
            }

            var color = SgtHelper.Brighten(Color, Brightness);

            material.renderQueue = RenderQueue;

            material.SetColor(SgtShader._Color, color);
            material.SetTexture(SgtShader._MainTex, MainTex);

            if (Detail == true)
            {
                SgtHelper.EnableKeyword("SGT_B", material);                 // Detail

                material.SetTexture(SgtShader._DetailTex, DetailTex);
                material.SetVector(SgtShader._DetailOffset, DetailOffset);
                material.SetVector(SgtShader._DetailScale, new Vector2(DetailScaleX, DetailScaleY));
                material.SetFloat(SgtShader._DetailTwist, DetailTwist);
                material.SetFloat(SgtShader._DetailTwistBias, DetailTwistBias);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_B", material);                 // Detail
            }

            if (Near == true)
            {
                SgtHelper.EnableKeyword("SGT_C", material);                 // Near

                material.SetTexture(SgtShader._NearTex, NearTex);
                material.SetFloat(SgtShader._NearScale, SgtHelper.Reciprocal(NearDistance));
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_C", material);                 // Near
            }

            if (Lit == true)
            {
                material.SetTexture(SgtShader._LightingTex, LightingTex);
                material.SetColor(SgtShader._AmbientColor, AmbientColor);
            }

            if (Scattering == true)
            {
                SgtHelper.EnableKeyword("SGT_A", material);                 // Scattering

                material.SetFloat(SgtShader._ScatteringMie, ScatteringMie * ScatteringMie);
            }
            else
            {
                SgtHelper.DisableKeyword("SGT_A", material);                 // Scattering
            }
        }
Exemplo n.º 28
0
        public void MakeEditableCopyContext()
        {
            var customBelt = MakeEditableCopy(gameObject.layer, transform.parent, transform.localPosition, transform.localRotation, transform.localScale);

            SgtHelper.SelectAndPing(customBelt);
        }
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(generatedTexture);
 }
Exemplo n.º 30
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(material);
 }