Tool and Shader

Virtual Light Based On Unity Light Probes – Tool and Shader

Problem:
Lightmapping adds greatly to the realism of a scene. After lightmapping a scene all static objects have nice, high quality lighting. If we don’t do anything about the dynamic objects though, they might look dull and detached from the environment with their direct light and ambient only.The solution is to use light probes to sample the nice baked lighting at various points in the scene.
One Problem with Unity 5.02 is object lighten up by light probes in Gamma color space looks super bright and less realistic. It looks very different than static object with same material.
Problem Solving:
The tool I wrote to solve this problem is a virtual light system, based on the Unity Light Probes technique. The tool will go through every light in the scene(including directional light, spot light and point light), and add the light directions together with different intensity weight. With this calculation, it can get a direction where object has the highest intensity of lighting. Then use this direction as a world-space normal to sample light probes using Spherical Harmonics(SH). After light probes sampling, it can get a RGB value as the color for virtual light. Then the color and direction information of virtual light can be passed into shader. With a virtual light system setup in shader, it can light up dynamic objects with full illumination, using a virtual directional light. With this tool and shader, users don’t need to choose “Use Light Probes” in Unity for a dynamic object. The tool can light up dynamic objects with high quality and realistic lighting. User can also control the virtual light intensity with a controllable parameter in the tool.
Screenshots:
virtual light 01
intensity new
Video Demo:

Automatic GI – Tool

Problem:
When using Precomputed Realtime GI system in Unity 5.x, it will precompute all possible light bounces and encodes this information in “LightmapSnapshot.asset” file for use at runtime. The precomputed file will be generated by pressing the Build button in the Lighting window. This file contains the GI data and all the supporting files needed when creating the lighting for a scene. When using Precomputed Realtime GI system for a big and complicated game scene, this file will be very bloated. To make matters worse, in current Unity version, this file contains data for multiple platforms, which makes it more burdensome. Additionally, precomputing for a big scene will take a long time.
Problem Solving:
Because “LightmapSnapshot.asset” file is bloated, how to reduce asset size is a crucial problems. There are two main causes which can lead to a big asset size. The first one is Precomputed Realtime GI resolution, and the other one is the number and the shape of objects which are included in the realtime GI calculation. To solve this problem, we can divide the objects into two groups, one is lightmap static objects group(will be calculated in Precomuted Realtime GI system), another one is lightmap non-static objects group. Objects that are not lightmap static will not be lit by global illumination, neither precomputed GI or baked GI. In order to make them realistically rendered, we can let these objects lit via light probes.
The Unity Editor Tool I wrote can help artist set GI automatically. It will go through every game object in the scene and calculate mesh information, such as volume and area. It will divide these objects into two groups according to the mesh information and mesh type, and automatically set up GI for the scene. With this tool, you can also easily check the result and do some further changes after one-click setup.
QQ图片20151228222031
How To Use:
Step 1: In order to clearly see which objects are currently in Realtime GI and which objects are using light probes, first you need to choose color for each type.
20151228210738
Step 2: After color setting, you can choose either “Set GI For The Whole Scene” or “Set GI For Selected Object(s)”.
QQ图片20151228212914 — Scene From Unity Viking Village Demo

Step 3: When you are satisfied with the result, you can click “Turn Off Color View” and exit the tool. This button is only for turning off the color preview. It cannot cancel the setting we did.
Step 4: Those steps are all you need to do to automatically set GI. You can also do some further changing by hand after automatically setting, and you can always click “Update And Turn On Color View” button to check the current status after changing.

Automatic Light Probes Placement – Tool

Problem:
Only static objects are considered by Unity’s Baked or Precomputed Realtime GI systems. It is impossible to calculate lightmapping for moving objects in real time. As a result, non-static objects in the scene are less realistically rendered and can look disconnected. In Unity 5 we can record the lighting information into Light Probes Group(LPG) which can be quickly read and used in our lighting equations during gameplay. However, LPG has to be placed by hand. It can be incredibly tedious and inefficient for a big level with complicated terrain.
Problem Solving:
I wrote an Unity Editor Tool for artist to easily designate fields within the scene to automatically populate with an even distribution of Light Probes. The arrangement of the LPG is based on the ground of the scene. There could be three kinds of possibilities for the ground, Unity Terrain, game Object or a value. User can choose any one of them.
How To Use:
Step 1: Choose a ground type from Unity Terrain, custom value or game object. If you select Unity Terrain, the tool will use main terrain of the scene automatically. If you select custom value, you need to enter in a value as the ground. If you select custom game Object, you need to drag a gameObject into the field as the ground.
Step 2: Set subdivisions for axis X, Y and Z. The subdivision of Y axis means how many layers of LPG. After setting, click “set height value for each layer” button.
Step 3: Set height for each layer. It means the distance from probe to the ground you choose in step 1.
Step 4: You need to choose an area in the scene to set LPG. With this feature, you can selectively choose area that you want to set LPG. You may not want to set a LPG in the zone that player will never walk into. So in this step, you need to select some game objects in the scene. They are the boundary objects of axis x and z. Additionally, you can also choose one big object, like a game object terrain.
Step 5: Click “create light probes based on the boundary gameObject(s) selected” button. It will create a game Object named “lightProbes” in the scene.
Step 6: Click “locate created light probes” button will help you select the LPG you just created easily and quickly.
Step 7: If you are not satisfied or don’t need it anymore, you can click “delete created light probes” button to delete it.

Video Demo: