Upgrading a Unity project to Unity 5: Shaders and lighting


  Not long ago Unity 5 has been released. There's lots of new things in Unity 5 but unfortunately the documentation hasn't been created yet.
  Owing to my job as a technical artist I had to give up everything and upgrade a project to Unity 5. Recently Apple required developers to create 64-bit apps.

 Once you open a project in the new version you'll see... nothing, or almost nothing. Unity 5 doesn't recognize old shaders that use alpha and just fills it with a black or white color depending on the shader implementation.
 Good old Beast got retired so you'll have to rebake the lights too. All the info below is partially from Unity3d website and my experience.
  To those who have updated to Unity 5.

Standard shader

Useful links:

Why your old and custom shaders don't work;
Official tutorial on shaders.

A new standard Unity Shader for each platform is assembled separately, that is the unused fields won't be written into the resulting shader. Shader optimization is made due to the target platform. When a standard shader is building 2 important things are happening:

  • All properties that wasn't used are cut out of the further build (or maybe they use presets);
  • The assembled shader is checked and optimized for a type of device (defined in Build Settings), that's why there's no need to worry about the productivity.

Standard shader parameters are divided into 3 sections:

Rendering mode is the way your shader is being rendered (transparent, semi-transparent, straight texture or a color).

  • Opaque. Non-transparent mode, rendering is going to be carried out without alpha;
  • CutOut. It's the Alpha Testing, the Alpha Cutoff parameter defines a border between 2 states: totally transparent and non-transparent;
  • Transparent. Believe it or not this represents semi-transparency, for example you can use it to get glass effect, alpha in Albedo is used to adjust transparency.
  • Fade. Basically it is the same as Transparent but allows you to make an object absolutely transparent.

Main Maps is the group of the properties that describes the main texture and its properties.

  • Albedo is the main texture and/or color, alpha (RGB + A) influences the reflection and transparency, in different rendering modes.
  • Metallic (when Standard) specifies the level of reflecting the environment by a material, when set to 0 the material looks like a dull plastic, when it's 1 the material looks like a metallic or a mirror-like material. By using a white color or texture you can get the material similar to Metal. I recommend you to use shades of grey. The R-channel in the texture is in charge of the property called Metallness, in A-channel (alpha) it controls smoothness.
  • Specular (when Specular Setup) defines a color of the reflection and its brightness from alpha.
  • NormalMap is a magical texture for 3D appearance: takes a vector (x,y,z) from a pixel (r,g,b) and brings in additional detailing during illumination. (and other effects, SSR, e.g.) Gives the three-dimensional effect.
  • HeightMap is the second one magical texture, also known as map of heights, it's required for either Displacement-mapping (with tessellation) or Parallax Occlusion.
  • Occlusion is the property that works with a texture (black and white) and darkens on a texture. E.g. shading of the bricks borders on a brick wall.
  • Emission. This specifies the color of the object reflection.
  • Detail Mask can be used to lay a mask on the Secondary Maps.  

For properties Albedo, Metallic and Emission a texture is just an option and is NOT NECESSARY.

It's possible to set the color for properties Albedo and Emission but for emission a color can't be set when scale is set to zero.
Secondary Maps is the group of properties that describes the second texture which is laid on top of the main one.
An example of use from the video-tutorial is shown on a patterned fabric where Main Maps has a color and a texture set. Secondary Maps lays an embroidery-like pattern and its texture on.


I've found some documentation for GI but haven't come across any settings that worked out. That's why I was experimenting with different baking properties. All the properties were accomplished experimentally after reading manuals from the official site, blog and forum.

It came in really useful for me to download the Viking Village project.

Currently I'm working on a robust 3D project for tablets. I have got static shadows, light probes and a light source. I use directional light and the baking settings set to Mixed.

Surprise #1: You got 10 Gb cache in Local Settings. You may take a look at this disgrace by clicking Edit->Preferences.

IT'S not self-cleaning, you will have to do it with your hands.

About the first bake:
My system is located on 256GB SSD, that's why I transferred cache on a regular hard drive. To be honest I haven't noticed any difference in the bake speed even though plenty of textures are generated. The first bake of the scene with 100k polygons on default settings generated 200 maps (light + dir) that took 1 GB of memory (The process was carried out on a Intel I7-4770 processor, with 32 GB of memory). Unfortunately it was down the drain.

Review of new possibilities

Currently Unity is using the technology of the real-time Global Illumination (GI) called.

It's using a dynamic GI for the direct lighting and shadows. They are calculated in real-time using GPU (Graphical Processor Unit) of the device.

Real-time GI needs to be pre-calculated. And you won't get a lightmap as it used to be in Beast, you will most likely get a LightmapSnapshot. This thing is pretty heavy because it contains copies of your Lightmaps. In the build this LightmapSnapshot less. I don't really know what's happening under the hood.

Description of the Lighting tabs

As an example I will use the Viking Village project, then Window->Lighting, tab.

This scene is baking for a half of an hour and it's really awesome.

The baking process is conducted in 2 phases: first one is divided into 11 sub-stages and the second one into 15. For Baked GI it glitches at 5/11 Clastering, 7/11 LightTransport, 4/15 Bake AO, 6/15 Bake Visibility 12/15 BakeInderect.

Scene Tab. Environment Lighting

The lighting should be Baked or Mixed, which will help to switch smoothly between a baked and real-time calculated GI modes.
Properties Skybox and Sun are not required and can be left empty.
SkyBox a property to simulate the sky or other distant background
Sun. When a SkyBox is used you can set direction of the lighting or the (or any other big distant light source that is illuminating the scene. If this is set to None DirectionalLight is gonna be considered eternally-remote like the Sun.
Ambient Source is the source of dispersed light (Ambient Light) that is present all around the scene. There are 3 options for the source of the ambient light:

  • SkyBox. In Skybox field you should set a material with a Cubemap (something like that). Skybox uses the colors of the skybox in order to determine ambient light coming from different angles.
  • Gradient lets you choose the color separately for ambient light from the Sky Color, Equator Color and Ground Color and blends smoothly between them. Looks kind of like that.
  • Color is a color of all ambient light in the scene.

Ambient Intensity the brightness of the ambient Light in the scene, goes from 0 to 1.
Ambient GI. The property is only available when Precomputed Realtime GI and Baked GI modes are turned on. It allows you to choose a mode (Precomputed Realtime or Baked GI ) that is going to be used to handle the ambient light.

Reflection Source allows you to choose whether to use the Skybox for reflection effects (the default) or choose a Cubemap instead. If the Skybox is selected as the sourcean additional option is provided for determining its resolution for the reflection calculation.
Reflection Intensity level of the effect of Cubemap or Skybox reflections on the scene.
Reflection Bounces how many times the object reflection is going to be reflected. Speaking of that a mirror passage comes to mind.

Precomputed Realtime GI

Realtime Resolution sets the number of texels that are going to be used per unit of length for objects that are being lit by real-time GI. Usually this value is approximately 10 times smaller than the resolution of the baked ones. It can be a float number like 0.5.

CPU Usage determines how much you can load your CPU in the editor when baking textures in real-time.

Baked GI

Baked Resolution sets the number of texels (i.e. Texture pixels), that will be used per unit of length for the objects that are being lit by Baked GI. For a quick prototyping use values in range from 1 to 4.

Baked Padding distance on a texture between the baked objects in texels.

Compressed will the texture be compressed? If yes, it will less but unwanted artifacts may be introduced into the texture.

Ambient Occlusion relative brightness of surfaces in Ambient Occlusion i.e. shading on the internal angles. Higher values resulted in higher contrast between the shaded and lit spots. It can only be applied with the Indirect lighting calculated by the GI system.

Final Gather. When the option is enabled the final bounces that you get in the GI calculation will have the same resolution as the baked lightmap.

General GI

Following parameters influence reflected light in Realtime and Baked GI modes: Ambient, Light Bounces and Emissive materials but not the reflection.

Indirect intensity scales the brightness of Indirect Light. You can check your Indirect Light in menu Scene Window->Irradiance.

Bounce Boost determines to what extent the light is bounecd from one surface to the other. Reflected light is multiplied by this value. By default it's set to 1.

Directional Mode. It basically specifies whether you need to save the information about Directional and Specular into lightmaps when in Baked GI mode.

Atlas size Lightmap size when baking in Baked GI mode. I usually set it to 1024px.

A Lightmap Paremeters property has been added In Skinned Mesh Renderer. This property is in charge of the objects grouping, e.g. inside or outside of a building, by levels or scenes, manually or automatically set etc.

My custom setup for a quick bake.


Precomputed Realtime GI

  • Resolution. It is the resolution of the final lightmap in texels to world units.

  • Cluster Resolution is a ratio of the cluster resolution to the final lightmap resolution, i.e. the resolution which is used to calculate the reflected light.

  • Irradiance Budget specifies the accuracy of calculating the data about falling light for each texel on the lightmap, i.e. a pattern of falling light is written. Lower values result in blurring of the lit part borders, higher values lead to more distinct borders. Be careful with this parameter because it directily loads your memory and CPU when baking.

  • Irradiance Quality the quality of conveyance of the reflected light on a lightmap. The value doesn't affect the final result on a device, but increases precomputing time in the editor. As far as I understand this property is identical to the Final Gather Rays property in Beast but applies to reflected rays. The more rays you have the better quality you get but on the other side the bigger baking time you get.

  • Backface Tolerance. This allows to neglect the lighting of those texels that aren't sufficiently lit (e.g. the ones inside a mesh), and the calculation of their illumination is implemented by interpolation with the adjacent texels. Helps avoiding unwanted artifacts.

  • Modelling Tolerance is the maximal size of the holes in the grid geometry that can be neglected when calculating GI.

  • Edge Stitching. When the option is enabled UV charts will be baked with lightmaps, in order to avoid visual artifacts.

  • Is Transparent. If the property is enabled all transparent objects remain transparent while GI is being calculated. At the same time back faces aren't taken into account and the light is coming through the object. Can be used to make invisible surfaces radiate.

  • System Tag is a group of objects with lightmaps in one atlas. It's also the detailing that calculations depend on. A few System Tags are created automatically if there's plenty of objects in the scene. Different System Tags may be used whether for different levels in a location or for different level parts.

Baked GI

  • Blur Radius is the radius (in texels) of the blur filter that is applied to direct lighting during postprocessing. This radius is the distance over which adjacent texels are averaged out. Higher levels of blur tend to reduce visual artifacts but also soften and smooth the edges of shadows.

  • Antialiasing Samples The degree of antialiasing (ie, reduction of texel artifacts) that is applied.
  • Direct Light Quality the number of rays. It is used to evaluate direct lighting (absolutely identical to the Final Gather Rays in Beast). Higher number of rays results in more accurate soft shadows.

Baked AO

  • Quality is the number of rays that are cast for evaluation of ambient occlusion (AO).
  • Antialiasing Samples is the degree of antialiasing (ie, reduction of blocky texel artifacts) that is applied.
  • Baked Tag similar to System Tag,lets you group specific sets of objects together in their own baked lightmaps to facilitate dynamic levels, etc. As with the System Tag, the exact numeric value is not significant; objects use the same baked lightmap if they have the same Baked Tag value.

General GI Directional Lightmapping.

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 three modes:Non-directional,Directional and  Directional with Specular. All three are available as real-time and baked lightmaps.

Non-directional: flat diffuse T

he simplest mode that uses a single lightmap. It stores the information about how much light the surface emits, assuming it's purely diffuse. If the objects have NormalMap or diffuse light they will appear flat and diffuse, but otherwise will be lit correctly.

Directional: normal-mapped 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, and 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.

Dual lightmaps allow using specular surfaces and normal mapping.

Directional uses twice more memory compared to Non-directional and has a higher shading cost.

Directional with Specular uses twice more memory compared to Directional.



All data posted on the site represents accessible information that can be browsed and downloaded for free from the web.




User replies

No replies yet