# UE4 Mobile Physical-Based Rendering and Material Template Design

## 1. Theory

Physically-based rendering is a theory to shade based on physical lighting theory instead of artist painting. That means it's more accurate. Artist need to suit for new pipeline and discript object surface more scientifically.

### 1) Physically Light

Light is technically an electromagnetic transverse wave. Electromagnetic waves can be characterized by frequency or wavelength. Normally, we can assume light as a ray.

When a light ray come to a new surface, some ray will reflect directly, some ray come into surface and after complex interactive with scattering particles, reflect back out of surface, some ray is event directly absorbed, some ray will pass through objects. So, we define these phenomenon as Opacity, Translucent, Diffuse Reflection and Specular Reflection.

About opacity and translucent, they are very easy to understand. But the two reflection(diffuse & specular) are complex to calculation. In the following, we are focus on microfacet theory on simulate two reflection.

### 2) Microfacet Theory

In theory, diffuse and specular reflection are dependent on surface roughness and  metallicity. Microfacet theory think light ray keep simple reflection rules. A roughness surface composed by a lot of micro face. because all micro face face to different direction. That cause light ray will reflection to different direction.

Roughness will affect both diffuse and specular. More rough surface will has less diffuse(not very obviously though). More rough surface will cause specular spread more area and more dark(energy conservation).

Metalicity will cause weather diffuse exist(or very weak). Metal almost doesn't have diffuse, more strong specular at same time(energy conservation).

Every surface has special attribution to absorb some kind of light ray(wave) and reflection some kind of light ray(wave). There's the basic property of surface. As RGB is used to represent light ray. This property can also be a value between 0 to 1 to identify how much color reflected.

In mathematics, we always define these reflection model as Bidiretional Reflectance Distribution Function(BRDF).

<Final BRDF> = a * <Diffuse BRDF> + b * <Specular BRDF>

Lambert

Burley

OrenNayar

Gotanda

### 4) Microfacet Specular BRDF

In generally, microfacet specular BRDF can be defined as following formula:

n ---- normal

l ---- light direction

v ---- view direction

h ---- half direction of view and light direction

The denominator part is direct there. The numerator part is composed by three different term, all of them represent some effects of specular reflection.

Normal Distribution Function: D(h)

Blinn

[Blinn 1977, "Models of light reflection for computer synthesized pictures"]

Beckmann

[Beckmann 1963, "The scattering of electromagnetic waves from rough surfaces"]

GGX / Trowbridge-Reitz

[Walter et al. 2007, "Microfacet models for refraction through rough surfaces"]

Anisotropic GGX

[Burley 2012, "Physically-Based Shading at Disney"]

Fresnel Reflectance: F(l,h)

Schlick

[Schlick 1994, "An Inexpensive BRDF Model for Physically-Based Rendering"]

Fresnel

Geometry Function: G(l,v,h)

Neumann

[Neumann et al. 1999, "Compact metallic reflectance models"]

Kelemen

[Kelemen 2001, "A microfacet based coupled specular-matte brdf model with importance sampling"]

Schlick

[Schlick 1994, "An Inexpensive BRDF Model for Physically-Based Rendering"]

Smith

[Smith 1967, "Geometrical shadowing of a random rough surface"]

Appoximation of joint Smith

## 2. PBR in UE4

Whatever deferred rendering or forward rendering, UE4 using most efficient method without lost obviously graphic quality.

Diffuse Reflection

Lambert

Specular Reflection

D function  GGX

F function Schlick

G function Smith Joint Approx

Specular Color

Metal [ Lazarov 2013, "Getting More Physical in Call of Duty: Black Ops II" ]

Nonmetal simplified with specular color (0.04, 0.04, 0.04)

More detail in ShadingModels.usf and BRDF.usf.

## 3. Mobile PBR in UE4

On mobile platform, UE4 did some optimization and simplification.

Diffuse Reflection

Customized Lambert

Specular Reflection

Customized PhongApproox

Specular Color

Metal [ Lazarov 2013, "Getting More Physical in Call of Duty: Black Ops II" ]

Nonmetal simplified with specular color (0.04, 0.04, 0.04)

More detail in MobileBasePassPixelShaer.usf.

## 4. PBR Material for UE4

Above figure show a typical UE4 material. Let's check each item of them.

• Base Color

Base color simply defines the overall color of the Material. It takes in a Vector3 (RGB) value and each channel is automatically clamped between 0 and 1. If taken from the real world, this is the color when photographed using a polarizing filter (polarization removes the specular of nonmetals when aligned). UE4 document lists some typical base color.

3 floats between [0~1]

• Metallic

The metallic input literally controls how "metal-like" your surface will be. Nonmetals have Metallic values of 0, metals have Metallic values of 1. For pure surfaces, such as pure metal, pure stone, pure plastic, etc. this value will be 0 or 1, not anything in between. When creating hybrid surfaces like corroded, dusty, or rusty metals, you may find that you need some value between 0 and 1.

1 float between [0~1]

• Specular

The specular input should not be connected and left as its default value of 0.5 for most cases. It is value between 0 and 1 and is used to scale the current amount of specularity on non-metallic surfaces. It has no effect on metals. UE4 document lists some typical specular value.

1 float between [0~1], default 0.5

• Roughness

The roughness input literally controls how rough the Material is. A rough Material will scatter reflected light in more directions than a smooth Material. This can be seen in how blurry or sharp the reflection is or in how broad or tight the specular highlight is. Roughness of 0 (smooth) is a mirror reflection and roughness of 1 (rough) is completely matte or diffuse.

1 float between [0~1]

• Cavity

Commonly, if we modify Specular, we do so to add micro occlusion or small scale shadowing, say from cracks represented in the normal map. These are sometimes referred to as cavities. Small scale geometry, especially details only present in the high poly and baked into the normal map, will not be picked up by the renderer's real-time shadows. To capture this shadowing, we generate a cavity map, which is typically an AO map with very short trace distance. This is multiplied by the final BaseColor before output and multiplied with 0.5 (Specular default) as the Specular output. To be clear this is BaseColor = Cavity*OldBaseColor, Specular = Cavity*0.5.

1 float between [0~1]

*Normally, it can be stored into base color and specular directly.

• Emissive Color

The emissive color input literally represent emissive of object.It should be an Vector3(RGB). It will directly add more color for final result.

3 floats between [0~1]

• Normal

The Normal input literally controls surface normal. More detail refer to normal map. It need three values between 0 ~ 1 and remaped to -1 ~ 1 intenally. In tangent space, normal.z should between 0 to 1.

2 floats between [-1~1] and 1 float between [0, 1]

• Ambient Occlusion

The Ambient Occulsion input literally controls precomputed AO. Normally some local shadow. It can be represented by an intencity value between 0 to 1.

1 float between [0, 1]

Because most of scene objects are opacity. In the following, a material and texture layout was defined to suit to for UE4 PBR system.

Texture0

Texture1

• Base Color

Base color is very important and need very detail information. So, we keep all three value in texture0 RGB channel.

• Metallic

As mentioned above, metallic is a mask value to identify if the surface is metallic or nonmetallic. We can using texture0 alpha channel. For example, if the texture0 alpha channel is very low value below 0.1, it should be metal, in other vlaue, it should be nonmetal.

• Specular

This value is for nonmetal surface to artifactly scale surface. we can ignore it and use the default value 0.5 for all nonmetal surface. For metal surface, the value is not used at all. So, we skip it.

• Roughness

Roughness is very important and need very detail information too. A seperated channel is revered for it, texture1 blue channel.

• Cavity

As mentioned, cavity can be precombined to base color and specular color. So, we skip it.

• Emissive Color

Emissive color is a little bit complex. The best case, we should use a texture including RGB of emissive color. But it will cost too much buffer and we can do some simplification.

Method 0: Define const emissive color for whole object and using texture1 alpha channel as mask;

Method 1: Directly use base color as emissive color and using texture1 alpha channel as mask.

• Normal

Tangent Space Normal is composed by 1 vector. If we ensure all normal vector are normalized, we can only use two floats to represent a vector. For example, we keep x, y value only and z will calculated by x^2+y^2+z^2=1. Then, we only keep normal x, y in texture1 red and green channel. Here is some more detail.

• Ambient Occlusion

Similar with cavity, we skip it.

## 5. Database

[CUReT]Columbia-Utrecht Reflectance and Texture Database http://www1.cs.columbia.edu/CAVE/software/curet/

[UE4 Doc]Some reference value for base color and specular https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/PhysicallyBased/

## Reference

2. Real Shading in Unreal Engine 4 https://de45xmedrsdbp.cloudfront.net/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf

3. [UE4 Doc] Physically Based Materials https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/PhysicallyBased/

4. Physically Based Rendering Encyclopedia[Brian Yu] https://docs.google.com/document/d/1Fb9_KgCo0noxROKN4iT8ntTbx913e-t4Wc2nMRWPzNk/

5. Physically-Based Shading at Disney[Brent Burley] https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf

6. Moving Frostbite to Physically Based Rendering http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf

7. UnrealEngine4 PBR Shading Model 概述 http://blog.csdn.net/pizi0475/article/details/48296265