CE 306 - Computer Graphics

brasscoffeeΤεχνίτη Νοημοσύνη και Ρομποτική

17 Νοε 2013 (πριν από 3 χρόνια και 6 μήνες)

64 εμφανίσεις

Learning Objectives


Classification of Visible Surface Detection
Algorithms


Back
-
Face Detection


Depth
-
Buffer Method


Scan
-
Line Method


Depth
-
Sorting Method


Wire
-
Frame Visibility Methods


OpenGL

Visibility Detection Functions


Visible Surface Detection


A major consideration in the generatation of
realistic graphics is determining what is visible
within a scene from a chosen viewing position


Algorithms to detect visible objects are referred
to as visible
-
surface detection methods

Classification of Visible Surface
Detection Algorithms


Object
-
space methods


Compares objects and parts of object to each other
within the scene definition to determine which
surfaces should be marked as visible


Image
-
space methods


Visibility is decided point by point at each pixel
position

Back
-
Face Detection


A fast and simple object
-
space method for
locating back faces


A point (x,y,z) is “inside” a polygon surface with
plane parameters A, B, C, D if :


Ax + By + Cz + D < 0


When an inside point is along the line of sight to
the surface, the polygon must be a back face and
so cannot be seen


Back
-
Face Detection


The test is simplified by considering the normal vector
N to the polygon and the viewing vector V







This is back face if

V
·

N > 0

Depth Buffer Method


A commonly used image
-
space approach


Each surface is processed separately, one point
at a time


Also called the z
-
buffer method


It is generally hardware implemented

Depth Buffer Method


3 surfaces overlap at (x,y). S
1

has the smallest
depth value

Depth Buffer Method


Two buffers are needed


Depth buffer (distance information)


Frame buffer (intensity/color information)

Depth Buffer Method


Depth
-
Buffer Algorithm


for all (x,y)



depthBuff(x,y) = 1.0,


frameBuff(x,y)=backgndcolor


for each polygon P



for each position (x,y) on polygon P




calculate depth z





if z < depthBuff(x,y) then






depthBuff(x,y) =z







frameBuff(x,y)=surfColor(x,y)


Scan
-
Line Method


Image space method


Extension of scan
-
line algorithm for polygon
filling


As each scan line is processed, all polygon
surface projections intersecting that line are
examined to determine which are visible

Scan
-
Line Method


Example

Depth
-
Sorting Method


Both image
-
space and object
-
space operations


Also called painter’s algorithm


Surfaces sorted in order of increasing depth


Surfaces scan
-
converted in order, starting with the surface of
greatest depth

B behind A as seen by viewer

Fill B then A


Display all object edges


difficult to determine front and back






Depth cueing


displayed intensity of a line is a function of its
distance from the viewer

Wire
-
Frame Visibility Methods

Wire
-
Frame Visibility Methods


Detect hidden lines and display them differently

Wire
-
Frame Surface
-
Visibility


Compare edge positions with surface positions


Similar to line clipping, but we need to compare depths as well

Wire
-
Frame Depth Cueing


Vary the brightness of objects in a scene as a function of
distance from the viewing position

min
max
max
)
(
d
d
d
d
d
f
depth




Multiply each pixel color by:

Where d is the distance of a point
from the viewing position

OpenGL

Visibility Detection
Functions


Back
-
face removal:

glEnable(GL_CULL_FACE);

glCullFace(mode);

GL_BACK, GL_FRONT, GL_FRONT_AND_BACK

glDisable(GL_CULL_FACE);

default


GL_BACK is default. Sometimes we want to see the back faces,
for example if we are in a room we can use GL_FRONT

OpenGL

Visibility Detection
Functions

Depth
-
buffer functions:


Request depth buffer when initializing:


glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);


Clear depth buffer each time a new frame is displayed:


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


OpenGL depth
-
buffer visibility
-
detection routines can be
activated with


gl
Enable
(GL_
DEPTH_TEST
);


and deactivated with


gl
Disable
(GL_
DEPTH_TEST
);




OpenGL

Visibility Detection
Functions


Wire
-
frame surface visibility:


glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

OpenGL

Visibility Detection
Functions


Depth cueing:



glEnable(GL_FOG);


glFogi(GL_FOG_MODE, GL_LINEAR);


This applies the linear depth function to object colors using
d
min
=0.0 and d
max
=1.0. We can set different values for d
min
and
d
max

with the following function calls


glFogf(GL_FOG_START, minDepth);


glFogf(GL_FOG_END, maxDepth);