Page 1 of 1

Different colors when using constant or property values

PostPosted: Tue Oct 09, 2018 11:19 am
by Jono00
Hi!

I just made a new, empty shader. I use 2 colors to define the albedo of a mesh. For some reason, I get different results when the colors are constant or property!

Results when the colors are constants.
Results when the colors are properties.

To reiterate, the only thing I changed is the color type (Constant to Property). Am I misunderstanding something here?

I'm using unity 2018.2.9f1

Thanks!

Re: Different colors when using constant or property values

PostPosted: Tue Oct 09, 2018 2:11 pm
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

This behavior is expected and it only happens in Linear color space, which is due to Unity trying to convert the property's value. It won't happen if the value is a constant, since the value is directly specified in the shader, or if you work in Gamma color space, which hopefully are valid workarounds.

Please let me know if you have any further questions, thanks!

Re: Different colors when using constant or property values

PostPosted: Tue Oct 09, 2018 2:27 pm
by Jono00
Oh! I actually did not know that.

Thank you for the swift and kind reply :)

Re: Different colors when using constant or property values

PostPosted: Tue Oct 09, 2018 3:06 pm
by Amplify_Borba
No problem, please don't hesitate to get in touch if you have any further questions, we'll be happy to help!

Re: Different colors when using constant or property values

PostPosted: Sat Jan 05, 2019 10:59 am
by JohnnyFactor
I'm encountering the same thing and it's causing issues when building to mobile, so how do we use Property mode in linear color space?

EDIT: I'll be more specific here. The color nodes work fine when working in linear space, but the floats do not. I've been replacing floats with greyscale color nodes but I would really like to understand what's going on.

Re: Different colors when using constant or property values

PostPosted: Mon Jan 07, 2019 3:45 pm
by Amplify_Borba
Hello, the conversion between linear and gamma is expected to only occur in color properties.

However, the float node does have a Gamma attribute that, according to Unity's documentation, might perform the necessary conversion.

Please let us know if the above does work, otherwise you'll likely have to use the color node rather than the float node.

Re: Different colors when using constant or property values

PostPosted: Mon Jan 07, 2019 8:50 pm
by JohnnyFactor
Yes, that worked! Thanks for finding this, now it's clear. A build to iOS with a float node with the Gamma attribute is identical to a color node. I found the same info on a link from the page you posted, worded slightly differently:

https://docs.unity3d.com/Manual/SL-Properties.html:
"For properties that are marked as Float or Vector type, no color space conversions are done by default; it is assumed that they contain non-color data. It is possible to add [Gamma] attribute for float/vector properties to indicate that they are specified in sRGB space, just like colors."

Re: Different colors when using constant or property values

PostPosted: Tue Jan 08, 2019 12:24 pm
by Amplify_Borba
No problem, thank you for letting us know this worked out for you!