Light and shadow

Started by
2 comments, last by kslam 19 years, 7 months ago
How to calculate the diffuse, ambient, emission, specular light and infinite, point, spot light? Are they in scalar form or in RGB(x,x,x) form ? any formula and algorithm example ?
Advertisement
Diffuse, ambient, emission, and specular determine how a single polygon will be affected by light rays.

Infinte, point and spot properties determine what kind of rays a light source will emit.

The lighting step produces colors, so they are best stored in RGB form, rather than as a scalar (unless all your lights are monochrome).

An infinite light will produce parallel light rays, so the "light" vector will always be the same. A point light produces radial light rays, so the "light" vector will be a vector from the point light to the considered point. Also, the type of light source will determine various attenuation factors for the rays.

Ambient light is the same for all objects. Diffuse lighting is in fact the sum of diffuse lightings for all light sources that affect the polygon. For each point, the diffuse lighting intensity for a light is:

light intensity * (normal vector DOT light vector)

You can google for much more details about the various light types, lighting types, and formulas. Also, API references and related documents (for DirectX and OpenGL) contain many useful remarks about these formulas, and may be found lying around on the web.
Here's the simplified lighting equation :-

Color = Ambient + Diffuse + Specular + Emmisive

where,

Ambient = Material_Ambient * Light_Ambient
Diffuse = Material_Diffuse * Light_Diffuse * Dot(Normal, LightDirection)
Specular = Material_Specular * Pow(Dot(Normal, HalfAngle), SpecularPower) * Light_Specular
Emissive = Material_Emissive

HalfAngle = normalize(ViewDirection + LightDirection)

All values except the dot products are in vector form.

For a spot light, the diffuse and specular terms must be set to zero if the dot product between the light-to-vertex vector and the actual light direction is greater than the cone angle of the spot light.
May you show me some simplified code of the lighting equation below. Because I got some problem to convert the equation to code form.

Ambient = Material_Ambient * Light_Ambient
Diffuse = Material_Diffuse * Light_Diffuse * Dot(Normal, LightDirection)
Specular = Material_Specular * Pow(Dot(Normal, HalfAngle), SpecularPower) * Light_Specular
Emissive = Material_Emissive

Thank you.

This topic is closed to new replies.

Advertisement