Search Unity

2d Depth *kind of* shader, please advise.

Discussion in '2D' started by Gibbonuk, Nov 13, 2017.

  1. Gibbonuk

    Gibbonuk

    Joined:
    Dec 10, 2013
    Posts:
    175
    Hi, Im trying to find out if this is currently possible with shaders or at least doable.

    Ill try and explain as simple as I can. I basically want to have a moving 2d sprite or image where the brightness of individual pixels are decided by a mask or black and white image thats not visible to the screen.

    So to further explain, if the mask is full screen half white half black, and I then have the moving image in the white, as I move it over to the black all the pixels that are over the black part of the mask will be brighter.

    Thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well, for starters, you could simply switch from the standard sprite shader (which ignores lights) to the default shader (which applies lights), and then put some spotlights into your scene.
     
  3. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    Yes it's doable.
    You could use lights, from your question you probably don't have much shader experience so that could be the simplest if you can get the mask detail you want.

    Otherwise you just need the mask texture, a way to look up in that mask texture the correct uv for your sprite.
    Read the value and then do some extra math in the shader to adjust the color value.
    A lot will depend on how your mask is generated and in what space it exists to get the correct uv coordinates.
     
  4. Deleted User

    Deleted User

    Guest

    So if I get it right you are trying to do something like this:


    Take a read at this link, it may help you:
    http://mehm.net/blog/?p=1218
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    is the mask fixed on screen? (camera wont move)
    if fixed, then could try using screenspace texture, and add/blend that to sprite.. (with custom sprite shader or maybe modifying sprite mask shader)

    there is example with screenpos how it would look, see that grid:
    https://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
     
    JoeStrout likes this.