#Combining Unity's SpriteRenderer component with a custom lit sprite shader (Issue flipping on the X)

1 messages · Page 1 of 1 (latest)

last yacht
#

Hello, I'm working on a game that combines a 3D world with 2D billboard sprites, a little bit like the original Doom games. I've created a custom ShaderGraph that lets you still use spritesheets and the SpriteRenderer component, but the sprites also receive lighting. It's very straightforward so far. However, I've noticed that if a sprite faces you using its forward, the sprite is actually flipped backwards. I'd like to simply go inside the ShaderGraph, grab the UVs, then use a One Minus node on the X to flip the sprites so that they face the correct way by default. However, doing this seems to cause the sprite animations to crop weirdly and play the animations in an incorrect order. Is there a way to:

A.) Hook into the SpriteRenderer's FlipX and FlipY properties?
B.) Change up the ShaderGraph so that it fixes the cropping and animation order issues?

It's worth noting that my sprite sheets have evenly sized and spaced cells.

Any advice would be hugely appreciated! 🙂

fast garnet
#

You should flip the vertex positions instead of the UV

last yacht
#

It's worth mentioning that I can manually flip the scale on every single prefab to minus X. However, this isn't maintainable and kinda feels gross and hacky

#

Cyan! I've read all of your blogs ❤️ You're something of a legend haha. I'll give that a try now

fast garnet
#

Also looks like the flip x/y properties are passed into unity_SpriteProps.xy, might be able to use a Custom Function node to access that

last yacht
#

I'm very nooby with shaders. Is this along the right lines?

#

And I'll try the other approach too!

fast garnet
#

You'd want Negate here instead

#

Or with unity_SpriteProps.xy method that's -1 or 1 depending if it needs flipping, so if you pass the Position into the Custom Function you can do
Out = float3(Position.xy * unity_SpriteProps.xy, Position.z);

#

(At least in theory, based on the URP/Sprite-Unlit-Default.shader. Not something I've tested)

last yacht
#

Thank you very much! I think this works. Just trying to test out a couple of scenarios