Physically based rendering Documentation

From Nexus Mods Wiki
Revision as of 14:12, 17 October 2019 by WarhorseStudios (talk | contribs) (Created page with "<div class="xcontent"><div class="row"><div class="col-xs-12" id="xwikicontent"> == <span>Material Setup for Physically Based Shading</span> == CRYENGINE 3.6 and beyond uses...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Material Setup for Physically Based Shading

CRYENGINE 3.6 and beyond uses a shading model that is based on basic physical rules. Instead of using a lot of fudge and tweak factors which don't have a reasonable meaning in the real world, materials use some physical properties to describe how the incoming light should interact with them. A huge advantage of using a physically based model with certain rules is that material assets will be much more consistent and look more convincing under different lighting conditions.

To achieve naturally looking materials, it is required to follow a few rules. Using these rules can make the asset creation process slightly different from what artists are used to in other engines. However, once grasped, the rules are not complicated and will in many cases even simplify the asset creation, as fewer parameter tweaks are required to achieve a more natural material appearance under all lighting conditions.

Background

Although it is not absolutely necessary to know how light interacts with matter in the real world, a basic understanding can be very helpful when setting up materials.

Diffuse and Specular Reflectance

When light hits a surface, it splits into two directions: some part of it is reflected immediately while the rest gets refracted and enters the surface. The refracted light can be absorbed or can be scattered around underneath the surface and exit again at a slightly different location.

Light that gets reflected directly from the surface is handled as specular reflectance in a shading model. The light that is refracted and undergoes subsurface scattering is handled as diffuse reflectance.

The amount of light that is reflected versus refracted depends on the surface substance and the angle at which the light hits the surface. At a grazing angle, the amount of light that gets reflected directly (specular) gets higher, until it reaches 100% at an extreme angle. This behavior is described by the Fresnel effect.

Material Types

There are only two categories of substances which are relevant for rendering: metals (conductors like iron, gold, copper, etc.) and non-metals (dielectric materials like plastic, stone, wood, skin, glass, etc.). Both have special characteristics regarding diffuse and specular reflectance.

Metal absorbs all light that enters underneath the surface, hence metal has no diffuse reflection. This means that metal should have a black diffuse color. All visible light is reflected directly from the surface (specular reflectance). The different types of metal have characteristic specular colors.

In contrast to metal, non-metal has diffuse reflection, however the specular reflection is a lot weaker and less varied than for metal. Specular reflectance for non-metal is monochromatic (no color, just gray). Most non-metals reflect only a small fraction of the light as specular, for most materials between 2% and 5%.

Getting Started

sRGB Color Space

Be aware that you are working in sRGB color space on your monitor when painting a texture. In sRGB space, a 50% mid-gray is not 0.5 or 127 but rather 0.5 raised by the inverse of gamma 2.2 which equals 187 in Photoshop. In a nutshell, the reason that sRGB is used is to avoid banding artifacts. In sRGB space you get more precision for darker colors to which the human eye is more sensitive. Before working on colors, please make sure that your screen is calibrated properly.

Photoshop Setup

Verify that your Photoshop color management is set up properly. You can access the Color Settings from the menu via Edit->Color Settings...

RGB should be set to sRGB and Gray to Gray Gamma 2.2

By default, Gray is often set to Dot Gain 20% which will result in a color transformation in the alpha channel. A value of 127 will come into the engine as 104 in that case which can cause inconsistencies, so please make sure Gamma 2.2 is used instead.

Shading Model Parameters

The biggest difference of a physically based model compared to other older game models is the use of specular. While a specular mask was often used to vary the intensity of specular highlights over a surface, the specular color is a physical value now which is constant for a single type of material. To get variation in the highlights, a gloss map should be used instead. Gloss is more powerful than the traditional specular mask, as gloss influences not only the brightness of a highlight but also it's size and the sharpness of environmental reflections.

Diffuse Color

The diffuse color defines how bright a surface is when lit directly by a white light source with an intensity of 100%. More physically speaking, it defines which percentage for each component of the RGB spectrum does not get absorbed when light scatters underneath the surface. A diffuse map is always required. In most cases the diffuse color in the material editor should be set to white (255/255/255).

Usually the diffuse map should not contain any lighting, shading or shadowing information, as all this gets added dynamically by the engine. In case some pre-baked ambient occlusion is required, it has to be stored in a dedicated AO map (currently the diffuse channel of a Unified Detail Map is interpreted as AO).

For pure metal materials, the diffuse color should be black as explained before. Rusty metal however needs some diffuse color.

Surface Normals

Most materials should have a normal map. Make sure that the correct texture preset is used, otherwise the normal map might be gamma-corrected and give wrong shading results.

Specular Color

The specular color defines how much light gets reflected immediately from the surface when the light source is directly above the surface. This is the minimum specular intensity, under grazing angles it will increase due to the Fresnel effect. As the specular color is specific for a certain type of material, it can also be considered as a mask for the type of material/substance. The specular color is a physical value which should be picked directly from a reference table. As such, it does not leave much artistic freedom.

Most non-metals reflect 2% to 5% of the light as specular and the highlight is monochrome/gray. As the variation is so little, it is often enough to use a constant specular color instead of a specular texture map. Suitable are values between RGB 45/45/45 and 55/55/55. However, if metals and non-metals are mixed in a single texture, it is required to use a specular map, as metal has a much brighter specular color than non-metal. If a specular map is used, the specular color in the material editor should be set to white which is 255/255/255, as it gets multiplied with the values from the specular map and would otherwise lower the physical values from the map.

Gloss/Smoothness

Gloss defines the roughness of a surface. A a low gloss value means that the surface is rough while a high value means the surface is very smooth and shiny. The roughness influences the size and the intensity of specular highlights. The smoother/glossier a surface is, the smaller the specular highlight will be. A more narrow/smaller highlight will at the same time be brighter in order to obey to the rules of energy conservation.

Most materials should have a gloss map, as it can give a lot of good variation to the shading. Gloss is closely related to normal maps, as high frequency details in a normal can create some feeling of roughness as well. However, gloss is more the micro-scale roughness of the material.

Physically Based Rendering Documentation Img1.jpg

Note how the specular highlight becomes smaller and brighter with an increasing gloss value, making the material look smoother (Image Source: Real-Time Rendering)

The gloss map is stored in the alpha channel of the normal map. If the preset NormalMapWithGlossInAlpha_highQ is selected, the RC will automatically adjust the gloss map stored in the alpha channel based on the normal variance and lower the gloss at parts where normals are very bumpy. This can greatly help to reduce temporal aliasing (shimmering, sparkling highlights).

Guidelines for Creating Different Materials

The material substance is defined to a huge degree by the specular color. Use a reference table to pick the appropriate color for the desired material type.

Non-Metals

  • Non-metal has monochrome/gray specular color. Never use colored specular for anything except certain metals.
  • The sRGB color range for most non-metal materials is usually between 45 and 55. It should never be higher than 80/80/80.
  • A good clean diffuse map is required.

Metals

  • The specular color for metal should always be above sRGB 180.
  • Metal can have colored specular highlights (for gold and copper for example).
  • Metal has a black or very dark diffuse color.

Checklist for Asset Setup

  1. Diffuse color multiplier is set to 255/255/255
  2. Specular colors are physically plausible values (see reference section for the correct values)
    1. No specular map is used for purely non-metal materials
    2. If a specular map is used, Material Specular Color should be 255/255/255
    3. If no specular map is used, Material Specular Color is the physically based value
  3. A gloss map is used (in combination with noemal map -> ddna) and creates interesting and plausible variation on the specular highlights. If there is gloss map used, material smoothess value should be set to 255

Tips

  • The gloss map is one of the most important textures. With the gloss map you can give some history to an asset. For example, make parts of an object that were touched a lot by people less rough.
  • For non-metal objects, don't waste time with a specular map but focus rather on the gloss map. This will also help to save memory, as a constant specular material color is enough in most cases.
  • Put variation into the gloss map. Not just random noise but think really where the object would be less or more rough.
  • Always test the specular reaction of objects/materials by rotating them against a light source and viewing them from different angles. Specular is what gives objects the sense of volume and breaks the flat look.
  • Make sure that the lighting is setup properly when testing assets (you can use a special asset test level with calibrated lighting).
  • If an object has the correct physical specular color but you see hardly any specular highlights on top of the diffuse, the gloss is likely too low. Try to increase the brightness of the gloss map.
  • To see just the specular without any diffuse, put the Diffuse Color to black in the material editor.
  • Use the histogram in the material editor to identify issues in the material setup. You can easily judge the overall brightness of textures using the histogram.

Reference Values

Specular Color

Material sRGB Color Linear (Blend Layer)
Water 38 38 38 0.02
Skin 51 51 51 0.03
Hair 65 65 65 0.05
Plastic / Glass (Low) 53 53 53 0.03
Plastic High 61 61 61 0.05
Glass (High) / Ruby 79 79 79 0.08
Diamond 115 115 115 0.17
Iron 196 199 199 0.57
Copper 250 209 194 N/A
Gold 255 219 145 N/A
Aluminum 245 245 247 0.91
Silver 250 247 242 N/A
If a non-metal material is not in the list, use a value between 45 and 65.

Diffuse chart

 

Physically Based Rendering Documentation Img2.jpg

 

Specular color and Glossiness values

Material Specular color Glossiness
wood rough 48,48,48 18-42, median 28
wood medium 55,55,55 31-57, median 47
wood polished 60,60,60 40-93, median 80
stone rough 50,50,50 27-58, median 42
grass 50,50,50 30-60, median 38
thatch, straw 56,56,56 55-85, median 77
plaster 48,48,48

15-58, median 30

soil dry 48,48,48 13-44, median 20
fabric 45,45,45 14-31, median 24
wicker new 60,60,60 60-130, median 95
dry leaves ground 45,45,45 27-50, median 32

Gloss Chart

Physically Based Rendering Documentation Img3.png

Cheat Sheet for Picking Values

Physically Based Rendering Documentation Img4.png