protected virtual void RegenerateAtmosphereLut()
    {
        if (atmosphereLut == null || atmosphereLut.width != 1 || atmosphereLut.height != 64)
        {
            SgtHelper.Destroy(atmosphereLut);

            atmosphereLut = SgtHelper.CreateTempTeture2D(1, 64);
        }

        for (var y = 0; y < atmosphereLut.height; y++)
        {
            var t = y / (float)atmosphereLut.height;

            atmosphereLut.SetPixel(0, y, DensityColor.Evaluate(t));
        }

        atmosphereLut.wrapMode = TextureWrapMode.Clamp;
        atmosphereLut.Apply();
    }
    private void RegenerateRimLut()
    {
        if (rimLut == null || rimLut.width != 1 || rimLut.height != 64)
        {
            SgtHelper.Destroy(rimLut);

            rimLut = SgtHelper.CreateTempTeture2D(1, 64);
        }

        for (var y = 0; y < rimLut.height; y++)
        {
            var t = y / (float)rimLut.height;

            rimLut.SetPixel(0, y, RimColor.Evaluate(t));
        }

        rimLut.wrapMode = TextureWrapMode.Clamp;
        rimLut.Apply();
    }
    private void RegenerateLightingLut()
    {
        if (lightingLut == null || lightingLut.width != 1 || lightingLut.height != 64)
        {
            SgtHelper.Destroy(lightingLut);

            lightingLut = SgtHelper.CreateTempTeture2D(1, 64);
        }

        for (var y = 0; y < lightingLut.height; y++)
        {
            var t = y / (float)lightingLut.height;

            lightingLut.SetPixel(0, y, LightingBrightness.Evaluate(t) * LightingColor.Evaluate(t));
        }

        lightingLut.wrapMode = TextureWrapMode.Clamp;
        lightingLut.Apply();
    }
Beispiel #4
0
    protected virtual void OnDestroy()
    {
        if (Planes != null)
        {
            for (var i = Planes.Count - 1; i >= 0; i--)
            {
                SgtProminencePlane.MarkForDestruction(Planes[i]);
            }
        }

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

            SgtObjectPool <Mesh> .Add(Mesh);
        }

        SgtHelper.Destroy(Material);
    }
    protected virtual void OnDestroy()
    {
        for (var i = InnerRenderers.Count - 1; i >= 0; i--)
        {
            var innerRenderer = InnerRenderers[i];

            SgtHelper.RemoveMaterial(innerRenderer, innerMaterial);
        }

        SgtHelper.Destroy(atmosphereLut);
        SgtHelper.Destroy(outerMaterial);
        SgtHelper.Destroy(innerMaterial);

        for (var i = outers.Count - 1; i >= 0; i--)
        {
            SgtCoronaOuter.MarkForDestruction(outers[i]);
        }

        outers.Clear();
    }
Beispiel #6
0
    public void UpdateTexture()
    {
        if (Width > 0 && Height > 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("Jovian Scattering (Generated)", Width, Height, Format);

                generatedTexture.wrapMode = TextureWrapMode.Clamp;

                UpdateApply();
            }

            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();
        }
    }
Beispiel #7
0
    private void ValidateTexture(ref Texture2D texture2D, string createName)
    {
        // Destroy if invalid
        if (texture2D != null)
        {
            if (texture2D.width != Width || texture2D.height != 1 || texture2D.format != Format)
            {
                texture2D = SgtHelper.Destroy(texture2D);
            }
        }

        // Create?
        if (texture2D == null)
        {
            texture2D = SgtHelper.CreateTempTexture2D(createName, Width, 1, Format);

            texture2D.wrapMode = TextureWrapMode.Clamp;

            UpdateApply();
        }
    }
Beispiel #8
0
    public void RebuildMesh()
    {
        displacedMesh = SgtHelper.Destroy(displacedMesh);

        if (OriginalMesh != null)
        {
#if UNITY_EDITOR
            SgtHelper.MakeTextureReadable(HeightTex);
#endif
            // Duplicate original
            displacedMesh = Instantiate(OriginalMesh);
#if UNITY_EDITOR
            displacedMesh.hideFlags = HideFlags.DontSave;
#endif
            displacedMesh.name = OriginalMesh.name + " (Displaced)";

            // Displace vertices
            var positions = OriginalMesh.vertices;

            for (var i = 0; i < positions.Length; i++)
            {
                var direction = positions[i].normalized;

                positions[i] = direction * GetSurfaceHeightLocal(direction);
            }

            displacedMesh.vertices = positions;

            displacedMesh.RecalculateBounds();
        }

        // Apply displaced mesh
        if (meshFilter == null)
        {
            meshFilter = GetComponent <MeshFilter>();
        }

        meshFilter.sharedMesh = displacedMesh;
    }
Beispiel #9
0
    public void UpdateTexture()
    {
        if (Width > 0)
        {
            // Destroy if invalid
            if (generatedTexture != null)
            {
                if (generatedTexture.width != Width || generatedTexture.height != 1 || generatedTexture.format != Format)
                {
                    generatedTexture = SgtHelper.Destroy(generatedTexture);
                }
            }

            // Create?
            if (generatedTexture == null)
            {
                generatedTexture = SgtHelper.CreateTempTexture2D("Flare Texture (Generated)", Width, 1, Format);

                generatedTexture.wrapMode = TextureWrapMode.Clamp;

                if (generatedMaterial != null)
                {
                    generatedMaterial.SetTexture("_MainTex", generatedTexture);
                }
            }

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

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

                WriteTexture(v, x);
            }

            generatedTexture.Apply();
        }
    }
Beispiel #10
0
    protected virtual void Update()
    {
        if (Terrain != null)
        {
            if (SgtTerrain.TickOverbudget == true)
            {
                return;
            }

            UpdateMaterialDirty();

            updateTime -= Time.deltaTime;
#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                updateTime = 0.0f;
            }
#endif
            if (updateTime <= 0.0f)
            {
                updateTime = Random.Range(0.5f, 1.0f);

                if (Terrain != null)
                {
                    UpdateSplitMerge();
                }
                else
                {
                    SgtHelper.Destroy(gameObject);
                }
            }
        }
        else
        {
            Pool(this);
        }
    }
Beispiel #11
0
    public void UpdateTextures()
    {
        if (Width > 0)
        {
            // Destroy if invalid
            if (generatedTexture != null)
            {
                if (generatedTexture.width != Width || generatedTexture.height != 1 || generatedTexture.format != Format)
                {
                    generatedTexture = SgtHelper.Destroy(generatedTexture);
                }
            }

            // Create?
            if (generatedTexture == null)
            {
                generatedTexture = SgtHelper.CreateTempTexture2D("Jovian Depth (Generated)", Width, 1, Format);

                generatedTexture.wrapMode = TextureWrapMode.Clamp;

                UpdateApply();
            }

            var color = Color.clear;
            var stepX = 1.0f / (Width - 1);

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

                WriteTexture(u, x);
            }

            generatedTexture.Apply();
        }
    }
Beispiel #12
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(material);
 }
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(penumbraLut);
 }
Beispiel #14
0
    protected virtual void OnDestroy()
    {
        RemoveMaterial();

        SgtHelper.Destroy(depthMaterial);
    }
    protected override void OnDestroy()
    {
        base.OnDestroy();

        SgtHelper.Destroy(lightingLut);
    }
Beispiel #16
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(generatedTexture);
 }
Beispiel #17
0
 protected virtual void OnDestroy()
 {
     mesh = SgtHelper.Destroy(mesh);
 }
Beispiel #18
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(generatedInnerTexture);
     SgtHelper.Destroy(generatedOuterTexture);
 }
Beispiel #19
0
 protected virtual void OnDestroy()
 {
     SgtHelper.Destroy(renderTexture);
     SgtHelper.Destroy(readTexture);
 }
Beispiel #20
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);
    }