Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Masking a parallax background with the foreground

Discussion in '2D' started by Lahol, Jun 29, 2022.

  1. Lahol

    Lahol

    Joined:
    May 23, 2022
    Posts:
    15
    Hi !

    I am working on a 2D platformer game with some backgrounds on the z-axis to achieve a parallax effect. It works quite well but I would like to mask the background (red on the picture) when it's out of the foreground.

    Does anyone have an Idea if it could work ? I'm struggling with it because it's just a perspective effect and the background is at the same x and y position as the foreground...
    I appreciate any help !


     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,099
    Can you explain more what you mean by this?
     
  3. Lahol

    Lahol

    Joined:
    May 23, 2022
    Posts:
    15
    Thank for answering !
    Sorry if my question was unclear, I have one foreground (characters and platforms) and one background.
    The background (z=3) is just behind the foreground (z=0)

    (The depth of field effect is applied on the Background).
    The parallax effect works well but when the camera moves, sometimes, my background looks "out of place".
    That effect is caused by the perspective Camera.

    I would like to hide the red part, as if the foreground were masking the background.
    Both background and foreground have the same x and y position.
    Honestly, I don't know if it's a thing or if I should just paint in black what's out of bounds in the foreground to hide the background.
    Thank you in advance for your help !
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,099
    I would just insert an extra stretched bunch of black plates where you need them... you certainly COULD do it with shader tricks and stencils / masks, but if you just made a single 32x32 black tile sprite and stretched/inserted it as many times as necessary, it might be the fastest simplest solution. It would use almost no memory either.
     
    Lahol likes this.
  5. Lahol

    Lahol

    Joined:
    May 23, 2022
    Posts:
    15
    Thank you, it works :)