Search Unity

Use vertex color as emission color?

Discussion in 'Shaders' started by alanmthomas, May 17, 2017.

  1. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    197
    I'm looking for help writing a shader that does the following:
    1. Takes the current vertex color and inverts it(i.e. white becomes black)
    2. Uses that vertex color as the emission color
    Any help is appreciated. It seems like it should be a pretty basic thing to accomplish but I can't for the life of me figure it out.

    Thanks!
     
  2. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    For emission to "work" you need a HDR RenderTarget (just tick that checkbox on your camera) and a post processing effect like Bloom (see Image Effects) on your camera.

    Inverting a color:
    vertColor = 1-vertColor;

    Emission:
    You need to push the color beyond 1.0f which means you need to specifiy an additional vertex color multiplier to the shader as a property becaus vertex colors are clamped:
    vertColor *= _EmissionMultiplier;

    Note:
    You can multiply black with any number you want. You'll get 0.0f as final output.
     
    Last edited: May 24, 2017