Vector3 vs Color

I noticed that an unlit shader graph seems to show different colors depending on data type. The left cube is using Color(0.5, 0.5, 0.5) (displays correctly) while the right cube uses Vector3(0.5, 0.5, 0.5) (incorrect). The vector3 value seems to display as (0.74, 0.74, 0.74). I’m using Unity 2021.2.5f1 with URP.

ColorTest unlit shader. Color(0.5, 0.5, 0.5)

VectorTest unlite shader. Vector3(0.5, 0.5, 0.5)

Is this a bug or am I just missing something?

I don’t have a thorough answer, but I immediately assume Color is literal, while Vector3 is going through a gamma correction or a perceptive luminance calculation, instead of a simple linear relationship.

1 Like

Whenever I hit things like this I’ll toss on the Colorspace Conversion node to find out what’s going on.

  1. Color
  2. Vector3 (Linear to RGB)
  3. Vector3 (RGB to Linear)
1 Like

Thanks @halley1 and @Ben_at_Work . That does seem to be the issue. The Colorspace Conversion node looks useful, I’ll have to try it in the future.

Technically they’re both “correct”.

This is on the right track … except it’s backwards. Color is going through a color conversion, and Vector3 is not! The thing you’re missing is when using linear color space rendering, which the URP and HDRP default to, the final image goes through a linear to gamma conversion before being displayed on screen.

Here’s the documentation for the Color node.
https://docs.unity3d.com/Packages/com.unity.shadergraph@10.2/manual/Color-Node.html

Here’s the code example for that node:

float4 _Color = IsGammaSpace() ? float4(1, 2, 3, 4) : float4(SRGBToLinear(float3(1, 2, 3)), 4);

Basically if a color conversion is needed, it does the gamma (sRGB) to linear conversion. If you were using gamma color space rendering, the color and vector3 nodes would end up looking exactly the same.

1 Like