Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question What is the most straight forward way of cutting alpha with a texture mask?

Discussion in 'Shaders' started by DotsCreative, Aug 28, 2020.

  1. DotsCreative

    DotsCreative

    Joined:
    Jul 3, 2018
    Posts:
    17
    Hi! I'm trying to make a cutout shader with a texture input which scales depending on another gameobjects scale & world position, to set alpha to zero inside the texture mask. In this case, the target of the shader is a wall, and the gameobject is a door. I don't want to use the uv because the uv on the target object could be arranged in any order. What is the most straight forward way of transforming the alpha mask to match another gameobjects world position and scale?

    Any help/directions is appreciated.
     
  2. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    You could use another graphic sample in the shader to define the mask area. Let's say we have another image to be the mask and black is where we want to discard and not black is where we want to draw; you can use it either way as to say only draw where color > 0 and/or discard where color == 0.
     
  3. DotsCreative

    DotsCreative

    Joined:
    Jul 3, 2018
    Posts:
    17
    But wouldn't it use the wall's uv? I'm trying to not make it uv dependent, but dependent on another gameobject's world position transformed to scale it correctly.
     
  4. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    The simplest way I can think of is have the other object prepared for any objects that could interact with it. I'm not sure of what you want to do but it sounds like you want a player to build a door on a wall. So if the wall is built in sections like this |---|---|---| and you want to put a door into the middle then you would have a sampler in the walls shader for a door and then cutout the door |---|- -|---|. Or maybe use a compute shader for the walls cutout sample that you update whenever a new change occurs.