Same Color in View and colorEffect shader argument produce different results

Opened feedback item FB21877364.

Context

I have the following Metal shader, which replaces one color with another.

[[ stitchable ]] 
half4 recolor(
    float2 position, 
    half4 currentColor,
    half4 from, 
    half4 to
) {
	if (all(currentColor == from))
		return to;
	return currentColor;
}

Given this SwiftUI view:

let shader = ShaderLibrary.recolor(.color(.red), .color(.green))
Color.red
    .colorEffect(shader)

I get a red rectangle instead of the expected green one. Note that this works on both dynamic and non-dynamic colors.

Note that this sometimes works with some colors, which is very inconvenient when trying to figure out what's going on.

Did I miss something? I would've expected the shader to work with colors the same way.

Issue

To really highlight the issue, here's another test case.

I'll define #94877E in an Asset Catalog as example and check the RGB values using the Digital Color Meter app in "Display native values" mode.

We'll use the following shader to determine how colorEffect receives colors:

[[ stitchable ]] 
half4 test(
    float2 position, 
    half4 currentColor, 
    half4 color
) {
	return color;
}

The following view yields "R: 0.572, G: 0.531, B: 0.498".

Color.example

While this one yields "R: 0.572, G: 0.531, B: 0.499".

let shader = ShaderLibrary.test(.color(Color.example))
Color.white.colorEffect(shader)

I would expect them to match.

Same Color in View and colorEffect shader argument produce different results
 
 
Q