Exemplo n.º 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";
        }
Exemplo n.º 2
0
 public static void CopyEdgeColors(EDColors from, BladeEdgeDetection to)
 {
     to.edgeColorMode            = from.edgeColorMode;
     to.edgeColor                = from.edgeColor;
     to.edgeColorGradient        = from.edgeColorGradient;
     to.edgeColorGradientTexture = from.edgeColorGradientTexture;
 }
Exemplo n.º 3
0
 private void CopyEdgeColors(BladeEdgeDetection dest, BladeEdgeDetection.EdgeColorMode edgeColorMode, Color edgeColor, Gradient edgeColorGradient, Texture2D edgeColorGradientTexture)
 {
     dest.edgeColorMode            = edgeColorMode;
     dest.edgeColor                = edgeColor;
     dest.edgeColorGradient        = edgeColorGradient;
     dest.edgeColorGradientTexture = edgeColorGradientTexture;
 }
        protected override void Start()
        {
            base.Start();
            edgeDetection = SuperspectiveScreen.instance.playerCamera.GetComponent <BladeEdgeDetection>();

            realBlackRoomPortal.gameObject.SetActive(!edgesAreBlack);
            fakeBlackRoomPortal.gameObject.SetActive(edgesAreBlack);
        }
Exemplo n.º 5
0
    void ToggleDoubleSidedEdges()
    {
        BladeEdgeDetection ed = SuperspectiveScreen.instance.playerCamera.GetComponent <BladeEdgeDetection>();

        if (ed != null)
        {
            ed.doubleSidedEdges = !ed.doubleSidedEdges;
        }
    }
Exemplo n.º 6
0
    void ToggleDebugMode()
    {
        BladeEdgeDetection ed = SuperspectiveScreen.instance.playerCamera.GetComponent <BladeEdgeDetection>();

        if (ed != null)
        {
            ed.debugMode = !ed.debugMode;
        }
    }
Exemplo n.º 7
0
            // Can't save textures easily

            public EDSettings(BladeEdgeDetection edgeDetection)
            {
                this.edgeColorMode = edgeDetection.edgeColorMode;
                this.edgeColor     = edgeDetection.edgeColor;

                this.edgeColorGradient = new Gradient {
                    alphaKeys = edgeDetection.edgeColorGradient.alphaKeys,
                    colorKeys = edgeDetection.edgeColorGradient.colorKeys,
                    mode      = edgeDetection.edgeColorGradient.mode
                };
            }
Exemplo n.º 8
0
        private void SwapEdgeDetectionColors(int channel)
        {
            BladeEdgeDetection playerED = EpitaphScreen.instance.playerCamera.GetComponent <BladeEdgeDetection>();

            UnityEngine.Transform camerasParent = cameraContainersByChannel[channel].transform;
            BladeEdgeDetection[]  portalEDs     = camerasParent.GetComponentsInChildrenOnly <BladeEdgeDetection>();

            BladeEdgeDetection.EdgeColorMode tempEdgeColorMode = playerED.edgeColorMode;
            Color     tempColor                = playerED.edgeColor;
            Gradient  tempColorGradient        = playerED.edgeColorGradient;
            Texture2D tempColorGradientTexture = playerED.edgeColorGradientTexture;

            CopyEdgeColors(source: portalEDs[0], dest: playerED);
            portalEDs.ToList().ForEach(ed => CopyEdgeColors(ed, tempEdgeColorMode, tempColor, tempColorGradient, tempColorGradientTexture));
        }
Exemplo n.º 9
0
        void SwapEdgeDetectionColors()
        {
            BladeEdgeDetection playerED = SuperspectiveScreen.instance.playerCamera.GetComponent <BladeEdgeDetection>();

            EDColors tempEDColors = new EDColors {
                edgeColorMode            = playerED.edgeColorMode,
                edgeColor                = playerED.edgeColor,
                edgeColorGradient        = playerED.edgeColorGradient,
                edgeColorGradientTexture = playerED.edgeColorGradientTexture
            };

            CopyEdgeColors(from: this, to: playerED);

            otherPortal.changeCameraEdgeDetection = true;
            CopyEdgeColors(from: tempEDColors, to: otherPortal);
        }
Exemplo n.º 10
0
        void Start()
        {
            debug                     = new DebugLogger(gameObject, () => DEBUG);
            mainCamera                = SuperspectiveScreen.instance.playerCamera;
            portalCamera              = GetComponent <Camera>();
            mainCameraEdgeDetection   = mainCamera.GetComponent <BladeEdgeDetection>();
            portalCameraEdgeDetection = GetComponent <BladeEdgeDetection>();

            depthNormalsReplacementShader   = Shader.Find("Custom/CustomDepthNormalsTexture");
            visibilityMaskReplacementShader = Shader.Find("Hidden/VisibilityMask");
            portalMaskReplacementShader     = Shader.Find("Hidden/PortalMask");

            SuperspectiveScreen.instance.OnPlayerCamPreRender      += RenderPortals;
            SuperspectiveScreen.instance.OnScreenResolutionChanged += (width, height) => ClearRenderTextures();

            renderStepTextures = new List <RecursiveTextures>();
            portalMaskTextures = new List <RenderTexture>();
        }
    /// <summary>
    /// On Awake, we cache various values and setup our command buffer to be called Before Image Effects.
    /// </summary>
    void Awake()
    {
        debug                  = new DebugLogger(gameObject, () => DEBUG);
        prePassMaterial        = new Material(Shader.Find("Hidden/GlowCmdShader"));
        prePassMaterialLarger  = new Material(Shader.Find("Hidden/GlowCmdShaderLarger"));
        prePassMaterialSmaller = new Material(Shader.Find("Hidden/GlowCmdShaderSmaller"));
        blurMaterial           = new Material(Shader.Find("Hidden/Blur"));

        prePassRenderTexID  = Shader.PropertyToID("_GlowPrePassTex");
        blurPassRenderTexID = Shader.PropertyToID("_GlowBlurredTex");
        tempRenderTexID     = Shader.PropertyToID("_TempTex0");
        blurSizeID          = Shader.PropertyToID("_BlurSize");
        glowColorID         = Shader.PropertyToID("_GlowColor");

        commandBuffer      = new CommandBuffer();
        commandBuffer.name = "Glowing Objects Buffer";         // This name is visible in the Frame Debugger, so make it a descriptive!
        thisCamera         = GetComponent <Camera>();
        edgeDetection      = thisCamera.GetComponent <BladeEdgeDetection>();
    }
Exemplo n.º 12
0
        void SetDefaultPlayerPositionForScene()
        {
            string sceneName = GetSceneName();

            SetVector3($"{PositionKeyPrefix}.{sceneName}", Player.instance.transform.position);
            SetVector3($"{RotationKeyPrefix}.{sceneName}", Player.instance.transform.rotation.eulerAngles);
            Camera             mainCam       = GameObject.Find("Main Camera")?.GetComponent <Camera>();
            BladeEdgeDetection edgeDetection = (mainCam == null) ? null : mainCam.GetComponent <BladeEdgeDetection>();

            if (edgeDetection != null)
            {
                string edgeDetectionKey = $"{EdgeDetectionSettingsKeyPrefix}.{sceneName}";
                SetEDSettings(edgeDetectionKey, new EDSettings(edgeDetection));
            }

            if (DEBUG)
            {
                Debug.Log(
                    $"Starting position for player set to {Player.instance.transform.position} for scene {sceneName}"
                    );
            }
        }
Exemplo n.º 13
0
        private OldPortalCameraFollow CreatePortalCamera(UnityEngine.Transform parentObj, OldPortalSettings receiver, OldPortalSettings otherPortal)
        {
            GameObject playerCam = EpitaphScreen.instance.playerCamera.gameObject;

            GameObject newCameraObj = new GameObject(receiver.name + " Camera");

            newCameraObj.transform.SetParent(parentObj);

            // Copy main camera component from player's camera
            newCameraObj.AddComponent <Camera>().CopyFrom(playerCam.GetComponent <Camera>());
            int hidePlayerMask = LayerMask.NameToLayer("Player");

            newCameraObj.GetComponent <Camera>().cullingMask &= ~(1 << hidePlayerMask);

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

            if (!receiver.useCameraEdgeDetectionColor)
            {
                edgeDetection.edgeColorMode            = receiver.edgeColorMode;
                edgeDetection.edgeColor                = receiver.edgeColor;
                edgeDetection.edgeColorGradient        = receiver.edgeColorGradient;
                edgeDetection.edgeColorGradientTexture = receiver.edgeColorGradientTexture;
            }
            newCameraObj.PasteComponent(playerCam.GetComponent <ColorfulFog>());                                                        // Copy Fog

            // Initialize PortalCameraFollow component
            OldPortalCameraFollow newPortalCameraFollow = newCameraObj.AddComponent <OldPortalCameraFollow>();

            // Fix Camera name
            newCameraObj.name = receiver.name + " Camera";
            return(newPortalCameraFollow);
        }
Exemplo n.º 14
0
 public void ApplyTo(BladeEdgeDetection edgeDetection)
 {
     edgeDetection.edgeColorMode     = this.edgeColorMode;
     edgeDetection.edgeColor         = this.edgeColor;
     edgeDetection.edgeColorGradient = this.edgeColorGradient;
 }
Exemplo n.º 15
0
 private void CopyEdgeColors(BladeEdgeDetection source, BladeEdgeDetection dest)
 {
     CopyEdgeColors(dest, source.edgeColorMode, source.edgeColor, source.edgeColorGradient, source.edgeColorGradientTexture);
 }
Exemplo n.º 16
0
        void LoadDefaultPlayerPosition()
        {
#if !UNITY_EDITOR
            return;
#endif

            if (!defaultPlayerPosition || hasLoadedDefaultPlayerPosition)
            {
                return;
            }

            string sceneName        = GetSceneName();
            string positionKey      = $"{PositionKeyPrefix}.{sceneName}";
            string rotationKey      = $"{RotationKeyPrefix}.{sceneName}";
            string edgeDetectionKey = $"{EdgeDetectionSettingsKeyPrefix}.{sceneName}";

            if (HasVector3(positionKey) && HasVector3(rotationKey))
            {
                Vector3 pos      = GetVector3(positionKey);
                Vector3 eulerRot = GetVector3(rotationKey);

                Player.instance.transform.position = pos;
                Player.instance.transform.rotation = Quaternion.Euler(eulerRot);
            }

            if (PlayerPrefs.HasKey(edgeDetectionKey))
            {
                Camera             mainCam       = GameObject.Find("Main Camera")?.GetComponent <Camera>();
                BladeEdgeDetection edgeDetection = (mainCam == null) ? null : mainCam.GetComponent <BladeEdgeDetection>();
                if (edgeDetection != null)
                {
                    GetEDSettings(edgeDetectionKey).ApplyTo(edgeDetection);
                }
            }

            if (DEBUG)
            {
                if (!HasVector3(positionKey))
                {
                    Debug.LogError($"No position key found for {positionKey}");
                }

                if (!HasVector3(rotationKey))
                {
                    Debug.LogError($"No rotation key found for {rotationKey}");
                }
            }

            // Hijacking this to display level banner on load, even when it's already the active scene
            LevelChangeBanner.instance.PlayBanner(enumToSceneName[sceneName]);
#if UNITY_EDITOR
            try {
                Scene scene = EditorSceneManager.GetSceneByName(sceneName);
                if (!EditorSceneManager.GetSceneByName(sceneName).IsValid())
                {
                    string path = $"Assets/{(sceneName != enumToSceneName[Levels.TestScene] ? "__Scenes" : "PrototypeAndTesting")}/{sceneName}.unity";
                    scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
                }
                EditorSceneManager.SetActiveScene(scene);
            }
            catch (Exception e) {
                Debug.LogError(e);
            }

            if (EditorApplication.isPlaying)
#endif
            hasLoadedDefaultPlayerPosition = true;
        }
Exemplo n.º 17
0
 void CopyEdgeColors(BladeEdgeDetection dest, EDColors edgeColors)
 {
     CopyEdgeColors(dest, edgeColors.edgeColorMode, edgeColors.edgeColor, edgeColors.edgeColorGradient, edgeColors.edgeColorGradientTexture);
 }