Search Unity

Alternative to "Directional specular" in Unity 5.6

Discussion in 'Global Illumination' started by TheShock, Dec 16, 2016.

  1. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    • GI: Deprecated the directional specular lightmap mode in Unity 5.5, since it will disappear in Unity 5.6 (as part of the lighting modes functionality).
    Directional specular lightmap is very important for my game and I dont see alternative for it in Lighting window preview 2

    E.G. i have such room without lightmaps:
    baked-removed.jpg

    It can be correctly baked in Unity 5.4 in "Directional specular"
    baked-old.jpg

    But it is totally broken in new Unity light system and I dont see any way to fix it:
    baked-new.jpg

    Okey, Directional specular is deprecated, but what should I use instead of it?
     
  2. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Is here anyone who can answer my question?
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    The alternative is to rely more on reflection probes/SSR and switch some of those lights to stationary (as they are called in the new 5.6 beta) so you can get "real" speculars.
     
  4. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    I have the same question as OP.
    Reflective probes and SSRR are on expensive side in deferred pipeline. I assume that if OP use baked lighting that means that performance is a bottleneck.
    And regarding stationary lights. It's a cool addition. I've been waiting for such functionality for very long time. But again. If performance is a bottleneck than stationary lights wouldn't help. For example. Forward rendering pipeline gives good performance and we could get more or less good lightmaps with directional specular approach. But now we would need to use stationary lights. But there is a limit for number of pixel lights. And pixel light = more performance cost. Reflection probes works OK in forward rendering if there is one probe per room and rooms are separated objects. And rooms should have simple shape.
    So it looks like that we have to find a workaround get specularity back without big performance hit.
    I'd love to know official solution.
    Because right now it looks like:
    - Oh, we've deprecated this feature in new update and we don't have any alternatives for you. Good luck.
    UPDATE:
    It looks like that I've missed the update of Reflection probes for forward rendering path. They work just fine now. But deferred probes are broken :)
    Forward rendering, box projections:

    Deferred rendering, box projections:


    Nah, sorry, probe blending issue is still there in forward rendering path:

    And it's not better in deferred:

    So, broken :(.
     

    Attached Files:

    Last edited: Dec 27, 2016
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    In deferred path, change the reflection probes' "Blend distance" to 0 and then they will be as "accurate" as the forward ones.
     
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Also, if graphics performance is a bottleneck, you shouldn't be using Directional Specular in the first place, since it was quite expensive.

    Means if you want some specularity, you can add a couple of realtime lights without shadows and you will have proper speculars and be on par performance wise.
     
  7. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    I agree, it's more expensive. But wouldn't it be more expensive to use only reflection probes and realtime lights for specularity? I mean there would be way more than just 1-2 reflection probes/lights for scene like de_dust2 or similar, wouldn't it?

    And regarding adding lights it really depends on level setup. Night street with street lights. There probably would be a bit more than 2 lights.

    But anyway, I've got your point. Unfortunately reflection probe isn't a silver bullet.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Directional Specular wasn't a silver bullet either though, I mean I experimented with it a lot early on and it was messing things too often to be usable (you sort of had to design the lighting around it, since if the scene had multiple strong sources of light, it would mess things up, and that was very restrictive, for me at least).

    And the impact of lights, at least in deferred and without shadows, is only for the pixels they actually affect, so if they are out of view, they don't impact performance at all. And reflection probes, when they are not realtime and not box projected, are pretty cheap.

    In short, it's kind of a bummer that Directional Specular worked for you and that's it's not available any more, but it was a deeply flawed method. And I think between adding some realtime lights and using reflection probes, you can get better results with similar performance.
     
  9. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    I see your points.
    I've tried to work with deferred rendering in my current project. It has it's pros and cons. And at this point in time cons overweight pros for me.
     
  10. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    But I dont have "a couple of realtime lights", I have hundreds and it works great (really, 60 fps) even on very slow notebook with Directional Specular. I have a ship with up to 100 separated rooms (several point lights in each) and you can see all rooms at one time. Look at this screenshot, here is only 10 rooms (~50-150 point lights), but you can zoom out and see whole ship and hundreds of rooms,

    all-rooms.jpg


    Also you can zoom in and see only one room on full screen. And I cant switch off the shadows of point lights, because light of neighbour room will affect central room and it will work very slowly (hundreds of point lights, remember?)

    wrong-specular.jpg

    And now, in Unity 5.4 it works fast (60 fps) even on low-end devices, I have beautiful shadows and beautiful reflections.

    And I cant get it with reflection probes
     
    Lex4art likes this.
  11. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    When the full screen is something like this:
    TZvgUVF.png

    You can see 18 rooms at one time. Look at this gif and on reflections in the Smeltery while camera is moving:

    KFO6DPxRre.gif
     
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    Two lights per pixel (if it's without shadows), if we're talking about deferred.
     
  13. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    Looks awesome.
    BTW. Have you tried new light modes in 5.6 beta? Looks promising. Especially shadowmask approach.
     
  14. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Thanks)

    Yeap, it becomes flat. Here is example (light is not cloned from game, but it is similar).

    In 5.6 light is not baked (looks good):
    56-dynamic.png

    Light is baked:
    56-no-probe.png

    Light + Reflection Probes:
    56-with-probe.png

    Config:
    56-config.png

    Currently in game (with dual lightmaps):
    54-ingame.png
     
    GenaSG likes this.
  15. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    Try to use Shadowmask approach. Not Distance Shadowmask. I've got quite good results in terms of performance and visual quality with Shadowmask approach. If it fits in your performance budget try to use deferred rendering.
    I use forward rendering + reflection probes + emissive materials. One main light + multiple emissive materials as secondary lights + reflection probes. If I remember correctly, realtime shadows are true resource hogs especially for point lights. So having possibility to bake those shadows is a big win.
    Anyway good luck and keep up the good work.

    P.S. I've experimented with fully baked lighting some time ago. The issue with baked light sources is that they aren't added to reflection probes so get flat image without any specularity. Try to add emissive sphere to separated layer which would be ignored by the camera but not reflection probe. Here is a short video.


    Here is an example. Not the same but you can get some specularity back.
     

    Attached Files:

    Last edited: Jan 22, 2017
    TheShock likes this.
  16. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    The main problem, that in 5.6 version I can get only bad and slow result while 5.4 version gives me cheap and beautiful result.

    Shadowmask approach is bad because of "Shadows are handled with realtime shadows". I have hundreds of point light, its very slow. And it renders the similar picture.
     
  17. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    GenaSG, interier in your video looks great. Very good work with light.
     
    GenaSG likes this.
  18. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    393
    Hi,

    I have similar concerns to @TheShock. We're creating an atmospheric VR game, lighting, shadows and spec so important the get the atmospheric tone right. We are satisfied with Directional Specular, we have 10 plus lights in our scene and can run at a stable 90fps.

    So, is the solution to bake all our lights as Directional then duplicate the lights as non-shadow casters? Aren't all those lights going to destroy performance especially considering we're forward rendering?
     
  19. David-Lindsay

    David-Lindsay

    Joined:
    May 20, 2009
    Posts:
    121
    I wish we had the same option for lightmapping as we do for shadows.

    For example, cast shadows and receive shadows.

    So we could have "Affects Lightmap" and "Receives Lightmap"

    This way, non-static objects in the scene could contribute indirect lighting to bakes.
     
    buttmatrix likes this.
  20. AFrisby

    AFrisby

    Joined:
    Apr 14, 2010
    Posts:
    223
    Seconding this request - there's been plenty of times when I wanted this over the years.
     
  21. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    I'd say that combination of directional lightmaps with reflection probes and emissive materials is closest we can get to directional specular. As far as I understand shadowmask approach has the same issues as lighting with realtime lights minus shadow cost. So several main, preferably non-overlapping realtime lights, and unlimited number of baked secondary lights.
     
  22. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    @TheShock, if you'd send me simple scene and screenshot with how it should look like I could try to hack around. I've spent some time with baked lighting in unity3d 5. So maybe some of those hacks will help you.
     
    TheShock likes this.
  23. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    So I've played a bit with this issue and I think that I've found the workflow to replace Directional+specular.
    Here is an example

    All light sources are baked spotlights with soft shadows. Emissive materials set to a colour of nearest spotlight(blue and yellow in this example). Emissive power set to 5. There is a Reflection probe in the centre of the room.
    Directional lightmap provides light information for defuse materials. The more reflective material is the more it takes information from reflection probe. Intensity of specularity can be adjusted by material emissive values or by intensity of reflection probe. Floor is a checker pattern of non-metal/metal materials with smoothness set to 0.7. Specular reflections a bit misaligned and I don't know how to fix it. Tried to adjust blend distance but didn't helped much.
    Regarding performance. Got 185-195 FPS on my 15" 2013 Macbook Pro with Iris 5200. Results are mostly the same with and without reflection probe.
    Hope this example would be helpful.
     

    Attached Files:

  24. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Hello again. I've just tried to migrate to Unity 5.6.0f3, but I the result is sadly.

    Here is gameplay video, where U5.4 and DirSpec LightMap is used. It looks beautiful and works fast:


    I set camera to "deferred" mode and create in the 20 point lights to get acceptable result:
    IHYpWoB.png

    I dont use shadows, but it looks quite good in realtime:
    2017-04-22 08_18_24-.png

    Reflection Probe still makes image flat and dirty, so I have to turn it off:
    2017-04-22 08_20_33-.png

    But as the result I have two problems:

    1. The lights of room can influence on the neighbour rooms.
    You can see this effect here:
    light-infl.png
    The light is in bottom room, but the top room is illuminated by it. That's why I have to create lights with low radius and cant create powerfull and bright light. All this lights will create garbage lights in neighbour rooms:
    light2.png

    (continue in next message, because of uploads limit)
     
    Phan-Nhung likes this.
  25. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    This light cant be bigger and illuminate the box:
    light-3.png

    2. Second problem is prefomance:
    light-5.6.png

    While in 5.4 version Batches and SetPass calls are 10 times lower:
    light-5.4.png

    So, help me, how can I upgrade to 5.6 in such situation?
     
  26. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Simply baked with Directional lm looks ugly:
    light-baked.png

    Here is Workshop.fbx for experiments
     
    reev4eg likes this.
  27. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    You could try using one reflection probe per room.
     
  28. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Thanks! I use only one R.P. per room, but the result is not good - room becames flat in case of Directional LM + R.P.
     
  29. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Is the way to limit realtime light inside the box, so I can set high intense without influence on neighbour rooms?
     
  30. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    No, there is no way to do that aside from utilizing layer based light culling or implementing custom light types with cutoff planes (like in the new pipe light type from the Adam demo assets).
     
  31. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    Does its source available anywhere? Does it high perfomance for hundred of lights?

    No, several same rooms with same layer can be very close and influence each other =(
     
  32. westingtyler

    westingtyler

    Joined:
    Dec 7, 2013
    Posts:
    34
    I also am very saddened by this change. I discovered this feature of Directional Specular Lightmaps right before they removed it in 5.6, and it allowed baked lights to streak across walls, etc. showing the glisten and glow and bumps perfectly (like dynamic lights). I currently use 5.4 but am hesitant to update due to this removed feature.

    I'm in VR, so "just make all your dozens of baked lights dynamic/stationary" is not performant enough. And "make all your bump maps actual polygon geometry" also doesn't work. "Just have a much better computer, and expect all customers also to just have much better computers, just for this feature" is not a super useful suggestion. And "you just shouldn't have been using Directional Specular if you care about performance," is also not helpful. It worked GREAT.

    Directional Specular Lightmaps in 5.4 worked GREAT for performance and realism.

    Without normal directional light maps, the walls always just look chalky when the bake is done. With them, you can see light bouncing off the walls.

    Surely Unity wouldn't remove the only way to get realistic baked lighting, without some replacement? What am I missing? It's weird we should have to use long, hacky workflows just to get something like a feature we JUST had back.

    These renders use the Directional Specular Lightmaps, and notice the glisten and spatial reflections of baked lights off of surfaces: https://westingtyler.tumblr.com/post/158513150075/improving-the-geometry-and-textures-of-the

    It's kind of devastating because the answer seems to be "spend a LOT more time setting up your lights to get NOT QUITE AS GOOD results" or "have a much worse looking final product."

    You would think Unity would be adding BETTER support for VR as we progress, not worse.
    Is this stuff why people sometimes switch to Unreal?
     
    Last edited: May 25, 2018
    syenet and Kellios11 like this.
  33. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Yes, but also shadowmasks and mixed lighting return to 5.6.x and 2017.x, maybe try that out.
     
  34. pjbue

    pjbue

    Joined:
    Oct 8, 2016
    Posts:
    2
    @TheShock Did you ever find a suitable alternative to directional specular? I'm in the same situation: upgrading to Unity 5.6 lightmapping has significantly decreased the visual quality of my scenes.
     
  35. TheShock

    TheShock

    Joined:
    Aug 5, 2014
    Posts:
    35
    @pjbue, unfortunately, no. I'm stuck with great quality on Unity 5.5.3 and I'm afraid, that important new features will appear in next versions of Unity (e.g. LightProbes in prefabs):



    Deferred realtime renderer is too slow and buggy for me (because of shadows are turned of - the light influence is too wide), plus I'm using several cameras, and I can't use them because of bug - [Deffered+HDR+PostEffects+Several Cameras] doesn't works correctly now.
     
  36. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I would look at unity's otoy integration with lightfield stuff to see if it's at all relevant. I would also look at parallax window shaders, layering billboards etc, there's so much you can do here. Unless you can go inside each room and look around, there's plenty of room for optimisations.
     
    buttmatrix likes this.
  37. rachel_r2

    rachel_r2

    Joined:
    Nov 16, 2016
    Posts:
    2
    Similar situation here @westingtyler , working in VR, directional specular looked amazing, now trying to work with mixed mode lighting and having to use a mixed light to get any specular is killing performance. Incredibly frustrating.
     
    TheShock likes this.
  38. tDevogel

    tDevogel

    Joined:
    Oct 10, 2017
    Posts:
    2
    Bumping. Forward rendering, VR, no SSR available. Directional Specularity was a big loss.
     
  39. syenet

    syenet

    Joined:
    May 13, 2013
    Posts:
    47
    Bump, I think all Unity VR devs who stick with forward rendering(MSAA) should pay attention to this issue, new mixed lighting is destroying the performance.

    Alhough the obsolete Directional Specular looks bad at specular hightlight due to it's calculated per texel on lightmap, and it can't handle shadow blending well due to no specific shadow info, yes it's true, but the reason why VR forward rendering is still utilizing it is simple enough, it does one critical thing right: all 4 data we required for calculating static lights (direct color, direct direction, indirect color, indirect direction) are baked to lightmaps (yes, accumulated result of multiple static lights per texel indeed, but GOOD ENOUGH), and we can calculate the final result of all static lights IN ONE PASS.

    None of the new lighting mode in 5.6 could achieve this crucial thing except for the subtract mode which has no specular at all. In 5.6 or later, if VR devs ever want specular on an object, it has to be realtime lit, and if an object ever needs to be lit by any light other than the main directional light, it requires additional passes, and you're done, the CPU drawcall number explodes, and GPU shades more times.

    I think Unity just forgot the fact that there's still a plenty of VR devs require MSAA and then stick to forward rendering for ultimate sharpness of images.
     
  40. Adam-Bailey

    Adam-Bailey

    Joined:
    Feb 17, 2015
    Posts:
    232
    Going back a while, but in case anyone comes across this while searching I believe this post was looking for the feature you get when setting a lightmap scale to 0? If you set a renderers lightmap scale to 0 it will cast shadows that are baked into the lightmap while otherwise acting as a non-static object and being lit by lightprobes.
     
  41. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Also dealing with this at the moment. Also for a VR project (moving from 5.x to 2018). Haven't got a good solution, a loss of visual quality seems inevitable (trying shadowmask lightmaps and relying mostly on specular from one directional light + reflection probes, but by using shadowmasks you lose 'direct AO' from that light)

    It would be nice if the light baking system was more open/scriptable, rather than the very-fixed-function (albeit with lots of settings) black box system that we've got now, where we keep bumping into limitations/inflexibility, and worse, where features are lost with no way to bring them back

    Off the top of my head, things I'd have recently wanted to try implementing with a hypothetical 'scriptable light bake pipeine' would include:

    1) Bring back directional specular lightmapping
    2) Apply ambient occlusion to shadowmask lightmaps (for 'direct AO')
    3) Put custom data in lightprobes (shadow mask values), and exclude mixed lights from probe bake
    4) Control over scaling of non-HDR lightmaps (e.g. double/quad LDR)
     
    Last edited: Dec 11, 2018
  42. Ilkka-Kuusela

    Ilkka-Kuusela

    Joined:
    May 14, 2016
    Posts:
    5
    Hi,
    Directional specular is basically a shader feature, you don't need to edit the full lighting pipeline to enable it. I was able to get it back by creating a modified standard shader, which renders specular highlights using directional lightmaps.

    Mostly I just re-enabled the functionality that was still in the shader file, hardest part is figuring out how the shader works. You can download the shaders from the downloads page and use them as a base. The relevant code is in UnityGlobalIllumination.cginc, you have to modify UnityGI_Base to use DecodeDirectionalSpecularLightmap function instead of DecodeDirectionalLightmap. And then you have to create a custom shader (I used a copy of standard), which uses the modified UnityGI_Base instead of the original one.

    https://www.shadercat.com/tag/standard-shader/ is a good learning resource on Unity's shader architecture
    I can help you out if you're interested in this approach.

    Of course by switching to your own shader you risk having to maintain the shader on future unity versions.
     
    chrismarch and bluescrn like this.
  43. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I need to have a better look at the current directional lightmaps and see how well it works.

    IIRC, the old directional specular maps were a bit more complex, with separate directions and colours stored for direct and indirect light. But I'm not sure how much difference it makes in practice over what's possible now. Does it still use the magnitude of the direction vector as a 'directionality' value?

    And we've got the option now of using a shadowmask light for a main/sun light - maybe combining that with the new directional mode will give good results for a similar cost to the old directional specular mode?
     
  44. Ilkka-Kuusela

    Ilkka-Kuusela

    Joined:
    May 14, 2016
    Posts:
    5
    Yeah, directionality is stored in direction vector magnitude. The drawback of using a single color+direction map is, that increasing the amount of indirect light will slightly water down the direct highlights due to reduced directionality.

    I believe you can get separate maps for indirect light by enabling realtime global illumination, which moves indirect light to a second pair of textures.

    Can Unity render a shadowmasked main directional light in single pass? That sounds like a good solution for outdoor scenes. For indoor I haven’t found a valid alternative to directional specular lightmapping. I can see why Unity considers shadowmasked lights the correct solution, but with forward rendering they are just too expensive for lowend vr.
     
  45. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I think it will in the ForwardBase pass? - But if you're using custom shaders, you can definitely render a shadowmasked directional light plus baked lights from a directional lightmap in a single pass. (haven't tried distance shadowmask)

    I got the directional specular working using the new directional mode, and it seemed pretty good in the scene I was looking at. Certainly better than specular being missing or all faked based on the main light direction.

    Dynamic objects are more of a pain, as there's no shadowmask value in the lightprobes, and the mixed (main directional) light is baked into the probes. So if you want normal mapping, you've got to some ugly cheating/faking...

    One alternative to lightprobes might be to try and bake a directional+shadowmask lightmap for dynamic objects - for example, a large plane baked at ground level, if the scene was flat, and sample that in the shader instead of probes, to give an approximate light colour, direction, and shadowmask value.

    (Hmmm, maybe we could throw away the SH coefficients in the probes, and replace them with custom data - poking in the lightmap colour, lightmap direction, and shadowmask value from the lightmap texel closest to or below each probe?... does probe blending just linearly interpolate the coefficients, or does it do something more clever?...)
     
  46. Ilkka-Kuusela

    Ilkka-Kuusela

    Joined:
    May 14, 2016
    Posts:
    5
    I’m not rendering specular for dynamic objects yet, but I was going to extract the dominant light from the sh coefficients. It should be pretty straightforward for a single light, as the first order coefficients basically define a direction vector, and directionality could be derived from the ratio between the magnitude of that vector and the zeroeth order coefficient. With colored lighting this will result in different directions for red green and blue, I’d try to average those and render as a single light for perf reasons. I can let you know how it works when I get around to trying that out.

    That said, your idea of replacing probe data with custom values sounds like it would work too. I don’t know how Unity interpolates the probes.