コード例 #1
0
        private void CalculateOcclusion(int layers, Vector4 eye, Vector4 tgt, ref float flareOcclusion)
        {
            if (occlusion > 0.0f && mainTex != null && SgtOcclusion.IsValid(flareOcclusion, layers, gameObject) == true)
            {
                if (cachedRingMesh == null)
                {
                    cachedRingMesh = GetComponent <SgtRingMesh>();
                }

                if (cachedRingMesh != null)
                {
                    var plane = new Plane(transform.up, transform.position);
                    var ray   = new Ray(eye, tgt - eye);
                    var dist  = default(float);

                    if (plane.Raycast(ray, out dist) == true)
                    {
                        var point = transform.InverseTransformPoint(ray.GetPoint(dist));
                        var u     = Mathf.InverseLerp(cachedRingMesh.RadiusMin, cachedRingMesh.RadiusMax, Vector3.Magnitude(point));

                        flareOcclusion += mainTex.GetPixelBilinear(u, 0.5f).a *Mathf.Clamp01(occlusion) * (1.0f - flareOcclusion);
                    }
                }
            }
        }
コード例 #2
0
        private void CalculateOcclusion(int layers, Vector4 worldEye, Vector4 worldTgt, ref float occlusion)
        {
            if (SgtOcclusion.IsValid(occlusion, layers, gameObject) == true && OuterRadius > 0.0f && outerDepthTex != null)
            {
                var eye = cachedTransform.InverseTransformPoint(worldEye) / OuterRadius;
                var tgt = cachedTransform.InverseTransformPoint(worldTgt) / OuterRadius;

                var dir    = Vector3.Normalize(tgt - eye);
                var len    = Vector3.Magnitude(tgt - eye);
                var length = default(float);

                if (GetLength(eye, dir, len, ref length) == true)
                {
                    var localPosition  = cachedTransform.InverseTransformPoint(worldEye);
                    var localDistance  = localPosition.magnitude;
                    var innerThickness = default(float);
                    var outerThickness = default(float);
                    var innerRatio     = SgtHelper.Divide(innerMeshRadius, OuterRadius);
                    var middleRatio    = Mathf.Lerp(innerRatio, 1.0f, middle);
                    var distance       = SgtHelper.Divide(localDistance, OuterRadius);
                    var outerDensity   = 1.0f - outerFog;

                    SgtHelper.CalculateHorizonThickness(innerRatio, middleRatio, distance, out innerThickness, out outerThickness);

                    length *= SgtHelper.Reciprocal(outerThickness * outerDensity);

                    var depth = outerDepthTex.GetPixelBilinear(length, length).a;

                    depth = Mathf.Clamp01(depth + (1.0f - depth) * GetSky(worldEye, localDistance));

                    occlusion += (1.0f - occlusion) * depth;
                }
            }
        }
コード例 #3
0
        private void HandleCalculateOcclusion(int layers, Vector4 eye, Vector4 tgt, ref float occlusion)
        {
            if (SgtOcclusion.IsValid(occlusion, layers, gameObject) == true && radius > 0.0f && depthTex != null)
            {
                eye = transform.InverseTransformPoint(eye) / radius;
                tgt = transform.InverseTransformPoint(tgt) / radius;

                var dir    = Vector3.Normalize(tgt - eye);
                var len    = Vector3.Magnitude(tgt - eye);
                var length = default(float);

                if (GetLength(eye, dir, len, ref length) == true)
                {
                    var depth = depthTex.GetPixelBilinear(length, length).a;

                    depth = Mathf.Clamp01(depth + (1.0f - depth) * GetSky(eye));

                    occlusion += (1.0f - occlusion) * depth;
                }
            }
        }
コード例 #4
0
        private void CalculateOcclusion(int layers, Vector4 worldEye, Vector4 worldTgt, ref float occlusion)
        {
            if (SgtOcclusion.IsValid(occlusion, layers, gameObject) == true && OuterRadius > 0.0f && outerDepthTex != null)
            {
                var eye = transform.InverseTransformPoint(worldEye) / OuterRadius;
                var tgt = transform.InverseTransformPoint(worldTgt) / OuterRadius;

                var dir    = Vector3.Normalize(tgt - eye);
                var len    = Vector3.Magnitude(tgt - eye);
                var length = default(float);

                if (GetLength(eye, dir, len, ref length) == true)
                {
                    var depth         = outerDepthTex.GetPixelBilinear(length, length).a;
                    var localPosition = CachedTransform.InverseTransformPoint(worldEye);
                    var localDistance = localPosition.magnitude;

                    depth = Mathf.Clamp01(depth + (1.0f - depth) * GetSky(localDistance));

                    occlusion += (1.0f - occlusion) * depth;
                }
            }
        }
コード例 #5
0
        private void HandleCalculateOcclusion(int layers, Vector4 worldEye, Vector4 worldTgt, ref float flareOcclusion)
        {
            if (occlusion > 0.0f && SgtOcclusion.IsValid(occlusion, layers, gameObject) == true)
            {
                var localEye = transform.InverseTransformPoint(worldEye);
                var localTgt = transform.InverseTransformPoint(worldTgt);

                if (asteroids != null)
                {
                    for (var i = 0; i < asteroids.Count; i++)
                    {
                        var asteroid = asteroids[i];

                        if (asteroid.Radius > 0.0f)
                        {
                            var position = CalculateLocalPosition(ref asteroid, OrbitOffset);
                            var distance = GetDistance(localEye, localTgt, position);

                            if (distance < asteroid.Radius)
                            {
                                //var blocking = 1.0f - SgtHelper.Sharpness(1.0f - distance / asteroid.Radius, occlusion);

                                //flareOcclusion += blocking * (1.0f - flareOcclusion);
                                flareOcclusion += (asteroid.Radius - distance) * occlusion;
                            }

                            if (flareOcclusion > 0.99f)
                            {
                                flareOcclusion = 1.0f;

                                break;
                            }
                        }
                    }
                }
            }
        }