Essential Reading Notes for Getting Started with Unity Shader Seven

Unity shader lighting basics

==You If it looks right, it's right - First Law of Computer Graphics==


Here I mainly take notes on the basics of lighting. The lighting foundation is really mind-blowing here, and I haven't understood it for a long time. Below are some of the main points.

To render an environment, you need to consider:
- Light originates from a light source
- When light hits other objects, it is reflected and scattered.
- The last light that enters the camera is the last rendered image.

light source

A light source strikes an object, and the incoming energy can be quantified by irradiance. Usually the light source illuminates the object in two forms, the first is vertical illumination, and the second is illuminated in a certain angle direction.

The vertical direction is actually very easy to calculate. If it is not vertical, you can use the dot product of the light and the surface to calculate:

a b = | a | | b | c O s θ

What is actually calculated here is the component of the light in the vertical direction.

Absorption and scattering of light

After the light hits the object, there are two results when it intersects with the object:
1. Scattering. Scattering only changes the line of defense of the light, not the color and density.
2. Absorb. Absorption only changes color and density, not orientation.

Scattering in turn includes refraction into the interior of the object and reflection directly on the surface. There are different representations for these two different types of scattering: Specular reflections represent rays that reflect directly on the surface, while diffuse reflections represent rays that are refracted internally.

The reflected light can be measured by the degree of refraction.

Coloring

Using mathematical methods to describe the irradiation process of light on an object is called a lighting model.
The BRDF (Bidirectional Reflectance Distributioni Function) method uses a mathematical formula to describe the distribution of light rays hitting an object.
Before this method, the standard lighting model was usually used.

Standard Lighting Model

There are many standard lighting models that are often used:
- Phong model
- Blinn model

When these models describe lighting, the lighting part is divided into 4 parts, each part is calculated with different formulas:
- Self-illumination
- Specular reflection
- Diffuse reflection
- Ambient light

Self-luminous

Self-illumination actually means that an object can emit light by itself. In the programming, you can add the self-illuminating color after the fragment shader at the end.

Specular reflection

Specular reflection is an empirical model that simulates the specular reflection of an object. The phong model is actually different from the blinn model.

diffuse reflection

Diffuse reflection follows Lambert's law, but since diffuse reflection is random, all basically diffuse reflections are the same at all angles.

ambient light

Ambient light is actually used to describe the light that hits the object directly and to the light that is reflected by other objects.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326704016&siteId=291194637