OPENGL 4 Illumination Models

Source: Internet
Author: User
1.Lambert Model (diffuse reflection)

Ambient light:

Iambdiff = Kd*ia

Wherein IA indicates ambient light intensity, Kd (0<k<1) is the reflective coefficient of the material to ambient light, and Iambdiff is the light intensity that the diffuse reflector interacts with the ambient light.

Directional Light:

Ildiff = Kd * Il * Cos (θ)

Where IL is the intensity of the point light source, θ is the angle of the incident light direction and the vertex normal, called the angle of incidence (0<=a<=90°), Ildiff is the diffuse reflector and direction light interactive reflection of the light intensity, if n is the vertex unit normal vector, L represents the unit vector from the vertex to the light source (note vertex points to the light), The cos (θ) is equivalent to dot (n,l), so there are:

Ildiff = Kd * Il * DOT (n,l)

Finally, the Lambert illumination model can be written as a combination of ambient light and directional light source:

Idiff = Iambdiff + Ildiff = kd * Ia + Kd * Il * DOT (n,l)


2.Phong Model (specular reflection)

The Phong model considers that specular light intensity is related to the angle of reflection light and line of sight:

Ispec = Ks * Il * (dot (v,r)) ^ns

Where KS is a specular reflection coefficient, NS is a high-light index, v represents the viewing direction from vertex to viewpoint, and R represents the direction of reflected light. Because the direction of the reflected light r can be obtained by the incident light Direction L (from the vertex point to the light source) and the object's normal vector,
r + L = 2 * DOT (n, L) * n i.e. R = 2 * DOT (n,l) * n-l

So the final formula is:

Ispec = Ks * Il * (dot (V, (2 * DOT (n,l) * n–l)) ^ns



3.blinn-phong Illumination Model (fixed specular light)

Blinn-phong is a model modified based on the Phong model with the following formula:

Ispec = Ks * Il * (dot (n,h)) ^ns

where n is the unit normal vector of the entry, H is the intermediate vector of the light incident direction L and the direction V of the viewpoint, often referred to as the half-width vector (half-width vectors are widely used in various illumination models, not only because of the information value contained in the half-width vector, but also because the half-width vector is very simple:  L + v| )。



4.Rendering equation (global illumination model)

Rendering equation was proposed by Kajia in 1986,

Lo (x, wo) = Le (x, wo) +∫fr (x, WI, wo) Li (x, WI) dot (N, WI) dWi

where x represents entry, Lo (x, wo) is the light intensity reflected from the surface of the object x points along the direction of Wo, Le (x, wo) represents the intensity of the light emitted from the object surface x in the direction Wo, which is only valid for the self-luminous body, fr (x, WI, wo), the incident light direction is Wi And then from the wo direction emitted from the BRDF value, Li (X, WI) for the incident direction of Wi irradiation to the incident light on the X-ray intensity, n represents the normal vector at point X, and then to the incident direction of the integral (because the direction of the incident light is in all directions, the meaning of the integral is calculated after each direction), The result of the calculation is the radiation rate of the global illumination.

For a single point light to illuminate an object that does not emit self-illumination, the formula can be simplified into:

Lo (x, wo) = fr (x, WI, wo) Li (x, WI) dot (N, WI)

This formula is useful and usually decomposes the formula into the sum of the diffuse and specular expressions. For diffuse surfaces, BRDF can be ignored because it always returns a constant value, so it can be written as follows:

Lo (x, Wo) = Idiff + FRS (x, WI, wo) Li (x, WI) dot (N, WI)

Wherein the IDIFF represents diffuse reflection component, using the calculation method of the formula, FRS (X, Wi, Wo) represents the BRDF function of specular reflection, the front of the Phong high-light model, in fact, rendering equation in a single light source for the ideal specular reflection of the specific deduction, For Phong Highlights:

FRS (X, WI, Wo) = Ks (dot (n, H) ^ns/dot (n, WI)


//------------------------------------------------------------------------------------------------------------- ------------

comparison of several illumination models

Lambert model can better show the rough surface of the light phenomenon, such as lime wall, paper and so on, but in the rendering of metal materials made of objects, it will appear stiff, do not show gloss, the main reason is that it does not take into account the specular reflection effect, so the Phong model for its very good supplement. Because the BLINN-PHNG light model mixes the diffuse portion of the Lambert with the standard highlight, the rendering is sometimes softer than the Phong highlight, and some people think that the Phong lighting model is more realistic than blinn-phong, in fact, Blinn-phong rendering effect is more gentle, but because the Blinn-phong light model eliminates the calculation of the reflected light direction vector two multiplication, faster, so many CG software is the default method of light-looking rendering, in addition to it is also inherited in most graphics chip, To generate real-time, fast rendering. In OpenGL and Direct3D rendering pipelines, Blinn-phong is the default rendering model. Rendering equation is a model based on physical optics, which quantitatively quantifies the radiation rate in the direction of observation, and the Phong model is only the derivation of its specific BRDF.

The following is a Blinn-phong CG fragment for reference implementations:

struct Vertexscreen
{
FLOAT4 oposition:position;
FLOAT4 objectpos:texcoord0;
FLOAT4 Objectnormal:texcoord1;
};

void Main_f (Vertexscreen posin,
Out Float4 Color:color,
Uniform float4x4 Worldmatrix,
Uniform float4x4 Worldmatrix_it,
Uniform FLOAT3 globalambient,
Uniform FLOAT3 eyeposition,
Uniform FLOAT3 lightposition,
Uniform FLOAT3 Lightcolor,
Uniform FLOAT3 Kd,
Uniform FLOAT3 Ks,
Uniform float shininess)
{
FLOAT3 Worldpos = Mul (Worldmatrix, Posin.objectpos). xyz;
FLOAT3 N = Mul (Worldmatrix_it, posin.objectnormal). xyz;
n = normalize (n);

Calculate incident light direction \ line of sight direction \ half-width vector
FLOAT3 L = normalize (Lightposition-worldpos);
FLOAT3 V = normalize (Eyeposition-worldpos);
FLOAT3 H = normalize (L + V);

   //Calculate diffuse component
    float3 diffusecolor = Kd * Globalambient+kd*lightcolor*max (dot ( N, L), 0);
 
   /Calculate specular component
    float3 specularcolor = Ks * LIGHTCOLOR*POW (max (dot ( N, H), 0), shininess);
    color.xyz = Diffusecolor + specularcolor;
    COLOR.W = 1;
}

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.