Search Unity

Resolved Is this a defect? Color node split into Vector3 seems really off...

Discussion in 'Shader Graph' started by wheee09, Jan 25, 2020.

  1. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Ok, I hope I'm not going crazy but this seems really off.

    Using the following Shader Graph:

    Screen Shot 2020-01-25 at 12.41.55 PM.png

    It's basically a simple IF/ELSE condition test.

    The above would essentially read:

    IF the input to the Step Node is GREATER than the R Value of the color node (0.1) then render the Red color.
    ELSE render Black.

    The Shader Graph itself predicts it will be black, but when I actually use this shader in Play Mode, it is actually red!

    In fact the threshold is around 0.01002 ~ 0.01003. Meaning if the Step Node Input is 0.01002, then it will render Black. If it is 0.01003, it will render Red.


    This all came from trying to do something as simple as this:
    Screen Shot 2020-01-25 at 12.51.38 PM.png


    Depending on whether I connect the Color Node or the Vector3 Node to the Unlit Master Node, I get different results when rendered! The Vector3 Node produces a lighter (more white) color. The Main Preview does not change in either case.

    I was trying to figure out why my colors looked washed out in white and it came down to this.

    Really looking forward to an explanation.

    I am using 2019.2.13 which is behind a bit - I'll go upgrade and see if it changes anything.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    With a Color node, you're defining the color in sRGB (aka Gamma) color space. This is the color space everyone is used to when defining color values, as a value of "0.5" looks half as bright as "1.0". However the human eye is funny and what we perceive as being half as bright is actually roughly only 20% as bright in terms of the actual photon energy being emitted. So Color properties and nodes will convert the color values from gamma space to linear space.

    When you set the color value using the Vector3 you're setting the color values in linear space. So to get a value equal to a Color node (0.5, 0.5, 0.5) you'd need to set the Vector3 to (0.214, 0.214, 0.214). You can use the Colorspace Conversion node to transform from "Linear" to "RGB" (aka sRGB) color spaces.
     
    wheee09 likes this.
  3. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    Ah... Thanks @bgolus!

    I did explore the Colorspace Conversion node but I had it reversed - I was trying to go from Linear to RGB like you suggested but it didn't work.

    I think the reason is because I had already changed the color space at the project level (Settings -> Player) to Linear already.

    Something seems amiss with how the Shader Graph treats color space here that is not intuitive, but thanks to you, cleared it up so I can get past this.

    Thanks again!
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    If your project is set to use Gamma Color Space (which is really sRGB color space) then the conversion isn't needed. A value of 0.5 in the color node and a Vector3 of 0.5 will produce identical outputs since all of the rendering is already happening in that space. It's only when rendering using Linear Color Space that this is an issue.

    Yep, my bad. I said that in a confusing / backwards way.
     
  5. Peter-Bailey

    Peter-Bailey

    Joined:
    Oct 12, 2012
    Posts:
    36
    I keep having to use colorspace conversion nodes in my graphs when working in linear colorspace. Would it be better for performance to just switch my project to gamma colorspace, since I wouldn't be using as many nodes in my shader graphs? I could always fake linear space lighting with a toon ramp, right?