Lighting esp in a graphics library such as OpenGL can be implemented with techniques such as ray tracing, ray casting which solve visibility problem and shading as in phong shading which is for applying color.
Let's begin with basics:
Objects are represented in either boundary representations or using solid modeling. When it comes to coloring a 3D scene the objects in the scene interact with the light from light sources. There are multiple reflections, refractions etc..
If multiple reflections and refractions are neglected and light in the scene is modeled by splitting into ambient, diffuse and specular light then phong shading model becomes useful. In this matter is modeled as having a Bi-Directional Reflectance Distribution Function(BRDF). How much light falling on a surface is reflected is specified by it. Gouraud shading: you evaluate the light color using the reflectance model at the known points, and interpolate on the color; Phong shading: you interpolate the normals and apply the reflectance model at every interpolated point.
There are several parameters of lighting that go into the phong shading calculations. Firstly the number and type of light sources. Light source types include point source, directional light and spot light.
Phong Shading parameters(Taken from wiki):
For each light source in the scene, components and are defined as the intensities (often as RGB values) of the specular and diffuse components of the light sources, respectively. A single term controls the ambient lighting; it is sometimes computed as a sum of contributions from all light sources.
For each material in the scene, the following parameters are defined:
- , which is a specular reflection constant, the ratio of reflection of the specular term of incoming light,
- , which is a diffuse reflection constant, the ratio of reflection of the diffuse term of incoming light (Lambertian reflectance),
- , which is an ambient reflection constant, the ratio of reflection of the ambient term present in all points in the scene rendered, and
- , which is a shininess constant for this material, which is larger for surfaces that are smoother and more mirror-like. When this constant is large the specular highlight is small.
Furthermore, we have
- , which is the set of all light sources,
- , which is the direction vector from the point on the surface toward each light source ( specifies the light source),
- , which is the normal at this point on the surface,
- , which is the direction that a perfectly reflected ray of light would take from this point on the surface, and
- , which is the direction pointing towards the viewer (such as a virtual camera).
Then the Phong reflection model provides an equation for computing the illumination of each surface point :
where the direction vector is calculated as the reflection of on the surface characterized by the surface normal using
and the hats indicate that the vectors are normalized.
No comments:
Post a Comment