Announcement

Collapse
No announcement yet.

3D Capsule/cone mask in material? (solution for seeing through obstacles)

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

    3D Capsule/cone mask in material? (solution for seeing through obstacles)

    I'm trying to figure out some GPU based solution for seeing through obstacles that occlude player character. It's for a topdown/isometric game. Here is what I have for now, prototyping stage:


    The material has a SphereMask in position of camera + offset towards camera forward vector, so it's around between camera and player. The mask serves as an alpha for DitherTemporalAA plugged into Pixel Depth Offset.
    This is my first idea: Every object that can be an 'occluder' (e.g. trees, buildings, etc.) have this masked 'transparency' material logic (I'd probably collapse it to a function) added to its material.

    It works, but as you can see, the fade-off starts too early because of sphere mask radius. If I decrease the radius, it won't work at all. That's why it'd be great to have something like CapsuleMask, where besides capsule position + radius we could also control capsule height. This way we could have a mask like that, so it would work perfectly for seeing through obstacles:
    Click image for larger version

Name:	bobneedshelp.png
Views:	1
Size:	38.4 KB
ID:	1216846

    ... I suspect that I could solve this by setting multiple sphere masks uniformly distributed between player and camera and adding all of them in material, but is there a better solution? Something like a capsule mask/cone mask that works similarly to the SphereMask...? But is it possible? I'd be grateful for some hints.

    PS. I've tried CPU based solutions like line/multiSphere traces + hiding/changing object material, but I need a solution that will hide only a part of object, exactly around player character. This is because with the CPU solution, when camera detects e.g. tree leafs, then it hides whole tree instead of only the leaf area that is occluding player.
    Last edited by Slavq; 04-20-2017, 12:34 PM. Reason: typo

    #2
    Maybe you should just transform pixel position into camera space and use BoxMask 3D?

    Comment


      #3
      Originally posted by Deathrey View Post
      Maybe you should just transform pixel position into camera space and use BoxMask 3D?
      Thank you, I'm trying to implement this, but without luck yet - I got the BoxMask 3D working, but it's not rotated towards camera direction:
      Click image for larger version

Name:	Bez tytułu.png
Views:	1
Size:	138.5 KB
ID:	1126688

      I've found a way to rotate the BoxMask 3D: https://forums.unrealengine.com/show...x-Mask-3D-Node
      ... But can't figure out how to rotate it towards camera direction:

      Click image for larger version

Name:	Bez tytułu2.png
Views:	1
Size:	16.3 KB
ID:	1126689

      Some kind of 'LookAt' rotation would be handy, but it's not present in material editor...

      Maybe that transform to camera space that you've suggested should solve this somehow, but I don't understand how it works/where to plug it in.

      Comment


        #4
        You do not need to rotate anything, if you are feeding pixel position transformed to camera-space.

        Comment


          #5
          Thank you, it works pretty well Naturally the mask appears rectangle-shaped, but with bigger Edge Falloff it appears more spherical (close to my initial capsule-mask idea). Now I'll try to learn how the world space -> camera space transformation works and fine tune the effect. Thanks again!

          Comment


            #6
            Originally posted by Slavq View Post
            Thank you, it works pretty well
            You're welcome.
            Originally posted by Slavq View Post
            Naturally the mask appears rectangle-shaped, but with bigger Edge Falloff it appears more spherical (close to my initial capsule-mask idea).
            Capsule - like mask can be implemented with something like this:

            Could be done slightly cheaper though.

            Comment


              #7
              Try Drawline-3D, it is basically a capsule. Should be cheaper as it does not require transforms.
              Ryan Brucks
              Principal Technical Artist, Epic Games

              Comment


                #8
                Thank you, I'll try this solution soon.

                Comment


                  #9
                  Originally posted by RyanB View Post
                  Try Drawline-3D, it is basically a capsule. Should be cheaper as it does not require transforms.
                  Could we get an example on how to use that node ? I mean "DrawLine-3D"

                  Comment

                  Working...
                  X