• International
  • 如何讓 Shader 在 Spine SkeletonGraphic(UI)中實現角色整體的漸層效果?(中/English)

我是中文使用者,我的英文不算好,但我會附上英文來進行討論。
English is not my first language, but I’ve included an English version to help with the discussion.

我目前正在 Unity 中使用 Spine 角色,並嘗試用 Amplify Shader Editor 製作一個垂直漸層效果(從腳到頭漸變顏色)。
這樣的效果在使用 SkeletonAnimation 組件時運作良好,Shader 能正確取得角色整體的空間,計算出漂亮一致的漸層。

但當我使用 SkeletonGraphic(UI 元件)時,問題就出現了:
無法呈現漂亮的漸層,即使使用 World Position → Transform → Object 的方式,也無法解決。

請問如何在 UI(SkeletonGraphic)實作具有範圍空間邏輯的shader?或是有其他推薦的解決方案嗎?


How to Achieve a Character-Wide Gradient Shader on Spine SkeletonGraphic (UI) in Unity?

I'm using Spine characters in Unity and trying to implement a vertical gradient effect via Amplify Shader Editor — a smooth color blend from feet to head.
This works perfectly when I use SkeletonAnimation, where the shader can calculate consistent space and apply the gradient as intended.

However, when switching to SkeletonGraphic (UI-based renderer), the gradient breaks:
The gradient does not render correctly, and even using World Position → Transform → Object does not solve the problem.

Is there a way to implement a shader with character-wide spatial logic for UI (SkeletonGraphic)? Or are there any other recommended solutions?


你可以從這裡下載這個專案:
You can download the project/package here:
Package file link

Related Discussions
...

@Hsiang While I haven't had the time to check your project yet, a quick guess is that your gradient scale needs to be adjusted when used with SkeletonGraphic, as skeleton in the UI are e.g. 100x larger in world space due to e.g. 1920x1080 resolution leading to 1 pixel being one game unit, which otherwise is by default corresponding to a meter.

感謝你的回覆,解決了顏色漸變的問題,但我遇到了新問題,漸層無法跟著角色座標走,如下圖:

Thank you for your response. It resolved the gradient rendering issue, but I’ve run into a new problem — the gradient doesn’t move with the character’s position, as illustrated in the image below:

@Hsiang I've just verified that input vertex positions are pre-transformed positions, so not in object space. You could pass the object position in as a separate Material property and subtract it from the vertex position to get object-space vertex positions.

Please note that this is unrelated to Spine, it's a general Amplify Shader Editor package and Unity question which might better be asked on the Amplify forum or the Unity forums.

In general I'm not sure if the Amplify Shader Editor package can at all be configured to author proper Canvas Renderer shaders, so be sure to test it thoroughly on your potential target devices.

@Harald
Thanks again! I’ll try asking on other forums too. Appreciate your reply~