Directional lightmaps

Hey everyone,

Beta 13 includes quite a few improvements to directional lightmaps. Here’s a quick overview of the feature.

Directional lightmaps store more information about the lighting environment than regular lightmaps. Shaders can use that extra data about incoming light to better calculate outgoing light, which is how materials appear on the screen. This happens at the cost of increased texture memory usage and shading time.

You can choose one of 3 modes: Non-directional, Directional and Directional with Specular. All 3 are available as realtime and baked lightmaps.

Non-directional: flat diffuse. This mode uses just a single lightmap, storing information about how much light does the surface emit, assuming it’s purely diffuse. Objects lit this way will appear flat (normalmaps won’t be used) and diffuse (even if the material is specular), but otherwise will be lit correctly. These barrels are using baked lightmaps. The only detail definition comes from a reflection probe and an occlusion map.

Directional: normalmapped diffuse. This mode adds a secondary lightmap, which stores the incoming dominant light direction and a factor proportional to how much light in the first lightmap is the result of light coming in along the dominant direction. The rest is then assumed to come uniformly from the entire hemisphere. That information allows the material to be normalmapped, but it will still appear purely diffuse.

Directional with Specular: full shading. Like the previous mode, this one uses two lightmaps: light and direction, but this time they’re split in halves. Left side stores direct light, right - indirect. Unlike the two other modes, light is stored as incoming intensity. That extra information allows the shader to run the same BRDF that’s usually reserved for realtime lights, resulting in a full-featured material appearance - now also interacting with indirect light.

Performance: the Directional mode uses twice as much texture memory as Non-directional lightmaps and has a slightly higher shading cost. Directional with Specular uses twice as much texture memory as Directional (it also uses two textures per set, but they’re split in two, so twice as many sets are needed). It’s shading cost is comparable to two un-shadowed lights, as it runs the BRDF twice - for direct and indirect light.
Non-directional: 1 texture, 1 texture sample, a few extra shader instructions.
Directional: 2 textures, 2 texture samples, a few more extra shader instructions.
Directional with Specular: 2 textures, 4 texture samples, high extra shader cost (~two un-shadowed lights).

Realtime lightmaps take advantage of the same approach, and are subject to the same shading quality/cost tradeoffs. The only difference from the list above is that the Realtime Directional with Specular lightmap uses 3 textures (incoming intensity, direction, normal), taking 3 texture samples. It has a shading cost of one un-shadowed light, as it runs the BRDF only once. It works in combination with a realtime direct light, of course, which has it’s own shading cost.

The BRDF that is actually used for indirect light (Directional with Specular realtime and the indirect part of baked) is a slightly less expensive version. UNITY_BRDF_PBS_LIGHTMAP_INDIRECT is defined in UnityPBSLighting.cginc.

The Directional with Specular mode pushes the lightmapper to the limits of the GI technique it uses, which in some cases leads to artifacts. These are most often patches of incorrect dominant light direction, causing dark or black shading. Some of these issues can be fixed increasing the Realtime/Indirect Resolution, others will be fixed by us before the release. If all else fails, the simpler lightmap modes are more robust.

13 Likes

Why this thread not stickied??

1 Like

No reason for it to be sticky, I think.

well honestly, this is a good information for me. And also enlighten are kinda new for most people here. just kinda shame if this thread gone under all of the thread

Isn’t there some overlap here somewhere…?

Specularity and reflection are in reality, the same thing. Assuming you have everything covered with somewhat proper cubemaps, doesn’t adding indirect speculars on top of that redundant or even… wrong?

You are correct that there’s no distinction in real life between specularity and reflectiveness. But in realtime graphics they’re typically handled separately, for a number of reasons.

I understand that. For example lightsources might not typically appear in cubemaps, so you need some sort of specularity from those, plus speculars from direct lights will be much more accurate than any cubemap can provide.

But with directional specular lightmaps, where speculars are generally inaccurate and with the new Unity workflow strongly favouring having a little reflectivity in everything and cubemaps eveywhere, things that look like speculars do appear, so I feel there is some redudancy in doing indirect speculars after that.

I’m not arguing against the feature, more tools and features are always welcome.

Reflection probes’ resolution is per object, at best. That means a specular highlight from a point light will travel with you as you go across a plane, for example. And it wouldn’t be shadowed. OTOH directions stored in lightmaps can vary from texel to texel - they’re very local.

But there might be very specific scenes, in which rendering hdr light discs into reflection probes would be preferable, I agree.

Fair enough, I think I understand more now. Thank you.

I definitely appreciate this feature, if only so we can use our own BRDF for some of the ambient lighting.

How do/should the two new Directional Lightmap modes compare (in performance) to the pre-5.x Directional Lightmaps?

4.x directional lightmaps compared to the new “Directional” mode had a slightly higher shading cost and used as much texture memory.

I assume you mean Directional as in not Specular Directional (I should’ve been a bit more specific)?

Yes. :slight_smile:

Hi robert,
with the realtime lightmaps the unity crew should think about to struct and load lightmaps dynamically.
Amplify does this with textures in Unity, I think you know already.

I think the whole streaming thing would be fine for this going forward once Unity gets around to it. I thought about donating a 3D printer to Unity so we could have more Robert’s making cool engine features, but sadly it doesn’t print his size, and lots of mini Roberts running around would be chaos.

In any case - nice work. It looks convincing. Be nice to see how it interacts with a moving light.

The shots above are wrong in the sense that the object in shadow isn’t as dark as the floor shadow, but that’s probably for a number of reasons.

Great feature and work from Robert! He spend so many time in usefull and great features to bring Unity to the top. So we understand that he have a low message quota.

Super stuff - it’s really coming along nicely :slight_smile:

Ha, ha, thanks guys. :slight_smile: I hope you’ll like it.

The truth is that we can’t store the entire lighting environment per texel. Not even close. And even if we could, we wouldn’t be able to use all that data efficiently in the shader.

So what we did was to look at the whole spectrum of possible approximations, test a number of them on our demo scenes and pick 3. Hopefully each will give you the most bang for the buck, and artifacts or cases in which these methods don’t fare well won’t give you much trouble.

Then there are different methods with different trade-offs. For instance, RNM handles some cases better than our “Directional” mode, but only those cases and it’s always ~50% more expensive in terms of memory and instruction count. But I’m not aware of methods strictly better than ours. For example something giving as good results as “Directional with Specular” in all cases, but cheaper. Or same performance, but looking better in a wider set of scenarios.

If you do know of a method that’s strictly better than one of those, please let me know :slight_smile: Or if you’re convinced that a different trade-off would be better for most users.

You can update the official documentation with these infos. Seems to be made for it :slight_smile: