Search Unity

Emission intensity not working correctly in inspector

Discussion in 'Editor & General Support' started by shaderbytes, Sep 27, 2018.

  1. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Hi All so I discovered some odd behaviour with the emission inspector:

    Start of by setting a color , r =1,g=0.5,b=0.5 , intensity zero. Now change the intensity up by one. You will see r has become 2. Ok now reset the color to the initial values and also the intensity back to zero. Now manually start to change the color values, Firstly the intensity is only controlled by the highest color component, which would be the r value here , so go ahead and change r to 2. Notice the intensity value? It is not one but rather 1.416925. Changing g and b has no effect ( so long it is less than r )

    Unity 2018 2.2f1

    Actually the whole logic of intensity needs to be reworked. Currently since it is treated as an exponent, setting it to zero just results in the emission color unmodified ( anything power of zero = 1 )

    Think of this from a programmers point of view , so you want to interpolate between no emission and some emission value. It used to be a scalar of this nature so setting it to zero resulted in what ever the emission color value is becoming black so there was no emission. Now this is not possible anymore, well not in a easy manner, now you need two color values, the emission color and black. If you want no emission you need to set the emission color to black, ( or rather use some abnormal negative intensity value ). When you do want emission you then have to set it again to the color you want, and of coarse have to jump through all the hoops of multiplying by 2 to the power exponent thing.

    It is simple, here is what it should be :

    The emission color is the color. You should be able to set this without any convoluted multiplying.
    The intensity is the intensity. You have no means to currently set this directly via code. It should be a scalar so that zero results in the emission color becoming black ( since all its component values are multiplied by zero )

    materialInstance.SetColor("_EmissionColor", yourColorValue);
    materialInstance.SetFloat("_EmissionIntensity", yourIntensityValue);

    Again intensity zero should scale the color to black , intensity 1 would result in the color as is etc.

    So now think how easy it would be to interpolate the emission, set the desired color , set the desired scalar. easy.

    If you really wanted to have the exponent thing you could create another variable for this. First cap the Intensity to the 0-1 range so it is a percentage scalar, then add the exponent variable ( default to 1 ) :

    materialInstance.SetFloat("_EmissionExponent", yourExponentValue);

    all sorted ;) Just an idea, anyway as pointed out in the opening paragraph the current set up is not working correctly as is , so some work on this need to be done anyway.
     
    Harinezumi likes this.