# Light and shadow

This topic is 5209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 ?

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633665
• Total Posts
3013247
×