Example #1
0
        /// <summary>
        /// Instantiates portalCamera as a copy of the player's Camera with post-processing effects copied, as a child of the PortalManager, and disables the Camera.
        /// </summary>
        void InitializeVirtualPortalCamera()
        {
            Camera playerCam = SuperspectiveScreen.instance.playerCamera;

            portalCamera = new GameObject("VirtualPortalCamera").AddComponent <Camera>();
            portalCamera.transform.SetParent(transform, false);
            portalCamera.enabled = false;

            // Copy main camera component from player's camera
            portalCamera.CopyFrom(playerCam);
            portalCamera.cullingMask    &= ~hideFromPortalCamera;
            portalCamera.backgroundColor = Color.white;

            VirtualPortalCamera virtualPortalCam = portalCamera.gameObject.AddComponent <VirtualPortalCamera>();

            virtualPortalCam.DEBUG = DEBUG;

            // Copy post-process effects from player's camera
            // Order of components here matters; it affects the rendering order of the postprocess effects
            //portalCamera.gameObject.PasteComponent(playerCam.GetComponent<BloomOptimized>());                                          // Copy Bloom
            ColorfulFog        fog           = portalCamera.gameObject.PasteComponent(playerCam.GetComponent <ColorfulFog>());                     // Copy Fog
            BladeEdgeDetection edgeDetection = portalCamera.gameObject.PasteComponent(playerCam.GetComponent <BladeEdgeDetection>());              // Copy Edge Detection (maybe change color)

            //edgeDetection.enabled = false;
            //edgeDetection.checkPortalDepth = false;
            virtualPortalCam.postProcessEffects.Add(fog);
            virtualPortalCam.postProcessEffects.Add(edgeDetection);

            portalCamera.gameObject.name = "VirtualPortalCamera";
        }
        public void Setup(Camera source, Portal portal, Portal otherPortal, int[] remove, int[] add, PortalCameraControl par = null, float nearclipoffset = 0f, bool ignoreFog = false)
        {
            if (par)
            {
                hasParent    = true;
                parentCamera = par;
            }
            setUp               = true;
            this.source         = source;
            this.portal         = portal;
            this.otherPortal    = otherPortal;
            this.nearClipOffset = nearclipoffset;

            if (portalDummy == null)
            {
                portalDummy        = new GameObject(portal.name + " Dummy").transform;
                portalDummy.parent = portal.transform;
            }
            if (otherDummy == null)
            {
                otherDummy        = new GameObject(otherPortal.name + " Dummy").transform;
                otherDummy.parent = otherPortal.transform;
            }

            camera = gameObject.AddComponent <Camera>();
            camera.CopyFrom(Camera.main);
            int i;

            for (i = 0; i < remove.Length; i++)
            {
                camera.cullingMask = VidyaMod.RemoveFromLayerMask(camera.cullingMask, remove[i]);
                //camera.cullingMask = camera.cullingMask & ~(1 << remove[i]);//remove layer
            }
            for (i = 0; i < add.Length; i++)
            {
                camera.cullingMask = VidyaMod.AddToLayerMask(camera.cullingMask, add[i]);
                //camera.cullingMask = camera.cullingMask | (1 << add[i]);//add
            }
            camera.depth = -2;

            sourceBloom = Camera.main.GetComponent <BloomAndLensFlares>();
            sourceSsao  = Camera.main.GetComponent <SSAOPro>();
            sourceAa    = Camera.main.GetComponent <AntialiasingAsPostEffect>();
            sourceFog   = Camera.main.GetComponent <ColorfulFog>();

            bloom = ModUtility.CopyComponent <BloomAndLensFlares>(sourceBloom, gameObject);
            ssao  = ModUtility.CopyComponent <SSAOPro>(sourceSsao, gameObject);
            aa    = ModUtility.CopyComponent <AntialiasingAsPostEffect>(sourceAa, gameObject);
            fog   = ModUtility.CopyComponent <ColorfulFog>(sourceFog, gameObject);

            bloom.enabled = false;
            ssao.enabled  = sourceSsao.enabled;
            aa.enabled    = sourceAa.enabled;
            fog.enabled   = sourceFog.enabled;

            layer   = add[0];
            ignored = ignoreFog;
            ProcessFog();

            UpdateFOV();
            ReferenceMaster.onFOVChanged += UpdateFOV;
        }