White seams when using Bleed + Straight Alpha with Unity on Android
I tried but I am also unable to use the 4.1 shader because they want the CGIncludes, which want a script, which want another script and so on.
Yes, that's the only difference.
lindsayt I tried but I am also unable to use the 4.1 shader because they want the CGIncludes, which want a script, which want another script and so on.
Sorry, I forgot that these were based on includes already. Then you need to import the required include files as well. It's these three:
Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-BlendModes-NormalPass.cginc
Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-BlendModes-ShadowCasterPass.cginc
Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Common.cginc
I will shortly compile a unitypackage (in a zip package so that the forum accepts the upload) which contains only the additional files to be imported to an existing spine-unity 3.8 project.
The documentation says this is obsolete but I don't know if this applies to Spine 3.8 as the "Upgrade" button that's mentioned is not present.
Upon testing the shaders I noticed that the latest spine-unity 3.8 runtime already provides the native support for slot blend modes and an Upgrade
button at the SkeletonDataAsset, rendering the BlendModeMaterialAssets
indeed obsolete. So if you don't see this Upgrade
button, you are not using the latest spine-unity 3.8 package.
Harald Thanks. I've done more experiments and have narrowed it down to some code on our side, but still unsure why it's occuring.
On our SpineActors we have a script that holds references to different shaders. One of them is the basic tint shader. We change these are run time depending on the situation, but in this case it's I'm just testing with the basic tint shader.
When these actors are bundled, the tint shader on script is different instance to the one on the material (I can see via debugging). Setting the shader to the one bundled with the script on the actor is causing this issue. Using the one already assigned to the material works as expected. The shader is the same, so I'm not sure why it breaks when bundled? We're changing the shader on the sharedMaterials reference.
Unfortunately I'm still not able to upload a slice of the project as it's all very much linked.
So in editor setting the material's shader to the Spine/Skeleton Tint
works when not using bundles.
When using bundles, and using a bundled version of the shader it does not work (doesn't matter if the shader is in it's own shared bundle or if it's an instanced copy). If I use Shader.Find(Spine/Skeleton Tint)
and apply that shader, it works. In editor presumably this version is the one on disk.
Is there something in Spine or the material that cares about whether or not the shader is bundled and/or the same instance?
@lindsayt A quick guess is that the references from the bundled skeletons to the shader (or Material) are referencing a new asset reference, while the target of the reference are in an asset bundle which is either not loaded when loading the skeletons, or perhaps has not been re-generated with the new shaders and materials. So in other words, it sounds as if the packages containing the references don't match the available packages containing the referenced asset, either of the two seem to have been missing an update. You could have a quick try whether putting the shader into the same bundle as the problematic skeleton resolves the issue for this skeleton. Or you could also add the used shaders to the Always Included Shaders in the Project Settings.
Or there is a race condition that the skeletons are loaded before the shaders and materials, and the dependency order is not maintained (for whatever reason).
You could also check in your used version control system whether the .meta files (and therefore the GUIDs) of the used shader or materials have been modified.
One more thing: in case you aren't already using that, please set any Asset Bundle editor settings to be as strict as possible, e.g. when building bundles use StrictMode
or the like.
Thanks. I've added the materials to the always included, moved them to the same / different bundles, and tried lots of other things. If the shader is the one in the bundle, it just doesn't work and I get the artifacts. I even changed the shader code to force it to be blue for testing and both the bundled shader and the on disk shader changed colour, so it's definitely the same shader. I've been deleting and rebuilding the bundles over and over and on two different machines so it's not a caching problem.
You talked about race conditions and such, is there some method I need to call on the skeleton or material to get it to refresh and possibly work again?
- Düzenlendi
(deleted)
OKAY I have a workaround, but I still don't know why bundles don't work.
If I put the shaders into "Always Loaded" and DONT bundle the shaders, those shaders aren't put into the asset bundles and the instance ids for the shader references all point to the same location and the artifacts are GONE. I've been testing with Editor bundles so far and will try with an Android build tomorrow, hopefully this works on device too.
After more investigating, the bundles problem could be something related to how shader features and they are bundled. The last comment on this post explains it.
So the difference between the editor shader and the bundled shader is that the bundled shader has been stripped of the Straight Alpha feature and thus why it's giving artifacts as if it was disabled
https://forum.unity.com/threads/asset-bundles-and-shaders.806331/
The "always loaded" didn't work on Device. I think this is because Unity is stripping it from the build as above. At least now I think I know the reason and just need to find a way to make sure the full shader is loaded instead
@lindsayt Thanks for sharing these insights! There are a few ways to avoid shader variants from being stripped:
1) Disable shader variant stripping completely via project settings (not really recommended)
2) Ensure that there is a reference for the later-required variants, e.g. by creating dummy Materials which are included in the main game instead of asset bundles, or in the "shaders" asset bundle which contains the problematic shaders (if you don't want to always include it for some reason).
3) In shader code of the problematic shaders, change shader_feature
to multi_compile
at the relevant variant keywords. This will always include both variants instead of only when referenced at build time.
What could perhaps also help diagnosing shader problems in general:
Temporarily, for testing purposes, you could replace all lines near the end of shaders that say Fallback "another/shader name"
with Fallback Off
. This way you should see the pink error shader used when a shader can't be loaded, as opposed to falling back to something that looks halfway correct.
You should have encountered the same problem as me, but I have solved it. All you need to do is reset it once it is loaded from AssetsBundle
Encountered a Spine issue with hot-updated AssetBundle loading on iOS
You can try this to solve your problem!
I also saw an article about Spine3.8 and URP rendering pipelines, hoping it would be helpful to you.
Unity Spine 3.8 (URP) 踩坑(Shader报错修改)
Qingswe The problem was the shader_feature's being stripped out during builds / bundles. The solution is to include the material in the base game with the feature being used. In my testing the spine asset was using the Spine/Skeleton shader and had the Spine/Skeleton_Tint shader set at runtime via code, but Unity had already stripped the straight_alpha part from it. Having the material set to straight alpha and having the Spine/Skeleotn_Tint shader set before building resolved the issue.