This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Bounds-Related Classes
Containers
Controls-Related Classes
Core Library
Engine-Related Classes
GUI-Related Classes
Node-Related Classes
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Utility Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Shading

Shading is a way to make a model look more realistic by changing colors, usually gradually, of its faces based on their angles to the light source. Shading is actually closely connected with lighting and is separated from it only because of different technologies that are used.

Each shading model uses some reflection model, on which it depends. So, the descriptions of shading models will be preceded by the descriptions of the corresponding reflection models.

Phong Reflection Model

The first model we will look at is the Phong reflection model. It is an empiric model, rather than a physical one, and it implies such simplifications:

  • It is a local reflection model that does not take into account second-order reflections.
  • It divides reflection from a surface into three components: ambient reflection (compensates for lack of second-order reflections), diffuse reflection, and specular reflection.
  • There are four coefficients defined for each material: ambient reflection constant ( ka ), diffuse reflection constant ( kd ), specular reflection constant ( ks ), and shininess constant for this material, which decides how "evenly" light is reflected from a shiny spot (α).

Then for each light source, components is and id are defined, which are intensities of the specular and diffuse components of the light source. There is also a single component ia ,that controls the ambient lighting (it is equal for all light sources). Also, for each surface point these vectors are considered:

  • L is the direction vector from the point to a light source.
  • N is the normal at this point.
  • R is the direction of a perfectly reflected ray of light from the point.
  • V is the direction towards the viewer.

Then the shade of each surface point, Ip is calculates using this equation, which is actually the Phong reflection model:
Ip = ka ia lights( kd id (L·N) + ks is (R·V) α ).

Or, simpler, the intensity of the point is a sum of the three main components: ambient, diffuse, and specular.

But this reflection model merely says how a point on a surface should look, however, when working with polygons, we have color values only at their vertices. How exactly pixels in-between will be lit depends on a particular shading model.

Phong Shading

A screenshot of a sphere with Phong shading

This approach to shading was proposed by Phong along with his reflection model. The technique explains how to actually shade the points on a surface by interpolating the surface's normal across a polygon.

Given the normals at vertices of a polygon, in Phong shading we linearly interpolate a normal vector across the surface of the polygon, from these normals. This is different from Gouraud shading, where the color is interpolated across polygons. The interpolation is done for each point at the surface, and at each point it is used to obtain the final color using the Phong reflection model.

Notice
It is assumed that normals at vertex have unit length, and the length does not change during interpolation.

This is a more expensive way to calculate point intensities, but it solves the problem of Gouraud shading when a small highlight occurs at the center of a polygon.

Anisotropic Reflection Model And Shading

A screenshot of a sphere Anisotropic shading

The anisotropic reflection model comes into play when you need to model surfaces that have small parallel grooves or fibers, such as brushed metal, old LP records, silk, and even hair (as a whole). It allows stretching reflections and highlights in a direction that runs perpendicular to the grooves on a surface. The peculiarity of this model is the way the specular term of reflection is calculated. Depending on a selected distribution of microfacets that constitute the surface, different parameters may be used, for example, the direction of the grooves or fibers.

This shading is also "heavier" than the Phong shading because of more elaborate computations, and its actual formula depends on the chosen distribution (see, for example, Wikipedia).

Last update: 2017-07-03
Build: ()