Announcement

Collapse
No announcement yet.

DepthMasks and Portals?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    DepthMasks and Portals?

    Hey guys.

    I'm coming from Unity where I was working on a project that utilizes Antichamber style 'portals' to do non-euclidean level design. If you're unfamiliar with it, Antichamber uses a network of 'portals' to move the player between rooms in a way that seems impossible (neverending circular hallways, doors that only work one way, etc). It may not be exactly how that designer did it, but it's the method I've been having success with. I can convert most of my code over, but I can't seem to get the 'visuals' working in Unreal. My setup in Unity was as follows:
    • A 'box' with it's render surfaces facing inside and one face missing (so you can walk into it).
    • A camera that writes to a lower depth in the depth buffer than the player camera.
    • A DepthMaskShader for the cube surfaces that allows access the non-player camera's information.

    Hopefully that makes sense. I'm trying to recreate this effect in Unreal and I'm running into roadblocks. I was hoping someone could point me in the right direction, as I can't find anything on the topic, or if there's a 'better' way to do this. Right now, this means I'd like to know how to do a Depth Mask in Unreal 4.

    Some things to consider; The 'cube' is required, as far as I can tell, to prevent the player from seeing clipping through the surface. I can probably have them 'teleport' before entering the surface, but I intend to have two players in this project, so they'd appear to just snap out of reality if player 2 sees player 1 use the system via that method. Hence, I need a cube so they can 'enter' it and THEN teleport to the destination.

    Because of the above, though, I can't just do a SceneCapture2D, at least without modifying the output somehow (struggling with how). I can make a flat surface work fine, but applying it to a cube surface makes undesirable tiling happen. That's why I used a depth mask in Unity. It let the scene just display over the surface pretty seamlessly. If the answer is programming, I can do that, but I'm trying to get this working without modifying code. I'm thinking it may be something I need to write myself, though.

    Thanks for any input you have.

    TL;DR; - How can I implement a Depth Mask Shader on an object in Unreal 4?
    Last edited by JMoore5268; 03-23-2014, 05:36 PM.

    #2
    Did you ever find a good solution for this? I also had a similar system set up in Unity, and I was wondering how it would work in UE4.

    If you've made any progress, I would be interested in an update. A demo project or code would be great, but even just a description of a feasible and efficient method would help.

    In Unity I used two cameras and a depth mask shader, but I'm not familiar enough with UE4 yet to even know where to look to control the rendering order of multiple cameras and shaders. I'm still working my way through the documentation and tutorials to get a better understanding of UE4's rendering pipeline before I can tackle this problem.

    Comment


      #3
      I'm still working through it. I've started working with code as I think it requires a custom programmed shader or material to accomplish this right now. I'll update when/if I get a solution.

      Comment


        #4
        I've been playing around with the Material editor a bit, reading through some of the docs, and I came up a with a prototype of the effect. It uses the custom depth buffer and post-processing to accomplish the depth mask. My concern is that it won't work on mobile (I read on this forum that the SceneTexture node may not be available there--the ES2 feature level uses a "pared down forward shading path").

        I did a quick video. The short walk-through of the set up (including a screenshot of the material graph) is included in the description of the video so I won't duplicate it here.



        I still think there is a better way that I might be able to figure out once I understand rendering with multiple cameras a bit better. This method is a starting point, at least, so I though I'd post it for anyone trying to implement a similar effect.

        (Edit: Or maybe I will duplicate it here, for posterity.)

        1) Enable "Render Custom Depth" under "Rendering" for any object
        2) Create a new Render Target
        2) Create a new ScreenCapture2D and assign it the render target
        3) Create a new material.
        4) Set it up like this: http://i.imgur.com/IzaXH5D.png
        5) On your Global PostProcess under "Misc" add a new "Blendable" and assign the depth mask material to the slot
        Last edited by CaptainScience; 04-02-2014, 01:49 AM.

        Comment


          #5
          You're awesome, CaptainScience. I'll be testing this method out, but it looks like what we need and the limitations don't bother me.

          I'll still be experimenting with the code to see if I can find a better solution, possibly with recursive portal support, but this is a very nice starting point.

          Comment


            #6
            Captain, I managed to recreate your solution but it appears to disable additional visual effects such as bloom when within the Post Process volume. Is this a known shortcoming or did I miss a step?

            Comment


              #7
              I haven't played around with it too much, but it could be that I was sampling from "SceneColor" where I should be sampling from one of the "PostProcessX" sources. There is also a console command (which I used a bit but don't remember--it's in the docs somewhere) that outputs the whole post-processing chain and you'd want to make sure everything is happening in the correct order. There are a few options to control where the effect happens in the material editor, but there may be more fine-tuned control available somewhere else (maybe only in code).

              I discovered the mobile preview function, and I found that the effect doesn't work there so I haven't pursued it too much in favour of finding a more general solution. The ES2 feature level uses pared down forward rendering and it seems like this custom depth buffer isn't supported there.

              Comment


                #8
                I see. Well, it's definitely got me started so I'll experiment with it. I'm still trying to get used to UE4's shader system, so I'll have to do some digging.

                If you get a more general solution, let me know, I'm having a guy on my project investigate one as well.

                Comment


                  #9
                  Captaiin, thanks a lot, but is there a way to have 2 different portals with different textures visible at the same time? Is there only 1 Custom Depth?

                  Comment


                    #10
                    Originally posted by Hexabeast View Post
                    Captaiin, thanks a lot, but is there a way to have 2 different portals with different textures visible at the same time? Is there only 1 Custom Depth?
                    I found a way to solve this problem:

                    1- Follow CaptainScience's steps
                    2- Create 2 materials: 1 with roughness > 0.7
                    1 with roughness < 0.7
                    (I choose roughness here but it could be something else)
                    3- Put those 2 materials on 2 different objects with the "Render Custom Depth" enabled
                    4- Create another scenecapture and another texture
                    5- Modify the CaptainScience's material to be like that:

                    http://hpics.li/230d252

                    That works for me!

                    But I am facing another problem (I explained it here: https://answers.unrealengine.com/que...d-problem.html )
                    If anyone have a way to solve it that would be great!
                    Attached Files

                    Comment


                      #11
                      I posted in your answer as well, but what you're looking for is this: http://www.terathon.com/code/oblique.html.

                      You might be able to write a custom Blueprint node that applies this function to your camera.

                      Something else that would be useful is a "scissor rectangle" or "scissor test" that you apply to your portal camera to clamp the sides of the frustum to the screen-space bounding-box of the portal. Essentially, look at the size of your portal on your screen, draw a box around it, and make sure your SceneCapture2D only renders what it needs to fill that box.

                      I don't have a link for that one, but you should be able to apply that in addition to your oblique near-plane so that your portal camera is only rendering what your player could potentially see through the portal.

                      Comment


                        #12
                        I'm trying to create a portal-like (mine is more a dimension portal) I was wondering if someone managed to create the "Oblique Near-Plane Clipping" in blueprint.
                        Could you also show me how you managed the global post-process for your portals.

                        thanks

                        Comment


                          #13
                          I tried following CaptainScience's steps but as soon as I add the customdepth material to blendables, it makes the whole screen black. Am I missing something really simple here?

                          Comment


                            #14
                            Hey all! This is all really useful, thanks for posting everything.

                            I have followed all these steps but the screen aligned uvs aren't bringing in the render target.

                            Please see the attached image and error message:

                            Click image for larger version

Name:	Screen Shot 2014-08-16 at 11.21.34 am.png
Views:	1
Size:	160.0 KB
ID:	1053536

                            Any idea on what could be causing this?
                            Last edited by russellstephens; 08-16-2014, 11:45 AM.

                            Comment


                              #15
                              Originally posted by russellstephens View Post
                              Hey all! This is all really useful, thanks for posting everything.

                              I have followed all these steps but the screen aligned uvs aren't bringing in the render target.

                              Please see the attached image and error message:

                              [ATTACH=CONFIG]8923[/ATTACH]

                              Any idea on what could be causing this?
                              I would try to click the error node and choose the scene color like in the pictures below.

                              But I'm try it out the next time by myself.

                              Comment

                              Working...
                              X