Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Shader Graph and Multiple Sprite Mode

Discussion in 'Shader Graph' started by Jargs, Jul 7, 2019.

  1. Jargs

    Jargs

    Joined:
    Dec 8, 2018
    Posts:
    4
    I have created a wind sway shader for 2D trees, based on Brackeys grass sway video. I'm using LWRP.

    It doesn't appear to be playing well with sprites from textures that are set to multiple sprite mode. The sway is suposed to be nothing ath the bottom and gradually increase to full strength at the top. From what I can tell, instead of seeing the bottom of the selected sprite as the bottom, it looks like the shader is treating the bottom of the entire multi-sprite texture as the "bottom" of the sprite.

    In the example below, the tree on the left is using a sprite from the top left corner of a much larger texture in multiple sprite mode. The tree on the right is using a sprite from a texture in single sprite mode. The sway intensity has been increased to really show the problem...



    Notice how the trunk of the tree on the left is swaying back and forth, but the trunk of the tree on the right is practically stationary.

    Is this normal behavior for shader graphs? Is there some way I can tell it to treat the individual sprite separately from the entire texture, or do I have to split every sprite I want to add a shader to into it's own texture?

    upload_2019-7-7_14-16-28.png
     
  2. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    99
    my friend ,we have same problem here. waiting for replying or have you been solved it?
     
  3. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,019
    I'll send this over to the team for them to take a look for you guys.
     
  4. Hookkshot

    Hookkshot

    Joined:
    Jan 11, 2013
    Posts:
    19
    Has there been a resolution for hits. Also running into the same issue for tree swaying as well.
     
  5. DevilCult

    DevilCult

    Joined:
    Jun 24, 2017
    Posts:
    44
    Same problem here! That was a long 2 days before finding this thread... :\
    Is it working on a single sprite? Im gonna cut everything down! lol
     
  6. DevilCult

    DevilCult

    Joined:
    Jun 24, 2017
    Posts:
    44
    Ok seem the problem is with making sprite atlas, once in the atlas shader become weirds (those using vertex displacement at least). I separated all images and placed them outside atlas and everything is fine now.

    Enjoy ! ;P
     
  7. TobyM

    TobyM

    Joined:
    Apr 28, 2017
    Posts:
    7
    Is there any update on if there will be a way to use a sprite from a sprite atlas with shader graph? I would really like to avoid having to save every single sprite as a sperate file, as it would be an inconvenience for our workflow ...
     
  8. RatouPitouMaker

    RatouPitouMaker

    Joined:
    Apr 13, 2020
    Posts:
    1
  9. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    231
    Sliced, Tiled of type Multiple/Atlased .. Shader Graph has problems with all of those. The only type i was able to make work was Simple/Single Sprite/Texture combination. Defeats the purpose of having 9sliced or Atlased sprites completely.
     
    Storm4_ and Carrotpie like this.
  10. Gbreal

    Gbreal

    Joined:
    Mar 20, 2018
    Posts:
    2
    Hey All,

    I have found a reasonable workaround for this situation that allows you to use a Sprite sheet and still get the desired result.

    Firstly the issue is that the shader is taking into account the entire Textures UV coordinates and not the specific sprite.

    Option 1.
    Like above mentioned you can remove the sprites you want to apply this shader to from the sheet into it's own texture and lose the perfomance benefits of a sprite sheet.

    Option 2.
    • Create a second sprite sheet for the sprites you want this shader applied to.
    • Align each sprite in this sheet Horizontally, where there is only one line of sprites.
    • Ensure each sprite is aligned to the bottom of the sheet.
    • Add some padding to each sprite (Optional).

    This works since the shader uses the the Y UVs of Sprite sheet, which in this new sprite sheets case is the same for all sprites, this gives way to another slight issue see below notes.

    Notes
    • If you have Sprites that vary in height by a lot (e.g Bushes/Grass vs Trees) you will need to seperate these into their own material and adjust the Shader properties
     
    _watcher_ likes this.
  11. InvincibleCat

    InvincibleCat

    Joined:
    Dec 23, 2014
    Posts:
    73
    Is there any update on this?
    I have also submitted a bug 1244783_g924r2g1ockfm7r2

    Thanks
     
  12. mirostraka

    mirostraka

    Joined:
    Feb 17, 2014
    Posts:
    36
    Was there ever a resolution to this?
    We have encountered this issue as well and have already rather large atlases of textures done and in game, so redoing all the textures would be quite a task. is there a way to get sprite uv in shader?
     
    Storm4_ likes this.
  13. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    665
    I just tested today: this is still an issue at least for my test setup.

    SpriteAtlas. Tilemap. The ShaderGraph is very similar to what's in the Lost Crypt demo's tree sway. It seems to treat it like the tree spans the whole y-direction. So when the Atlas is in a shape like this:
    Capture.PNG
    It sways very, very slightly relative to just the tree alone because the sprites are small and there's extra unused atlas space above. It seems to use the Atlas's UVs, not the sprite's.

    edit: if I quadruple the Wind Strength in Play mode only then it seems to behave like before (with no Atlas), but that's hacky and likely will need to change every time that atlas grows.
     
    Last edited: Sep 10, 2020
  14. yuvalko

    yuvalko

    Joined:
    Dec 4, 2018
    Posts:
    2
    Hey, I solved it!

    Context:
    My solution is good only if you have a sprite sheet that is divided into equal parts.
    My character is in a 10 row, 10 column sprite sheet, each 36x36 pixels.
    and I wanted to superimpose another texture on top of it.

    Before the solution, some terminology:
    UV is actually two coordinates, both between 0 and 1 so 0,0 represent one corner and 1,1 represents the other.
    Since shader graph uv is for the whole sprite sheet than 0..1 => 0..360pixel (in my case)

    The Solution:
    The trick is to pass the UV node into a modulo node with x = 1/10 and y = 1/10 (in my case because I had a 10x10 sprites) and then to put it into a sampler UV node.

    Please note:
    it does not look good inside the shader graph as you will see many duplications of the texture.
    However, it works in the game itself just great.

    Hope it helped someone.
     
  15. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    665
    mirostraka likes this.
  16. T_Lavell

    T_Lavell

    Joined:
    May 29, 2013
    Posts:
    1
    Ah, sorry if this isn't effective but in another Brackeys video
    @ 9:30 he feeds world/object space to one of the nodes (instead of UV) and it seems to correct the issue of an effect being "stretched" over multiple sprites - even though they are on a single horizontally aligned sprite sheet.
    It's the Get Started with Shader Graph - Dissolve Tutorial video.
     
    Sinister-Design likes this.
unityunity