Search Unity

Dynamic "cutout" mesh colliders using shadow maps?

Discussion in 'Physics' started by Wikzo-DK, Sep 28, 2016.

  1. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    I saw an example where someone used a projection to make a cutout in a surface (https://github.com/cjacobwade/HelpfulScripts/tree/master/SeeThrough). Here is a small animated GIF showcasing the effect:



    I want to do this dynamically with mesh colliders, meaning that I cut a hole in the actual wall and thereby create a new mesh collider where another object can then pass through the hole

    Specifically, I want to do this with shadows. In essence, I want to dynamically “cut holes” in an object’s collider wherever it is not lit up (/ in shadow), in real-time.

    Here is a small (fake) GIF that illustrates what I want:



    For simplicity, red objects fall through the shadows on white objects. In the GIF, the red cylinder can roll forward, until the shadow gets too wide and the cylinder falls down through the shadow.

    I am thinking of using shadow maps to build a mesh collider. In the GIF above, this would create a new mesh collider for the floor with an intersection in the middle.

    Do you think this is doable at all? I need it to work in real-time and with multiple dynamic lights. It also needs to work with physic objects. Eg., can you replace the collider that an object is standing on, each frame, without it suddenly clipping through? Any obvious pitfalls?

    Thanks a lot in advance!