[Unity Shader] Illumination model assumptions about objects

Source: Internet
Author: User
Tags mul

What is a light model

The illumination model simulates the transfer of light between objects to ensure the brightness and color of each point of the visible surface of the object.

When light shines on an object's surface, light may be absorbed, reflected, or refracted. The reflected and refracted light makes the object visible. If the incident light is fully absorbed, the object will not be visible, and the object is called a blackbody.

The color of an object's surface is determined by the distribution of various wavelengths in the light energy emitted from the surface of the object to the direction of vision.

If the object is opaque, the color of the surface of the object is determined only by its reflected light, and the reflected light is usually considered as a combination of three components of the ambient reflection light , diffuse light and specular reflection light.

Ambient Reflection (Ambient light)

Environmental reflection is caused by multiple reflections of light due to neighboring objects. Light from all directions, such as from walls, floors, and smallpox, is a source of distribution.

The effect of this light is usually reduced to a uniform light level IA in all directions.

When an object is illuminated only by ambient light, its surface is exactly the same degree of shading as the dots. Its luminance is expressed as:

Ie = Ia * Ka

    • Ie: Ambient light reflection light brightness of the object;
    • Ia: Brightness of the environment;
    • Ka: Ambient light reflection coefficient (0≤ka≤1) on the surface of the object
Ambient Light Direct acquisition//unity_lightmodel_ambient is UNITY's own macro definition constant FLOAT3 ambientlighting = FLOAT3 (unity_lightmodel_ambient) * FLOAT3 (_color);//_color is a property attribute added in Shader properties {_color ("Diffuse Material Color", Color) = (1,1,1,1)}

  

Diffuse reflection (diffuse light)

Diffuse light is reflected in the light by a particular light source on the surface of the object, which is reflected evenly to the space parties. The reflection intensity of this light is irrelevant to the position of the observer, and its light intensity is proportional to the cosine of the angle between the incident light direction and the surface normal of the reflection point.

Suppose that the normal of the surface of the object is n at p Point, and the vector from P point to the light source is L, and the angle is θ. The diffuse light brightness at point P is:

Id = Ip * Kd * COSθ

    • Id: Surface diffuse reflection light brightness;
    • IP: Illumination of the incident light;
    • Kd: Diffuse reflectance coefficient (decision and surface material and wavelength of incident light) (0≤kd≤1);
    • Θ: the angle between the incident light and the normal, 0≤Θ≤PI/2;

Computed Diffuse light FLOAT3 diffusereflection = FLOAT3 (_lightcolor0) * FLOAT3 (_color) * MAX (0.0, Dot (normaldirection, lightdirection));

Specular reflection (specular light)

Specular reflection is light reflected in one direction.

For the ideal mirror, the light incident to the surface adheres strictly to the law of reflection of Light, and only in the reflective direction can the observer see the light reflected from the mirror, such as a.

For the general smooth plane, due to the surface has a certain degree of roughness, its surface is actually a lot of faces to different small surface composition, its specular reflection light scattered around the direction of reflection, such as B.

Specular light brightness can be expressed as:

is = is * Ks * cosnφ

    • is: the brightness of specular light received by the viewer;
    • Ip: The brightness of the incident light;
    • Ks: Specular reflection coefficient (related to material material and incident light wave);
    • φ: The angle between the specular reflection direction and the line of sight;
    • N: The convergence coefficient of specular reflection light (related to the smoothness of the surface of the object), generally 1≤n≤2000;

For a smoother surface, the specular reflection light converges more, the n value is larger, while the coarser specular reflection light is divergent and the n value is smaller.

_object2world and _world2object all provide unity with the built-in uniform parameters float4x4 Modelmatrix = _object2world;//World coordinate system to the object coordinate system of the transformation matrix float4x4 Modelmatrixinverse = _world2object;//normal vector n changes to object coordinate system float3 Normaldirection = Normalize (FLOAT3 (Mul (FLOAT4, 0.0) (Modelmatrixinverse))), or//parallel light source in the amount of L directly from the Uniform_worldspacelightpos0 float3 lightdirection =normalize (FLOAT3 (_ WORLDSPACELIGHTPOS0));//observation vector v is subtracted from camera coordinates and vertex coordinate vectors float3 viewdirection = normalize (FLOAT3 (FLOAT4, 1.0)-Mul (Modelmatrix, Input.vertex));//calculation of specular light float3 SPECULARREFLECTION=FLOAT3 (_lightcolor0) *FLOAT3 (_speccolor ) *pow (Max (0.0,dot (Reflect (-lightdirection, normaldirection), viewdirection)), _shininess);

  

[Unity Shader] Illumination model assumptions about objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.