sinkywer

Hello, I am using Spine 4.0 in Unity URP project.
I want to change color of character's individual parts in different colors.

Example Code)
_skeletonAnimation.skeleton.Slots.Items[0].SetColor();

It seems works in "Multiply" blend mode, same as Unity's default blend mode.
But I want "Hue-shift-like" Color change, or more detailed coloring in runtime than SetColor function.

Splitting character's parts and using material for each part makes too many objects.

Is there other any way to do this?
sinkywer
  • Postovi: 3

Harald

I'm afraid that if you need multiple different hue-shift color adjustments and multiple materials are not an option, then you will need to write your own custom shader. This shader would then use hue-shift color changing code instead of the normal tinting. You could base the shader on any one of the provided Spine shaders, and for hue adjustment use the code of the Spine Sprite shaders. You would copy the hue adjustment code from (or include the file) spine-unity\Shaders\Sprite\CGIncludes\ShaderShared.cginc here.
Avatar
Harald

Harri
  • Postovi: 4101

sinkywer

I see that "Universal Render Pipeline/Spine/Sprite" shader has "Color Adjustment" option.
And hue, saturation, brightness can be changed by material option.
Of course it changes whole color of character.

I want to slot.SetColor(); works in hue-shift instead of tining.
But creating my own shader will effect on whole color of character in my expectation.
:think:

Is SetColor function also effected by shader code?
sinkywer
  • Postovi: 3

Harald

slot.SetColor(); works by assigning the color as the vertex color at your mesh vertices. The Sprite shaders use a constant _Hue parameter which is set for the whole material. What you would need to do is use this vertex color in the shader code instead of the constant _Hue parameter, like this:
inline fixed4 adjustHueOfColor(fixed4 color, fixed hue)
{
float3 hsv = rgb2hsv(color.rgb);
hsv.x = hue; // sets it to the target hue
// hsv.x += hue; // or use this line instead to add a hue-shift to it
color.rgb = hsv2rgb(hsv);
return color;
}

fixed4 fragmentShader(.. inputVertex..) {
fixed4 vertexColorHSV = rgb2hsv(inputVertex.color);
fixed hue = vertexColorHSV.r;
...
fixed4 texureColor = ...;
texureColor = adjustHueOfColor(texureColor, hue);
...
}
Avatar
Harald

Harri
  • Postovi: 4101

sinkywer

I edited "LightweightFragmentBlinnPhongSimplified" in "Spine-Sprite-ForwardPass-URP.hlsl"
//half4 diffuse = texDiffuseAlpha * vertexColor; //before
half4 diffuse = adjustHueOfColor(texDiffuseAlpha, vertexColor); //after
like this and added rgb<->hsv code above it.
Then HSV coloring by SetColor(); function is working as I wanted.

Thank you for you help, Harald.
sinkywer
  • Postovi: 3

Harald

Very glad to hear it worked out. Thanks for letting us know.
Avatar
Harald

Harri
  • Postovi: 4101


Natrag na Unity