Hi is it possible to add the local 0…1 coordinates into the sprites uv2 channel?
Its quite annoying that we cant use the second channel for additional effects.
Thanks
Hi is it possible to add the local 0…1 coordinates into the sprites uv2 channel?
Its quite annoying that we cant use the second channel for additional effects.
Thanks
Yep. This would be awesome. But Unity’s sprite system explicitly doesn’t support more than one UV and they’ve shown no signs of looking to change that in the decade or so people have asked for it.
The only real work around is … don’t use the Sprite Renderer component.
If you instead use the Canvas and UI Image Component you can set up to 4 UVs using IMeshModifier
or BaseMeshEffect
class to modify the mesh at runtime, depending on if you’re using the original built-in version (up to around 2019.1) or package version of the UI systems (starting 2019.2 on). Though there’s some overlap where both BaseMeshEffect
and IMeshModifer
exist in some versions in the middle.
https://docs.unity.cn/Packages/com.unity.ugui@1.0/api/UnityEngine.UI.BaseMeshEffect.html
(For reasons I don’t understand, the only documentation for Unity’s current UI systems are only available on their official Chinese site or older versions of Unity. It’s not anywhere on their US or UK sites, or in the current LTS versions of the documentation. To add to the confusion the only public repos of the source are now 2+ years out of date and don’t seem to entirely match the documentation?)
There’s even an included class called PositionAsUV1 that shows how to use it, sort of. You can find it if you dig through your Library/PackageCache/com.unity.ugui@1.0.0/ folder inside your project for recent versions of Unity.
There’s also a version here on their official github, which appears to match the file in the latest package version, but I can’t guarantee any of the rest of the UI code does.
The other alternative is to use regular Mesh Renderer components and add a custom script that lets you expose and modify the renderer.sortingOrder
, renderer.sortingLayerName
, and renderer.sortingLayerID
properties. All of which do work on the mesh renderer, but which just aren’t exposed to the default inspector and aren’t serialized (saved) meaning you have to use this extra script to both store it and apply it OnEnable
.
Yeah im converting sprites to meshes, but its just an hacky approach.
This feature is clearly lacking. A second uv channel for costum data at shader level would be really nice.
At some point i wish unitys base system would be more extendable. Their 2d stuff is not really optimized. And using images is a nightmare where performance counts (mobile). Though shader level effects are probably the best for animation
Oh an thanks for this info, wasn´t aware that this is possible:
“All of which do work on the mesh renderer, but which just aren’t exposed to the default inspector and aren’t serialized (saved)”