Change in Light intensity between Unity 4 & 5 !?!

Hello,

I’m currently upgrading my project to Unity 5, and I just got a puzzling issue.
I’m using “Legacy Deferred” rendering path, with lighting customization in Internal-PrePassLighting.shader & UnityDeferredLibrary.cginc (as exposed here, but using U5 files instead => Easiest way to change Point Light attenuation ? (with Deferred path) - Unity Engine - Unity Discussions ).

As you can see on the following screenshots, the result is almost identical (don’t mind the red lines, they pulse with time :wink: ).

Unity 4:


Unity 5:

The light’s intensity on the wall in this scene is 1.35.

But for the light I put on the camera, the result is quite different ; to get a similar result, I had to raise its intensity from 0.75 (on 1st following screenshot) to 1.2 (on 2nd following screenshot):

Unity 4, 0.75 intensity :

Unity 5, 1.2 intensity :

And it’s even worst with low intensity, I had to raise from 0.055 to 0.35 to get a similar result. (screenshots in following post)

Of course, light ranges, light colors & ambient colors are the same, and I’m using Linear color space in both cases.

Anyone would have any idea what’s going on, why it doesn’t produce a similar result when using similar intensity ? :hushed:

Unity 4, Intensity 0.055 :

Unity 5, Intensity 0.35 :

Unity 5, Intensity 0.055 :

I triple checked and I think the issue comes from a modification I did in Internal-PrePassLighting.shader ; I can’t figure out why the calculation doesn’t produce the same result than before for now, but I’ll sleep on it and maybe I’ll figure it out tomorrow… :face_with_spiral_eyes:

Did you check out this page from the Docs?

http://docs.unity3d.com/Manual/UpgradeGuide5-Shaders.html

"Shaders no longer apply a 2x multiply of light intensity…"

Might be relevant to your conundrum - otherwise gamma/linear lighting settings could be worth investigating

@OllyNicholson ,
thanks for the answer.
It can’t be the x2 because I’m using the built-in legacy U4 Shaders.
My guess was that it could be about gamma/linear space, but I thought it didn’t make sense for the light color… But after more digging, I found out that Luminance() (in UnityCG.cginc) has been changed to better handle Linear space ! It is not the culprit though, as it’s used only for Specular color (I tried using the U4 Luminance() and it almost didn’t change anything), but I wonder if something similar could have been done to _LightColor ? I looked but couldn’t find anything assigning it, so I’m not sure what to do about it…

pffff… I created a small test project with only a 0.055 intensity light in U4, then converted it to U5, and boom, the light intensity has been raised to 0.366 !
A quick look at the 5.0 release notes solved the mystery => http://unity3d.com/unity/whats-new/unity-5.0 :

But there’s still an unsolved mystery : 0.055 ^ (1/2.2) = 0.268 , not 0.366 …! :hushed:
@OllyNicholson , any chance you could tell me what is the conversion formula ?
I checked and Mathf.LinearToGammaSpace(0.055) gives me 0.26 , so I have no idea where this 0.366 comes from…

Note: the light intensity of 1st screenshot of U4 is probably not 1.35, but whatever the value was before the project conversion… It was a prefab, so it got converted, while the light intensity on my camera is set by script, so it wasn’t converted… :face_with_spiral_eyes:

Sorry - I’m no mathmetician, and I didn’t write the code hopefully someone else will chime in :wink:

I just filled a bug report to raise the chance of someone chiming in ! :stuck_out_tongue:

Anyway, I think I have solved the equation by converting a U4 project with 2 additional intensities :

  • 0.75 got converted to 1.20
  • 1.0 to 1.37

So it gives :
NewIntensity = Mathf.LinearToGammaSpace(OldIntensity) * 1.37
This formula matches the observed results for 0.055, 0.75 & 1.

1 Like

Good work - there might be a higher chiming in chance if you post the bug ref number here so developers interested can check it out :slight_smile:

Oops, forgot to answer this…
So the Bug N° is : 689839 .