Search Unity

Resolved Custom mask using second sprite

Discussion in 'Shader Graph' started by spottedzebra, Nov 15, 2020.

  1. spottedzebra

    spottedzebra

    Joined:
    Oct 26, 2013
    Posts:
    39
    Hi I'm trying to get a smooth/feathered mask effect using Shader Graph but am getting stuck. I'm able to more or less get the effect I want when I hard code values but:

    1) I'm not really sure why I chose the tiling values I did, they just seem to work.
    2) The offset is effectively gobbly gook, what I need is to position the mask using world coordinates.

    Can anyone help? Here's my intended effect (note that the black "ceiling" enclosed by the walls is a single sprite shape renderer using the shader graph material):


    And here's my graph:


    Full images here: https://imgur.com/a/uxIU7f4
     
  2. Neohun

    Neohun

    Joined:
    Oct 30, 2018
    Posts:
    77
    So basically you want to mask a sprite if I understand correctly check out the time "29:15" that's what you're looking for:
     
    Last edited: Nov 15, 2020
  3. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535

    yes but it does not explain his question 2) how to move that mask to a position based on unity world coordinates. I would also like to know the answer to this part.

    If you notice the mask is centered on the sprite, the question is how to move the square off center based on a world position.
     
  4. spottedzebra

    spottedzebra

    Joined:
    Oct 26, 2013
    Posts:
    39
    Thanks for the video @Neohun -- yeah I know how to make the mask already (see my graph or the resulting image) the problem is I want to position the mask using world space... And rotate it around a pivot and have it respect the texture's aspect ratio...

    Basically I want it to work like SpriteRenderer's Mask functionality, but with "partial alpha" support.

    I've tried using the out-of-box mask functionality and drawing the "feathered" alpha as an overlay, which works up to a point. The problem is as soon as you rotate the mask/overlay such that it overlaps with an unmasked area you see the overlay texture's corner -- breaking the illusion.
     
  5. Neohun

    Neohun

    Joined:
    Oct 30, 2018
    Posts:
    77
    First of all the way you create mask is complicated and not the proper way I'm not an expert about shaders but know a little.. so the way I offer you is much more simple and proper..

    And Secondly I have spent half of an hour to figure out how to achieve what you want so you owe me (; and here's the shader which you want.. there's only one thing I don't get is I had to negate the position (multiply with -1) for some reason which I don't know..

    Shader.PNG

    Edit: by the way I forgot to say that you have to rotate the plane around x-axis 90 degrees to make the shader work properly.. because it's based on x-y surface.. If there's another solution (and probably there's one) it's propably an advanced one which I can't offer..
     
    Last edited: Nov 15, 2020
  6. spottedzebra

    spottedzebra

    Joined:
    Oct 26, 2013
    Posts:
    39
    Thanks @Neohun I owe you a beer -- next time you're in Seattle

    Here's my final graph (based on the above):



    And the result:


    No idea why the tiling sizes are what they are but ... it works.

    Full images here: https://imgur.com/a/FM15aKU