CG Unit 4
CG Unit 4
Unit 4
Light, Colour, Shading and Hidden Surfaces
(Duration: 7 Hours)
Contents
●
Colour models: Properties of Light, CIE chromaticity Diagram,
RGB, HSV, CMY.
●
Illumination Models: Ambient Light, Diffuse reflection, Specular
Reflection, and the Phong model, Combined diffuse and Specular
reflections with multiple light sources, warn model
●
Shading Algorithms: Halftone, Gauraud and Phong Shading.
●
Hidden Surfaces: Introduction, Back face detection and removal,
Algorithms: Depth buffer (z), Depth sorts (Painter), Area subdivision
(Warnock)
Color models
●
The purpose of color model (color space or color system) is to facilitate
specification of colors in some standard way.
●
A color model provides a coordinate system and a subspace in it where each
color is represented by a single point.
●
There are 3 hardware oriented color models:
1) RGB model: Used for color CRT monitor
2) YIQ model: Used for broadcast TV color system
3) CMY model: Used for color printing devices
●
There are another class of color models which are depend on hue, saturation
and brightness. They are: HSV, HLS, HVC models
Properties of light
●
A light produced by a sun or any light source emits all frequencies within the
visible range.
●
When this light is incident upon an object, some frequencies are absorbed
and some are reflected by the object.
●
The combination of reflected frequencies decides the color of the object.
●
If lower frequencies (or higher wavelengths) are predominant in the reflected
frequencies, the object color is red. (Since red color has lowest frequency or
highest wavelength than other colors)
●
Thus dominant frequency decides the color of object.
●
The dominant frequency is also called as hue or simply the color.
●
There are two more properties which describe various characteristics of
light. These are: brightness and saturation (purity).
●
The brightness refers to the intensity of the perceived light.
●
The saturation describes the purity of the color. There is no white, black, or
gray present in a color that has high purity.
●
When purity and dominant frequency are used collectively to describe the
color characteristics, are referred as chromaticity.
●
We can combine two colors with suitable intensities to produce a range of
other color.
●
The two colors that are combined to produce white color are called as
complementary colors of each other.
●
Red-Cyan, Green-Magenta, Blue-Yellow are the complementary color pairs.
●
Typically, the color model use combination of three colors to produce wide
range of colors. This range of colors is known as color gamut for that
model. The basic colors used to produce color gamut in a particular model
are called as primary colors for that model.
●
Primary colors for RGB models are: red, green and blue
●
Primary colors for CMY models are: cyan, magenta and yellow
CIE Chromaticity Diagram
●
In 1931, the CIE introduced the
Chromaticity diagram that represents
the mapping of human color
perception in terms of two CIE
parameters x and y.
●
The Commission Internationale de
l'Éclairage (CIE).
●
The points on the boundary are the
pure colors in the electromagnetic
spectrum, labeled according to
wavelength in nanometers from the
red end (700nm) to the violet end
(400nm) of the spectrum.
●
The Line joining the red and violet
spectral is called purple line, which is
not the part of the spectrum.
●
The CIE chromaticity diagram is useful in many ways:
1. It identifies complementary colors
2. It allows to define color gamuts or color ranges , that show the effect of
adding colors together
3. It allows us to measure the dominant wavelength of any color in
chromaticity diagram.
1) To identify complementary colors
2) To define color gamuts or color ranges
3) To identify the dominant wavelength of any color
Color Models
●
The purpose of color model (color space or color system) is to facilitate
specification of colors in some standard way.
●
A color model provides a coordinate system and a subspace in it where each
color is represented by a single point.
●
There are 3 hardware oriented color models:
1) RGB: Used for color CRT monitor
2) YIQ: Used for broadcast TV color system
3) CMY: Used for color printing devices
●
There are another class of color models which are depend on hue, saturation
and brightness. They are: HSV, HLS, HVC models
RGB Model
●
The red, green and blue (RGB) color model used for color CRT monitor.
●
In this model, primary colors - red, green and blue are added together to get
the resultant color. So this is additive model.
●
We can represent this color model with the unit cube defined on R, G and B
axes.
●
The vertices of the cube on the axes represent the primary colors.
●
The remaining vertices represent the complementary color for each of the
primary colors.
●
Main diagonal of cube have equal amount of each primary so represents grey
levels. The end at the origin of the diagonal represents black (0,0,0) and
other end represents white (1,1,1).
●
Thus each color point within the bounds of cube is represented by triple
(R,G,B) where R,G and B are assigned in the range from 0 to 1.
●
Color gamut for RGB model Vs
CMYK model in CIE Chromaticity
diagram is given as:
CMY Model
●
In CMY model cyan, magenta and yellow are used as a primary colors.
●
This model is used for describing color output to hard-copy devices (e.g.
printers, plotters etc.)
●
The subset of cartesian co-ordinate system for CMY model is similar to that
of RBG model. Difference is axes are made up of cyan, magenta and yellow
colors. White instead of black is at origin.
●
Colors are specified by what is removed or subtracted from white rather than
what is added to blackness.
●
Cyan can be formed by adding green and blue light. Therefore, when white
light is reflected from cyan colored ink, the reflected light does not have red
component. That is, red color is absorbed or subtracted by the ink.
●
The CMY color space is subtractive. Therefore, white is at (0.0, 0.0, 0.0)
and black is at (1.0, 1.0, 1.0). If you start with white and subtract no colors,
you get white. If you start with white and subtract all colors equally, you get
black.
CMYK Model:
●
The CMYK color space is a variation on the CMY model. It adds black
(Cyan, Magenta, Yellow, and blacK).
●
The CMYK color space closes the gap between theory and practice. In
theory (i.e. in CMY model), if you mix C, M and Y equally then you will get
black color. However, experience with various types of inks and papers has
shown that when equal components of cyan, magenta, and yellow inks are
mixed, the result is usually a dark brown, not black. Adding black ink to the
mix solves this problem.
●
The CMY and CMYK colors models are used in printing devices.
HSV Model
●
HSV is named as such for three values: hue, saturation, and value.
●
This color space describes colors (hue) in terms of their shade (saturation or
amount of gray) and their brightness value.
●
The HSV color wheel is depicted as a cone or cylinder, but always with these
three components:
Hue: Hue is the color portion of the color model, and is expressed as a
number from 0 to 360 degrees.
Saturation: Saturation is the amount of gray in the color. Saturation is
viewed on a range from just 0-1 (or 0-100 percent), where 0 is gray and 1 is
a primary color.
Value (or Brightness): Value works describes the brightness or intensity of
the color, from 0-100 percent, where 0 is completely black and 100 is the
brightest and reveals the most color.
●
The HSV color space is widely used to generate high quality computer
graphics. In simple terms, it is used to select various different colors needed
for a particular picture. An HSV color wheel is used to select the desired
color. A user can select the particular color needed for the picture from the
color wheel.
●
The HSV model describes colors similarly to how the human eye tends to
perceive color.
Illumination model
• An illumination model (or lighting model or shading model) is
used to calculate the intensity of light that we should see at a given
point on the surface of an object.
• For each scan line, the intensity at the intersection of the scan line
with the polygon edge is linearly interpolated from the intensities at
the edge endpoints.
3) Linear interpolation of the vertex intensities over the surface of the
polygon:
• Once the surface normals are evaluated, the surface intensity at that
point is determined by applying the illumination model.
4. Halftone shading
• Many displays and hardcopy devices are bilevel. They can only
produce two intensity levels (black and white).
• Halftoning is a process of increasing the number of intensities by
taking combine intensity of multiple pixels in to account.
• If we view from sufficient large viewing distance, the human visual
system has a tendency to average brightness over small areas, so the
black dots and their white background merge and are perceived as an
intermediate shade of grey.
• Halftone reproductions are usually done in pixel regions such as 2×2
or 3×3 pixels. These regions are called halftone pattern or pixel
pattern.
• Following are the halftone patterns that create number of intensity
levels:
• This process is used in black and white photographs and publishing
of newspapers, magazines and books.
• Newspaper photographs simulate a greyscale, despite the fact that
they have been printed using only black ink.
• A newspaper picture is, in fact, made up of a pattern of tiny black
dots of varying size.
Halftone: Dot size
Hidden Surfaces
●
When we view a picture containing non-transparent objects and
surfaces, then we cannot see those objects which are behind from
objects closer to eye.
●
We must remove these hidden surfaces to get a realistic screen image.
●
Surface determination (also known as hidden surface removal
(HSR), occlusion culling (OC) or visible surface determination
(VSD)) is the process used to determine which surfaces and parts of
surfaces are not visible from a certain viewpoint.
●
There are two approaches for removing hidden surface problems −
1)Object-Space method
2)Image-space method
1) Object-space methods: compares objects & parts of objects to each other
within the scene definition to determine which surfaces, as a whole, we
should label as visible.
2) Image-space methods: visibility is decided point by point at each pixel
position on the projection plane.
●
Hidden Surface Removal consists of two steps:
i. Backface culling: Polygons facing away from the viewer are removed
ii. Occlusion: Polygons farther away are obscured by closer polygons (i.e.
closer objects occludes the others). Full or partially occluded portions of the
polygons are removed.
●
Why should we remove these polygons?
To avoid unnecessary expensive operations on these polygons later.
Occlusion: Full, Partial, None
●
The rectangle is closer than the triangle (Rectangle is occluding the triangle).
Hence it should appear in front of the triangle
Back-Face Detection and removal
(Back-Face Culling)
●
Back-Face Culling avoids drawing polygons facing away from the viewer.
●
It is object space method.
●
The polygon normal of a …
➔
front-facing polygon points towards the viewer
➔
back-facing polygon points away from the viewer
●
The equation for plane surface can be expressed as −
Ax + By + Cz + D = 0
Where (x, y, z) is any point on the plane, and the coefficients A, B, C, and D are
constants describing the spatial properties of the plane.
●
For any point (x, y, z) with parameters A, B, C, and D, we can say that −
V . N >= 0
(Above condition can be considered as: VNcosθ>=0 where θ is angle between V and
N)
Depth buffer (z-buffer) Algorithm
●
It is an image space approach.
●
It is proposed by Catmull in 1974.
●
Easy to implement.
●
Each surface is processed separately one pixel position at a time across the
surface.
●
The depth values for a pixel are compared and the closest (smallest z)
surface determines the color to be displayed in the frame buffer.
●
Surfaces are processed in any order.
●
The z-coordinates (depth values) are usually normalized to the range [0,1].
●
Two buffers named frame buffer and depth buffer, are used.
●
Depth buffer is used to store depth values for (x, y) position, as surfaces are
processed (0 ≤ depth ≤ 1).
●
The frame buffer is used to store the intensity value of color value at each
position (x, y).
●
We can calculate depth of the polygon at each pixel position (x,y).
●
For calculation of depth (z), we use polygon surface equation as:
Area subdivision (Warnock) Algorithm
●
The Warnock algorithm is a hidden surface algorithm developed by John
Warnock.
●
The total viewing area is successively divided into smaller and smaller
rectangles until each small area is simple, I.e. it is a single pixel, or is
covered wholly by a part of a single visible surface or no surface at all.
●
We first classify each of the surfaces, according to their relations with the area:
➔
Surrounding surface - a single surface completely encloses the area
➔
Intersecting or Overlapping surface - a single surface that is partly inside and
partly outside the area
➔
Inside or contained surface - a single surface that is completely inside the area
➔
Outside or disjoint surface - a single surface that is completely outside the
area.
Algorithm:
1. Initialize the area to be the whole screen.
2. Generate list of polygons by sorting them with their z values.
3. Remove polygons which are outside the area (Don't include disjoint polygons in the list
because they are not visible).
4. Identify relationship of each polygon (surface) with area.
5. Execute visibility decision analysis:
a)Fill area with background color if all polygons are disjoint,
b) If there is only one intersecting polygon or only one contained polygon, fill entire area
with background color and fill part of polygon contained in area with color of polygon,
c) If there is a single surrounding polygon, but no intersecting or contained polygon then
fill area with color of surrounding polygon.
d) If surrounding polygon is closer to the viewpoint than all other polygons, so that all
other polygons are hidden by it, fill the area with the colour of the surrounding polygon.
e) If area is the pixel (x,y) and neither of (a) to (d) applies, calculate z- coordinate at pixel
(x,y) of all polygons in the list. The pixel is then set to colour of the polygon which is
closer to the viewpoint.
6. If none of above is correct then subdivide the area and Go to Step 2.
●
As shown in above figure (a), we can not make any decision about which
polygon is in front of other (because none of the condition in step 5 in
Warnock's algorithm is true). So we go for subdividing the area.
●
After subdividing area of interest (as in figure(b)), polygon 1 is ahead of the
polygon 2 in left area and polygon 2 is ahead of polygon 1 in right area.
Now we can fill these two areas with corresponding colours of the polygons.
Depth sorts (Painter's) Algorithm
●
The depth-sorting method performs two basic functions −
●
First, the surfaces are sorted in order of decreasing depth.
●
Second, the surfaces are scan-converted in order, starting with the
surface of greatest depth.
Key Idea
Test 0: Check for Z-extents overlap
Test-1: Check for X and Y-extent Overlap
Check for Y-extent overlap
• If Test 4 also fails (means all test from 0-4 fail) then
re-orderring of polygons is required.