private void WritePixel(float u, int x)
        {
            var fade  = SgtHelper.Saturate(SgtEase.Evaluate(ease, SgtHelper.Sharpness(u, sharpness)));
            var color = new Color(fade, fade, fade, fade);

            generatedTexture.SetPixel(x, 0, color);
        }
예제 #2
0
        private void WritePixel(float u, int x)
        {
            var e     = SgtEase.Evaluate(Ease, SgtHelper.Sharpness(u, Sharpness));
            var color = new Color(1.0f, 1.0f, 1.0f, e);

            generatedTexture.SetPixel(x, 0, color);
        }
예제 #3
0
        private void WritePixel(float u, float v, int x, int y)
        {
            var noise      = u * NoisePoints;
            var noiseIndex = (int)noise;
            var noiseFrac  = noise % 1.0f;
            var noiseA     = noisePoints[(noiseIndex + 0) % NoisePoints];
            var noiseB     = noisePoints[(noiseIndex + 1) % NoisePoints];
            var noiseC     = noisePoints[(noiseIndex + 2) % NoisePoints];
            var noiseD     = noisePoints[(noiseIndex + 3) % NoisePoints];
            var color      = MiddleColor;

            if (v < MiddlePoint)
            {
                color.a = SgtEase.Evaluate(BottomEase, SgtHelper.Sharpness(Mathf.InverseLerp(0.0f, MiddlePoint, v), BottomSharpness));
            }
            else
            {
                color.a = SgtEase.Evaluate(TopEase, SgtHelper.Sharpness(Mathf.InverseLerp(1.0f, MiddlePoint, v), TopSharpness));
            }

            var middle = SgtEase.Evaluate(MiddleEase, SgtHelper.Sharpness(1.0f - v, MiddleSharpness));

            color.a *= SgtHelper.HermiteInterpolate(noiseA, noiseB, noiseC, noiseD, noiseFrac);

            color.r *= middle * color.a;
            color.g *= middle * color.a;
            color.b *= middle * color.a;
            color.a *= 1.0f - middle;

            generatedTexture.SetPixel(x, y, color);
        }
예제 #4
0
        private float GetSky(Camera camera)
        {
            if (Lit == true && Night == true)
            {
                var mask   = 1 << gameObject.layer;
                var lights = SgtLight.Find(Lit, mask);

                var lighting        = 0.0f;
                var cameraDirection = (camera.transform.position - transform.position).normalized;

                for (var i = 0; i < lights.Count && i < 2; i++)
                {
                    var light     = lights[i];
                    var position  = default(Vector3);
                    var direction = default(Vector3);
                    var color     = default(Color);

                    SgtLight.Calculate(light, transform.position, null, null, ref position, ref direction, ref color);

                    var dot     = Vector3.Dot(direction, cameraDirection) * 0.5f + 0.5f;
                    var night01 = Mathf.InverseLerp(NightEnd, NightStart, dot);
                    var night   = SgtEase.Evaluate(NightEase, 1.0f - Mathf.Pow(night01, NightPower));

                    if (night > lighting)
                    {
                        lighting = night;
                    }
                }

                return(Mathf.Lerp(NightSky, Sky, lighting));
            }

            return(Sky);
        }
예제 #5
0
        private void WritePixel(float u, int x)
        {
            var fade  = SgtHelper.Saturate(SgtEase.Evaluate(ease, SgtHelper.Sharpness(Mathf.InverseLerp(offset, 1.0f, u), sharpness)));
            var color = new Color(fade, fade, fade, fade);

            generatedTexture.SetPixel(x, 0, color);
        }
예제 #6
0
        public override float GetDensity(Vector3 worldPoint)
        {
            var distance   = transform.InverseTransformPoint(worldPoint).magnitude;
            var distance01 = Mathf.InverseLerp(RadiusOuter, RadiusInner, distance);

            return(SgtHelper.Sharpness(SgtEase.Evaluate(ease, distance01), sharpness));
        }
        public override float GetDensity(Vector3 worldPoint)
        {
            var localPoint = transform.InverseTransformPoint(worldPoint);
            var distance   = localPoint.magnitude;
            var distance01 = Mathf.InverseLerp(Radius, 0.0f, distance);

            return(SgtHelper.Sharpness(SgtEase.Evaluate(Ease, distance01), Sharpness));
        }
        private void WritePixel(float u, int x)
        {
            var rim   = SgtEase.Evaluate(rimEase, Mathf.Pow(1.0f - u, rimPower));
            var color = Color.Lerp(Color.white, rimColor, rim * rimColor.a);

            color.a = 1.0f - Mathf.Pow(1.0f - Mathf.Pow(u, alphaFade), alphaDensity);

            generatedTexture.SetPixel(x, 0, SgtHelper.Saturate(color));
        }
예제 #9
0
        private void WritePixel(float u, int x)
        {
            var rim   = 1.0f - SgtEase.Evaluate(RimEase, 1.0f - Mathf.Pow(1.0f - u, RimPower));
            var color = Color.Lerp(Color.white, RimColor, rim * RimColor.a);

            color.a = 1.0f - Mathf.Pow(1.0f - Mathf.Pow(u, AlphaFade), AlphaDensity);

            generatedTexture.SetPixel(x, 0, color);
        }
예제 #10
0
        public override float GetDensity(Vector3 worldPoint)
        {
            var localPoint = transform.InverseTransformPoint(worldPoint);
            var distanceXZ = Mathf.Sqrt(localPoint.x * localPoint.x + localPoint.z * localPoint.z) - Radius;
            var distanceY  = localPoint.y;
            var distance   = Mathf.Sqrt(distanceXZ * distanceXZ + distanceY * distanceY);
            var distance01 = Mathf.InverseLerp(Thickness, 0.0f, distance);

            return(SgtHelper.Sharpness(SgtEase.Evaluate(Ease, distance01), Sharpness));
        }
        private void WritePixel(Texture2D texture2D, float u, int x, Color baseColor, SgtEase.Type ease, float colorSharpness, float alphaSharpness)
        {
            var colorU = SgtHelper.Sharpness(u, colorSharpness); colorU = SgtEase.Evaluate(ease, colorU);
            var alphaU = SgtHelper.Sharpness(u, alphaSharpness); alphaU = SgtEase.Evaluate(ease, alphaU);
            var color  = Color.Lerp(baseColor, HorizonColor, colorU);

            color.a = alphaU;

            texture2D.SetPixel(x, 0, color);
        }
예제 #12
0
        public override float GetDensity(Vector3 worldPoint)
        {
            var localPoint = transform.InverseTransformPoint(worldPoint);
            var distanceX  = Mathf.InverseLerp(Extents.x, 0.0f, Mathf.Abs(localPoint.x));
            var distanceY  = Mathf.InverseLerp(Extents.y, 0.0f, Mathf.Abs(localPoint.y));
            var distanceZ  = Mathf.InverseLerp(Extents.z, 0.0f, Mathf.Abs(localPoint.z));
            var distance01 = Mathf.Min(distanceX, Mathf.Min(distanceY, distanceZ));

            return(SgtHelper.Sharpness(SgtEase.Evaluate(Ease, distance01), Sharpness));
        }
        private void WritePixel(float u, int x)
        {
            var color = Color.white;

            color.r *= 1.0f - SgtEase.Evaluate(Ease, SgtHelper.Sharpness(u, SharpnessR));
            color.g *= 1.0f - SgtEase.Evaluate(Ease, SgtHelper.Sharpness(u, SharpnessG));
            color.b *= 1.0f - SgtEase.Evaluate(Ease, SgtHelper.Sharpness(u, SharpnessB));
            color.a  = color.grayscale;

            generatedTexture.SetPixel(x, 0, color);
        }
예제 #14
0
        private void WritePixel(float u, int x)
        {
            var sunsetU = Mathf.InverseLerp(SunsetEnd, SunsetStart, u);
            var color   = default(Color);

            color.r = SgtEase.Evaluate(SunsetEase, 1.0f - SgtHelper.Sharpness(sunsetU, SunsetSharpnessR));
            color.g = SgtEase.Evaluate(SunsetEase, 1.0f - SgtHelper.Sharpness(sunsetU, SunsetSharpnessG));
            color.b = SgtEase.Evaluate(SunsetEase, 1.0f - SgtHelper.Sharpness(sunsetU, SunsetSharpnessB));
            color.a = 0.0f;

            generatedTexture.SetPixel(x, 0, color);
        }
예제 #15
0
        private void WritePixel(float u, float v, int x, int y)
        {
            var ray        = Mathf.Abs(v * 2.0f - 1.0f); ray = rayleigh * ray * ray;
            var mie        = Mathf.Pow(v, this.mie);
            var scattering = ray + mie * (1.0f - ray);
            var sunsetU    = Mathf.InverseLerp(sunsetEnd, sunsetStart, u);
            var color      = default(Color);

            color.r = 1.0f - SgtEase.Evaluate(sunsetEase, SgtHelper.Sharpness(sunsetU, sunsetSharpnessR));
            color.g = 1.0f - SgtEase.Evaluate(sunsetEase, SgtHelper.Sharpness(sunsetU, sunsetSharpnessG));
            color.b = 1.0f - SgtEase.Evaluate(sunsetEase, SgtHelper.Sharpness(sunsetU, sunsetSharpnessB));
            color.a = (color.r + color.g + color.b) / 3.0f;

            generatedTexture.SetPixel(x, y, SgtHelper.Saturate(color * scattering));
        }
예제 #16
0
        private void WritePixel(Texture2D texture2D, float u, int x, Color baseColor, SgtEase.Type ease, float colorSharpness, float alphaSharpness)
        {
            var colorU = SgtHelper.Sharpness(u, colorSharpness); colorU = SgtEase.Evaluate(ease, colorU);
            var alphaU = SgtHelper.Sharpness(u, alphaSharpness); alphaU = SgtEase.Evaluate(ease, alphaU);

            var color = Color.Lerp(baseColor, horizonColor, colorU);

            color.a = alphaU;

            color.r = Mathf.Clamp01(color.r);
            color.g = Mathf.Clamp01(color.g);
            color.b = Mathf.Clamp01(color.b);
            color.a = Mathf.Clamp01(color.a);

            texture2D.SetPixel(x, 0, SgtHelper.Saturate(color));
        }
예제 #17
0
        // Calculates the 0..1 depth between the eye and target
        public float Calculate(Vector3 eye, Vector3 target)
        {
            if (busy == true)
            {
                Debug.LogError("Calculate is being called recursively");

                return(0.0f);
            }

            var coverage = default(float);

            busy = true;
            {
                coverage = DoCalculate(eye, target);
            }
            busy = false;

            return(1.0f - SgtEase.Evaluate(Ease, 1.0f - coverage));
        }
        private void UpdateTexture()
        {
            if (generatedTexture == null)
            {
                generatedTexture = new Texture2D(64, 1, TextureFormat.RGB24, false);

                generatedTexture.wrapMode = TextureWrapMode.Clamp;
            }

            for (var i = 0; i < 64; i++)
            {
                var t = SgtEase.Evaluate(ease, SgtHelper.Sharpness(i / 63.0f, sharpness));

                generatedTexture.SetPixel(i, 0, Color.Lerp(shallow, deep, t));
            }

            generatedTexture.Apply();

            CachedPlanet.Properties.SetTexture(Shader.PropertyToID("_WaterGradient"), generatedTexture);
        }
예제 #19
0
        private float GetSky(Vector3 eye, float localDistance)
        {
            var height01 = Mathf.InverseLerp(OuterRadius, innerMeshRadius, localDistance);
            var mul      = outerDepthTex.GetPixelBilinear(height01 / (1.0f - outerFog), 0.0f).a;

            if (lit == true && night == true)
            {
                var mask   = 1 << gameObject.layer;
                var lights = SgtLight.Find(lit, mask, cachedTransform.position);

                var lighting        = 0.0f;
                var cameraDirection = (eye - cachedTransform.position).normalized;

                for (var i = 0; i < lights.Count && i < 2; i++)
                {
                    var light     = lights[i];
                    var position  = default(Vector3);
                    var direction = default(Vector3);
                    var color     = default(Color);

                    SgtLight.Calculate(light, cachedTransform.position, null, null, ref position, ref direction, ref color);

                    var dot     = Vector3.Dot(direction, cameraDirection) * 0.5f + 0.5f;
                    var night01 = Mathf.InverseLerp(nightEnd, nightStart, dot);
                    var night   = SgtEase.Evaluate(nightEase, 1.0f - Mathf.Pow(night01, nightPower));

                    if (night > lighting)
                    {
                        lighting = night;
                    }
                }

                return(Mathf.Lerp(nightSky, sky, lighting) * mul);
            }

            return(sky * mul);
        }