Transfer of the project to Unity 5. Shaders and light


Most recently, Unity 5 was released, in which there are a lot of new and incomprehensible things, and they have not yet managed to create documentation.

Due to my work as a technical artist of all trades, I had to give up everything and urgently make an UP project on Unity 5. Not so long ago, Apple ordered developers to create 64-bit applications.

Opening the project in a new version, you will see ... nothing, well, or almost nothing. Unity 5 does not understand the old shaders with alpha and just fills them with black or white, as someone wrote.

Old Beast has gone down in history and the light will have to be baked.

Below is all the information gathered on the issue: translation of the manual and tutorial from the Unity3D offsite, and some notes (on settings) from me.

Dedicated to everyone who upgraded to Unity 5.

Standard shader

Useful links:
Why your old and generic shaders do not work ;
The official shader tutorial .

Description The
new standard Unity Shader for each platform is built separately, that is, unused fields do not go to the final shader. Shader optimization is performed on the target platform, when the standard shader builds, 2 important things happen:
  • All properties that are not used are cut from the subsequent build (or maybe they use presets);
  • The assembled shader is checked and optimized for the type of device (see Build Settings), so there is no need to worry about performance;

The parameters of the standard shader are divided into three sections:


Rendering mode - visualization mode (transparent, translucent, just texture or color).
  • Opaque - opaque, rendering will be done without alpha; Color is tint the texture.
  • CutOut is Alpha testing, the Alpha Cutoff parameter defines the line between two states: “completely transparent” and “opaque”.
  • Fade is essentially the same as Transparent , but allows you to make the object completely transparent.
  • Transparent - translucent, for example, used for glass, alpha in Albedo is used to control transparency.

Main Maps - a group of properties that describes the main texture and its properties.
  • Albedo - the main texture and / or color, alpha (RGB + A) affects the reflection and transparency in different rendering modes.
  • Metallic (with Standart) - determines the degree to which the material reflects the environment, at zero it looks like matte plastic, and at 1 it looks like a mirror or metal material. Using white color or texture, we get a material similar to metal. Optimal use of shades of gray. Channel R in the texture is responsible for the Metallness property , in channel A (alpha) - Smoothness .
  • Specular (at Specular Setup) - defines the color of reflection and its brightness from alpha.
  • NormalMap is a magical texture for bulk: it takes a vector (x, y, z) from a pixel (r, g, b) and introduces additional detail in lighting (and other effects, SSR, for example). The effect of volume is obtained.
  • HeightMap - the second magic texture, it is also a height map, similar to NormalMap , it is needed for Displacement-mapping (with tessellation) or for Parallax Occlusion.
  • Occlusion is a property that works with texture (b / w) and obscures the “edges” of the texture, meaning Ambeint-Occlussion. For example, darkening the seams of a brick wall.
  • Emission - radiation, the color of the reflection of the object.
  • Detail Mask - can be used to mask on Secondary Maps .

For the Albedo , Metallic, and Emission properties , texture is an option and is NOT required.
You can set a color for the Albedo and Emission properties , but you cannot set a color for Emission when scale is zero.

Secondary Maps - a group of properties that describes the second texture, superimposed on the main.
An example of use is shown on a fabric with a pattern where Main Maps has color and texture, and Secondary Maps overlays a pattern, such as embroidery, and its texture.


I found some GI documentation, but there weren’t any working settings there. Therefore, I translated what I managed to find and tried different baking settings. All settings are obtained experimentally and by reading manuals from off. site, blog and forum .

It was useful for me to download the Viking Village project .

At the moment I am working on a full-fledged 3D project, but for tablets. I have static shadows, light probes and a light source. The type of light is Directional , and the baking settings are Mixed .

First surprise : you have to in LocalSettings sitting 10GB cache. You can look at this disgrace in the menuEdit -> Preferece ...


It cannot be deleted on its own, it must be cleaned by hand.

About the first take:
I have a 256GB SSD system, so I transferred the cache to a regular hard drive. Honestly, I did not notice the difference in the speed of the take, and there a lot of textures are generated there. The first scene backing for 100k polics, with completely default settings, generated 200 cards (light + dir) with a total weight of 1GB (the process went to i7-4770, 32 gig and 24/7 hours of operation). Naturally, all this is down the drain.

Description of New Features

Unity now uses Enlighten's Global Real-Time Lighting (GI) technology.

Uses dynamic GI for direct lighting and shadows. They are calculated in real time using the GPU (graphics processor) of the device.

Real-time GI must first be calculated. However, you will not get Lightmap, as it was in Beast, most likely you will get LightmapSnapshot . This thing weighs a lot because it contains a cast of your Lightmap. This LightmapSnapshot will hit the build in a different size. What happens there I do not know.

Description of Lighting Panels

As an example, I use a project with a Viking village, then Window -> Lighting , Scene tab .
Immediately make a reservation that this scene is baked literally half an hour, and it's really cool.


Baking takes place in 2 stages, in the first 11 stages, in the second 15. For Baked GI, wedges on 5/11 Clastering, 7/11 LightTransport, 4/15 Bake AO, 6/15 Bake Visibility and 12/15 BakeInderect.

Scene Tab. Environment lighting

The light should be Baked or Mixed, which will allow you to smoothly switch between baked and real-time calculated GI modes. Skybox and Sun

properties are optional and may remain empty. SkyBox - property for simulating the sky or background backdrop. Sun - when using SkyBox , here you can specify the direction of light or the "sun" (or any large, remote light source that illuminates the scene). If this parameter is not used (None), then DirectionalLight will become an infinitely distant light source, like sun. Ambient Source - Ambient Light

that illuminates everything in the scene (the correct definition is somewhat more complicated). It can be of 3 types:
  • SkyBox - in the Skybox field you need to specify material with Cubemap ( something like this ). Skybox uses the colors of Skybox to determine the ambient light coming from different angles.
  • Gradient - allows you to assign colors to Sky Color, Equator Color and Ground Color, it looks something like this . This property sequentially smoothly mixes the listed colors.
  • Color - the color of the surrounding light.

Ambient Intensity - Ambient Light brightness , adjustable from 0 to 1.
Ambient GI - this property is available when Precomputed Realtime GI and Baked GI are on . Allows you to select the method ( Precomputed Realtime or Baked / Baked GI ) that will be used for ambient light.
Reflection Source - a source of reflections. Allows you to specify whether to use Skybox for reflection effects (default) or select Cubemap . If Skybox is selected as the source, then an additional option is needed in order to set its resolution for calculating reflections.
Reflection Intensity - the degree to which Cubemap or Skybox reflections affect the scene.
Reflection Bounces - how many times the reflection of the object will be reflected. It is appropriate to recall the mirror corridor.

Precomputed Realtime GI

Realtime Resolution - sets the number of texels to be used per unit of length for objects lit in real time by the GI. Usually this value is about ten times lower than the resolution of baked. May be non-integer, for example 0.5.
CPU Usage - determines how much you can load the CPU in the editor when baking textures in real time.

Baked GI

Baked Resolution - sets the number of texels (for example, “texture pixels”) to be used per unit length for objects illuminated by BakedGI . For rapid protopiping, it is better to use values ​​in the range of 1-4.
Baked Padding - The distance on the texture between baked objects in texels.
Compressed - whether the texture will be compressed. Will take up less space, but artifacts are possible.
Ambient Occlusion - relative brightness of surfaces in Ambient occlusion i.e. dimming at the inner corners. Higher values ​​showed a higher contrast between shaded and illuminated areas. This applies only to Indirect.(indirect) lighting calculated by the GI system.
Final Gather - when this option is enabled, the final light obtained in the GI calculation will have the same resolution as the baked lightmaps.

General gi

The following parameters affect reflected light in Realtime and Baked GI modes : Ambient scattered , Light Bounces reflected light, and Emissive material emission , but not reflection.
Indirect intensity - Scales the intensity of the Indirect light . In the Scene Window -> Irradiance menu, you can see Indirect light .
Bounce Boost - how much light is reflected from one surface to another. Reflected light is multiplied by this value, the default is 1.
Directional Mode - essentially indicates whether to save informationDirectional and Specular in lightmaps with Baked GI mode .
Atlas size - lightmap size when baking Baked GI mode . I usually set 1024px.

A new property is now added to the Skined Mesh Renderer - Lightmap Parameters , this property is responsible for grouping objects, for example, indoors and outdoors, by level or scene, as you set or automatically.


My low settings for fast backup.

Precomputed Realtime GI

  • Resolution - resolution of the final lightmap in tixels to world units.
  • Cluster Resolution - The ratio of the resolution of the cluster to the resolution of the final lightmap, i.e. resolution to which the reflected light is calculated.
  • Irradiance Budget - the value determines the accuracy with which data on incident (incoming) light is used to calculate the light of each texel on a lightmap, i.e. the pattern (pattern) of the incident light is recorded. Lower values ​​blur the contours of the illuminated part, higher values ​​result in sharper contours. You can’t get carried away with this parameter, since it directly loads the operative and percent during the backup.
  • Irradiance Quality - the quality of reflected light transmission on a lightmap. The value does not affect the final result on the device, but increases precomputing time in the editor . As I understand it, this property is equivalent to the Final Gather Rays property in Beast , but for reflected rays. More rays - higher quality, but more and more time to bake.
  • Backface Tolerance - this property allows you to neglect the lighting of those tixels that are insufficiently lit (for example, are inside the mesh), and their illumination is calculated by interpolation with adjacent texels. Helps to avoid artifacts.
  • Modeling Tolerance - the maximum size of the holes in the mesh geometry, which can be neglected when calculating the GI.
  • Edge Stitching - if this option is enabled, UV “charts” will be baked with lightmaps to avoid visual artifacts.
  • Is Transparent - if this option is enabled, objects with transparency remain transparent during GI calculation. In this case, the back faces are not taken into account and the light passes through the object. Can be used for radiating invisible surfaces.
  • System Tag - a group of objects with lightmaps in one atlas. This is also the granularity on which calculations depend. Several systems are created automatically if there are enough objects in the scene. Different System Tags can be used for different levels in a location or parts of a level.

Baked GI

  • Blur Radius - radius in tixels from the blur filter, which is used for direct lighting during post-processing. This radius corresponds to the distance over which adjacent pixels are averaged. Higher levels reduce the likelihood of artifacts and make the edges of the shadow smoother or softer.
  • Antialiasing Samples - the degree of smoothing to suppress artifacts.
  • Direct Light Quality - the number of rays used to evaluate direct lighting (a complete analogue of Final Gather Rays in Beast ). More rays produce more accurate, soft shadows.

Baked AO

  • Quality - the number of rays for calculating ambient occlusion (AO)
  • Antialiasing Samples - degree of anti-aliasing to suppress artifacts.
  • Baked Tag - like the System Tag described above , you can group objects into specific baking sets. It can be used to optimize dynamic level loading.

For Baked Tag and System Tag, the numerical value is not significant, objects use the same lightmap if they have the same tag value.

General GI. Directional lightmapping

Directional lightmaps store more information about ambient lighting than regular lighting maps. Shaders can use this feature to obtain additional data about the incoming light in order to better calculate the reflected / emitted light. This is due to the use of a larger memory texture and shading time .
You can choose one of 3 modes: Non-directional, Directional and Directional with Specular . All three support realtime and baked lightmaps.

Non-directional: flat diffuse.
The easiest mode using one lightmap. It stores information about how much light the surface emits, suggesting its diffuse . If objects have NormalMapor reflect light, they will be shown as diffuse , but otherwise displayed correctly.

Directional: normal-mapped diffuse
This mode adds a second lightmap that stores the dominant direction of incoming light and a factor proportional to how much light in the first lightmap comes in the dominant direction. The rest is calculated if the light came in evenly (over the sphere). This information allows you to calculate NormalMap , but the material will remain diffuse .

Directional with Specular: full shading
As in the previous one, 2 additional latmaps are used here: light and direction, but here they are divided in half. The left side keeps direct light, the right - indirect. The difference is that the light is stored as incoming intensity (illumination). This information allows you to use shaders similar to BRDF shaders, which are usually reserved for realtime lighting . As a result, it is possible to obtain a material with exposure to indirect light.
Dual illumination maps ( Dual lightmaps ) - allow the use of reflective surfaces (specular), normal maps (normal mapping).

Directional uses twice as much memory as Non-directional and has a highershading cost .
Directional with Specular uses twice as much memory as Directional .

I hope for constructive comments, maybe I'm wrong about something. I would be grateful for the advice.

Also popular now: