Sprite shaders backwards compatibility broken by the new _Flip uniform.

In 5.6, the sprite shaders were changed to have an additional uniform (_Flip) to control sprite flipping. It’s unclear to me why this exists. Why is this not simply applied as part of the model matrix instead of being passed as a separate uniform? This breaks backwards compatibility and also makes it impossible to create a shader that works with both sprites and regular meshes.

Is there a strong reason for breaking backwards compatibility in a minor release?

1 Like

To be clear, this causes several problems.

  • In our current project, we have several shaders that are shared between sprites and regular meshes (quads, generated meshes, etc). This change will force us to duplicate the shader or make a variant, and go through all of our prefabs by hand to replace materials.
  • For the assets that we sell, it’s going to require us to put out a non-backwards compatible update that forces the problem above on all of our customers. Since they aren’t likely to know about the sprite rendering changes, that puts the burden of support on us.

Please don’t release this change in Unity 5.6! It’s very unclear to me what problem it’s trying to solve. Sprites already receive a unique model matrix per instance, and I find it hard to believe that passing two booleans as 64 bits of floating point numbers through a uniform buffer is providing a performance boost over negating a couple of rows in a matrix.

And it doesn’t even work properly with some rotations. It starts skewing! (try flipping a sprite as child of a rotating rigidbody2d).

Instead of using it, I’ve decided to just make my sprites rotate to flip, even if this does mean I have to make workarounds, at least I’m making the workarounds in a sane manner.

Why isn’t it even documented given its a major, major breaking change.

+100.

Yes, I had to make the same shader twice as well.

Can I get a repro project or bug report? This is BETA after all, so these are the feedback that we want/expect.

It was originally proposed as a means to visually flip a sprite without messing with the physics2d. It was conceived before the start of 2D Animation project (2017). With the new 2D Character focus in mind, i’m actually thinking about deprecating this and rethink it again “How can I effortlessly flip a multi-sprite animated character without applying negative scale”.

Stay tuned.

“How can I effortlessly flip a multi-sprite animated character without applying negative scale”.
Rotating around yaw. We don’t use negative scale but I guess we could.

Why would Box2D care about a rotation or flip surely it should enforce it’s own constraint and sign? @MelvMay

Depreciating this would be ideal as we wouldn’t have to double up on shaders because a lot of the environment is mesh based but uses the same shading…

Also negative scale messes up batching/instancing because it flips the winding order of the triangles. We are forced to break batch and setup the backface culling states.

Perhaps, but I need to think deeper to see if there’s a proper/elegant solution.

2 Likes

@hippocoder Not sure I follow what the question is but 2D physics doesn’t care about the SpriteRenderer or its flipping properties. Its only concern is the Transform component:

  • Rigidbody2D position is driven by Transform XY position change. Also by Transform Z rotation which rotates the body.

  • Collider2D live in Rigidbody2D space so their vertices are driven by the Transform XY position if there isn’t a Rigidbody2D on the same GameObject. Also by Transform XY rotation and XY scale; Z rotation if there isn’t a Rigidbody2D on the same GameObject.

Sorry for minor necro, just had this issue today i think. Is this what you guys are talking about?
The issue seemed to relate to the sprite renderer not wanting to use a different material other than the default one for sprites. Even though the both used the same shader, and had same properties, other than the fact one had a main texture stuck on it from another shader.

Alright, turns out my issue has a new dimension, if both the gun shadow and gun sprite use the same material, it warps, if theyre both different, then it works as it should.

Hi Lelepoop,
Could you please file a bug report with a minimal reproduction case and reply with the case #?

Case 876008, good luck :slight_smile: