Shader Graph and Multiple Sprite Mode

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…

alertsmalllice

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?

1 Like

my friend ,we have same problem here. waiting for replying or have you been solved it?

I’ll send this over to the team for them to take a look for you guys.

Has there been a resolution for hits. Also running into the same issue for tree swaying as well.

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

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 ! :stuck_out_tongue_winking_eye:

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 …

I’m not sure i’ve understood the question but i think U can use secondary textures: Unity - Manual: Sprite Editor: Secondary Textures

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.

3 Likes

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
1 Like

Is there any update on this?
I have also submitted a bug 1244783_g924r2g1ockfm7r2

Thanks

5 Likes

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?

1 Like

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:


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.

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.

2 Likes

FYI to future people who find this thread, Unity considers this By Design, so don’t expect a fix:

2 Likes

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.

3 Likes

I tried this but it didn’t work for me: https://forum.unity.com/threads/object-space-doesnt-seem-to-work-for-sprite-lit-shader-anymore.1087970/

It would be nice to get access to the “cropped” uv coordinates the sprite renderer is using when rendering a sprite located in an atlas in order to use it with other textures…

1 Like

Anything new on this? Still annoying to this date. It takes up alot of unecessary space to have to separate the sprites into many different sheets.

Unity considers this “By Design” so don’t expect a change.

I am also interested in finding a solution to this problem!!
I join the thread.