Exemple #1
0
        void Reset()
        {
            directionalLight = GDOC_Utils.FindMainDirectionalLight();

                        #if UNITY_EDITOR
            if (UnityEditor.PlayerSettings.stereoRenderingPath == UnityEditor.StereoRenderingPath.SinglePass)
            {
                vrMode = GDOC_VRMode.SinglePass;
            }
            else if (UnityEditor.PlayerSettings.stereoRenderingPath == UnityEditor.StereoRenderingPath.MultiPass)
            {
                vrMode = GDOC_VRMode.MultiPass;
            }
                        #endif
        }
Exemple #2
0
        void OnDrawGizmos()
        {
            var c = camera;

            if (c == null)
            {
                return;
            }

            if (drawDebugGizmos)
            {
                GDOC_Utils.CalculateFrustumPlanes(c, frustumPlanes);

                Gizmos.color = massGizmoColor;

                foreach (var id in occludeeList)
                {
                    var e = occludees[id];

                    if (e == null)
                    {
                        continue;
                    }

                    if (!e.isActive)
                    {
                        continue;
                    }

                    if (e.currentState == 1 || e.currentState == 3)
                    {
                        continue;
                    }

                    // if (!GeometryUtility.TestPlanesAABB(frustumPlanes, e.bounds)) continue;

                    Gizmos.DrawWireCube(e.position, e.size * 2);
                }
            }

            Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
            Gizmos.color  = Color.blue;
            Gizmos.DrawFrustum(Vector3.zero, c.fieldOfView, c.farClipPlane, c.nearClipPlane, c.aspect);
        }
Exemple #3
0
        public void UpdateBounds()
        {
            if (hasCustomBounds)
            {
                position = transform.position + GDOC_Utils.ApplyScale(center, transform.localScale, originalScale);
                size     = GDOC_Utils.ApplyScale(extents, transform.localScale, originalScale) * sizeMultiplier;
                offset   = center;
            }
            else
            {
                var bounds = new Bounds(Vector3.zero, minExtents);

                if (isParticleSystem && renderer != null)
                {
                    bounds = renderer.bounds;
                }
                else if (isRenderer && renderer != null)
                {
                    bounds = renderer.bounds;
                }
                else if (isRendererGroup)
                {
                    bounds = new Bounds();
                    var initDone = false;

                    EnsapculateRenderers(ref initDone, ref bounds, renderers);
                    EnsapculateRenderers(ref initDone, ref bounds, noShadowRenderers);
                    EnsapculateRenderers(ref initDone, ref bounds, shadowOnlyRenderers);
                }
                else
                {
                    return;
                }

                position = bounds.center;
                size     = bounds.extents * sizeMultiplier;
                offset   = position - transform.position;
            }

            size = Vector3.Max(size, minExtents);

            volumeSizeSqr = size.sqrMagnitude;
            this.bounds   = new Bounds(position, size);
        }
Exemple #4
0
        void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            if (this == null)
            {
                return;
            }

            if (!enableNewSceneScan)
            {
                return;
            }

            if (autoDirectionalLight && directionalLight == null)
            {
                directionalLight = GDOC_Utils.FindMainDirectionalLight();
                ValidateSettings();
            }

            StartCoroutine(ScanScene(scene, true));
        }
Exemple #5
0
        void Kickstart()
        {
            GDOC_Utils.CalculateFrustumPlanes(camera, frustumPlanes);

            var pos = camera.transform.position;

            foreach (var e in FindObjectsOfType <GDOC_Occludee>())
            {
                if (e.mode == GDOC_OccludeeMode.Excluded)
                {
                    continue;
                }

                var d = (pos - e.position).sqrMagnitude;

                var rv = e.volumeSizeSqr / d;

                if (rv < 0.01 || (rv < 0.05 && !GeometryUtility.TestPlanesAABB(frustumPlanes, e.bounds)))
                {
                    e.SetVisibleState(0, false);
                }
            }
        }
Exemple #6
0
        public void RecalculateContainerBounds(bool omnidirectional = false)
        {
            var bounds = new Bounds(transform.position, minExtents);

            foreach (var e in GetComponentsInChildren <Renderer>())
            {
                if (!e.gameObject.activeInHierarchy)
                {
                    continue;
                }

                if (!e.enabled)
                {
                    continue;
                }

                bounds.Encapsulate(e.bounds);
            }

            foreach (var e in GetComponentsInChildren <Light>())
            {
                if (!e.gameObject.activeInHierarchy)
                {
                    continue;
                }

                if (!e.enabled)
                {
                    continue;
                }

                if (e.type == LightType.Point)
                {
                    var b = new Bounds(e.transform.position, Vector3.one * e.range * 2);
                    bounds.Encapsulate(b);
                }
                else if (e.type == LightType.Spot)
                {
                    var z           = e.range;
                    var xy          = z * Mathf.Tan(Mathf.Deg2Rad * e.spotAngle * 0.5f) * 2;
                    var localBounds = new Bounds(Vector3.forward * z * 1, new Vector3(xy, xy, 0.01f));

                    bounds.Encapsulate(GDOC_Utils.TransformBoundsToWorldSpace(e.transform, localBounds));
                }
            }

            center        = bounds.center - transform.position;
            extents       = bounds.extents;
            originalScale = transform.localScale;

            if (omnidirectional)
            {
                extents.x += Mathf.Abs(center.x) * 0.5f;
                extents.y += Mathf.Abs(center.y) * 0.5f;
                extents.z += Mathf.Abs(center.z) * 0.5f;

                center = Vector3.zero;

                var s = Mathf.Max(extents.x, Mathf.Max(extents.y, extents.z));

                extents.x = s;
                extents.y = s;
                extents.z = s;
            }

            UpdateBounds();
        }
Exemple #7
0
        void OnEnable()
        {
            if (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Direct3D11)
            {
                initError = GDOC_Error.UnsupportedGraphicsAPI;
                enabled   = false;
                return;
            }

            var os = SystemInfo.operatingSystem;

            if (os.Contains("Windows") && !os.Contains("64"))
            {
                initError = GDOC_Error.x86NotSupported;
                enabled   = false;
                return;
            }

            camera = GetComponent <Camera>();
            if (camera == null)
            {
                initError = GDOC_Error.CameraRequired;
                enabled   = false;
                return;
            }

            RequestLimits(ref limits);

            if (limits.version == -1)
            {
                // demo won't work in builds
                enabled = false;
                return;
            }

            if (instance != null && instance != this)
            {
                if (instance.isActiveAndEnabled)
                {
                    initError = GDOC_Error.SecondInstance;
                    enabled   = false;
                    return;
                }

                /*
                 * _instance = this;
                 *
                 * if (fastCameraSwitch) {
                 *      fast = true;
                 * }
                 */
            }

            initError = GDOC_Error.None;

            if (autoDirectionalLight && directionalLight == null)
            {
                directionalLight = GDOC_Utils.FindMainDirectionalLight();
            }

            Clean(camera);
            Init(camera);

            InitPlugin();

            foreach (var e in Resources.FindObjectsOfTypeAll <GDOC_Occludee>())
            {
                if (e.isTemporary)
                {
                    if (!kickstart)
                    {
                        Destroy(e);
                    }
                }
                else
                {
                    e.OnRemove();
                }
            }

            lastCameraPosition = camera.transform.position;
            lastCameraRotation = camera.transform.rotation;

            if (maxQueuedFrames > -1)
            {
                QualitySettings.maxQueuedFrames = maxQueuedFrames;
            }

            maxOcludeeId = 0;

            if (sampleMaterial == null)
            {
                sampleMaterial = new Material(Shader.Find("Hidden/GDOC/Sample"));
                sampleMaterial.enableInstancing = true;
            }

            InitLightBuffers();

            InitUI();

            if (kickstart)
            {
                Kickstart();
            }

            InitScanning();

            StartOrRestartCoroutine(ref frameEndWaiter, FrameEndWaiter());
        }
Exemple #8
0
        void EnableFrustumObjects()
        {
            if (shouldLogInfo)
            {
                sw.Reset();
                sw.Start();
            }

            GDOC_Utils.CalculateFrustumPlanes(camera, frustumPlanes);

            var pos   = camera.transform.position;
            var count = 0;

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

                if (e == null)
                {
                    occluders.RemoveAt(i);
                    continue;
                }

                if (!e.isActive)
                {
                    continue;
                }

                if (e.currentState == 1 || e.currentState == 3)
                {
                    continue;
                }

                var d = (pos - e.position).sqrMagnitude;

                var rv = e.volumeSizeSqr / d;

                if (rv < teleportRV)
                {
                    continue;
                }

                if (!GeometryUtility.TestPlanesAABB(frustumPlanes, e.bounds))
                {
                    continue;
                }

                ChangeOccludeeState(e.runtimeId, 1);

                UpdateOccludeeState(e.runtimeId, 1);

                count++;
            }

            if (shouldLogInfo)
            {
                var t = (float)sw.ElapsedTicks / Stopwatch.Frequency * 1000f;

                UnityEngine.Debug.Log(string.Format("Enabled {0} of {1} objects in {2} ms", count, occluders.Count, t));
            }
        }