// TODO: Make this work correctly
    public override bool CalculateShadow()
    {
        if (base.CalculateShadow() == true)
        {
            var direction = default(Vector3);
            var position  = default(Vector3);
            var color     = default(Color);

            SgtHelper.CalculateLight(Light, transform.position, null, null, ref position, ref direction, ref color);

            var rotation = Quaternion.FromToRotation(direction, Vector3.back);

            SetVector(0, rotation * transform.right * transform.lossyScale.x * OuterRadius);
            SetVector(1, rotation * transform.up * transform.lossyScale.y * OuterRadius);
            SetVector(2, rotation * transform.forward * transform.lossyScale.z * OuterRadius);

            SortVectors();

            var spin  = Quaternion.LookRotation(Vector3.forward, new Vector2(-vectors[1].x, vectors[1].y));             // Orient the shadow ellipse
            var scale = SgtHelper.Reciprocal3(new Vector3(magnitudes[0], magnitudes[1], 1.0f));

            var shadowT = SgtHelper.Translation(-transform.position);
            var shadowR = SgtHelper.Rotation(spin * rotation);
            var shadowS = SgtHelper.Scaling(scale);

            Matrix = shadowS * shadowR * shadowT;
            Ratio  = SgtHelper.Divide(OuterRadius, OuterRadius - InnerRadius);

            return(true);
        }

        return(false);
    }
Beispiel #2
0
    public override bool CalculateShadow(ref Matrix4x4 matrix, ref float ratio)
    {
        if (base.CalculateShadow(ref matrix, ref ratio) == true)
        {
            var direction = default(Vector3);
            var position  = default(Vector3);
            var color     = default(Color);

            SgtHelper.CalculateLight(Light, transform.position, null, null, ref position, ref direction, ref color);

            var dot      = Vector3.Dot(direction, transform.up);
            var radiusXZ = (transform.lossyScale.x + transform.lossyScale.z) * 0.5f * RadiusMax;
            var radiusY  = transform.lossyScale.y * RadiusMax;
            var radius   = GetRadius(radiusY, radiusXZ, dot * Mathf.PI * 0.5f);
            var rotation = Quaternion.FromToRotation(direction, Vector3.back);
            var vector   = rotation * transform.up;
            var spin     = Quaternion.LookRotation(Vector3.forward, new Vector2(-vector.x, vector.y));             // Orient the shadow ellipse
            var scale    = SgtHelper.Reciprocal3(new Vector3(radiusXZ, radius, 1.0f));
            var shadowT  = SgtHelper.Translation(-transform.position);
            var shadowR  = SgtHelper.Rotation(spin * rotation);
            var shadowS  = SgtHelper.Scaling(scale);

            matrix = shadowS * shadowR * shadowT;
            ratio  = SgtHelper.Divide(RadiusMax, RadiusMax - RadiusMin);

            return(true);
        }

        return(false);
    }
    protected override float CalculateOuterPower(Vector3 cameraPosition, float clampedAltitude)
    {
        var cameraDir  = (cameraPosition - transform.position).normalized;
        var lightCount = 0;
        var maxLights  = 2;
        var strength   = 1.0f - clampedAltitude;

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

            if (SgtHelper.Enabled(light) == true && light.intensity > 0.0f && lightCount < maxLights)
            {
                var direction = default(Vector3);
                var position  = default(Vector3);
                var color     = default(Color);

                SgtHelper.CalculateLight(light, transform.position, null, null, ref position, ref direction, ref color);

                var dot      = Vector3.Dot(direction, cameraDir);
                var lighting = LightingBrightness.Evaluate(dot * 0.5f + 0.5f);

                clampedAltitude += (1.0f - lighting.a) * strength;
            }
        }

        return(base.CalculateOuterPower(cameraPosition, clampedAltitude));
    }
Beispiel #4
0
    public override bool CalculateShadow(ref Matrix4x4 matrix, ref float ratio)
    {
        if (base.CalculateShadow(ref matrix, ref ratio) == true)
        {
            if (Texture != null)
            {
                if (SgtHelper.Enabled(RingMesh) == true)
                {
                    RadiusMin = RingMesh.RadiusMin;
                    RadiusMax = RingMesh.RadiusMax;
                }

                var direction = default(Vector3);
                var position  = default(Vector3);
                var color     = default(Color);

                SgtHelper.CalculateLight(Light, transform.position, null, null, ref position, ref direction, ref color);

                var rotation = Quaternion.FromToRotation(direction, Vector3.back);
                var squash   = Vector3.Dot(direction, transform.up);                 // Find how squashed the ellipse is based on light direction
                var width    = transform.lossyScale.x * RadiusMax;
                var length   = transform.lossyScale.z * RadiusMax;
                var axis     = rotation * transform.up;                                                // Find the transformed up axis
                var spin     = Quaternion.LookRotation(Vector3.forward, new Vector2(-axis.x, axis.y)); // Orient the shadow ellipse
                var scale    = SgtHelper.Reciprocal3(new Vector3(width, length * Mathf.Abs(squash), 1.0f));
                var skew     = Mathf.Tan(SgtHelper.Acos(-squash));

                var shadowT = SgtHelper.Translation(-transform.position);
                var shadowR = SgtHelper.Rotation(spin * rotation);          // Spin the shadow so lines up with its tilt
                var shadowS = SgtHelper.Scaling(scale);                     // Scale the ring into an oval
                var shadowK = SgtHelper.ShearingZ(new Vector2(0.0f, skew)); // Skew the shadow so it aligns with the ring plane

                matrix = shadowS * shadowK * shadowR * shadowT;
                ratio  = SgtHelper.Divide(RadiusMax, RadiusMax - RadiusMin);

                return(true);
            }
        }

        return(false);
    }