If you cannot see it, ignore it
•
CULLING
– Do not render the primitives that are not visible
– Throw away the primitives that do not change
the scene
• Or with negligible impact
– Do it as soon as possible! (in the pipeline)
Notation
•
We call it
culling
if we discard primitives
– Or groups of primitives
•
If a primitive is divided into a visible part and a not
visible one, we call it
clipping
•
If we discard a fragment, this is
fragment
testing
Notation
•
We call it
culling
if we discard primitives
– Or groups of primitives
•
If a primitive is divided into a visible part and a not
visible one, we call it
clipping
•
If we discard a fragment, this is
fragment testing
(in most cases)
an
optimization
!
(in most cases)
(in most cases)
Forms of Culling
•
Occlusion
culling
– Not visible ... because it is covered
•
View-frustum
culling
– Not visible... because it is outside the view frustum
•
Backface
culling
– Not visible... because it is in the inside of a closed figure
•
Importance
culling
Forms of Culling
• Executed in hardware
– automated
– Very efficient (very small overhead)
– But discard late and only one primitive at the time
• Executed by the application (SW)
– Require algorithms and data structures
– Less efficient (quite large overhead)
Forms of Culling
• Conservative
– Only discard when sure
– Sometimes they draw objects not visible
• Non Conservative
– Discrad according to an heuristics
– Sometimes they DO NOT draw a (partly) visible
object!
Less efficient but sound.
•
We call artifact a rendering error,
– A discrepancy between the model and the image
– Or between reality and the model
– In most cases, it draws on the screen a
non-existant detail
parentesi notazione parentesi notazione parentesi notazione
Culling and Visibility
Computer Graphics Pagina 8
•
We call artifact a rendering error,
– A discrepancy between the model and the image
– Or between reality and the model
– In most cases, it draws on the screen a non-existant
detail
parentesi notazione parentesi notazione parentesi notazione
Forms of Culling
•
Occlusion
culling
– Not visible ... because it is covered
•
View-frustum
culling
– Not visible... because it is outside the view frustum
•
Backface
culling
– Not visible... because it is in the inside of a closed figure
•
Importance
culling
Backface Culling
•
Idea:
– We are modeling the surface of a
closed
object
...
– I cannot see the inside
(HW) Backface Culling: Where?
Final pixels
(HW) Backface Culling: How much?
Throw away approx 50% of the faces...
The speed-up?
x2
?
...only after this step!
Final pixels
(HW) Backface culling: when?
•
I cannto use it always!
– Need to know
a priori
that the object is closed
primitives
here
OpenGL state
(HW) Backface culling: How?
•
Turn it on and off:
glEnable( GL_CULL_FACE );
glDisable( GL_CULL_FACE );
• Deciding whether to discard the front
orback-facing faces:
glCullFace(GL_FRONT );
glCullFace(GL_BACK );
These commands only change
the state. “not the screen"
Metodologie di Culling
•
Occlusion
culling
– Not visible ... because it is covered
•
View-frustum
culling
– Not visible... because it is outside the view frustum
•
Backface
culling
– Not visible... because it is in the inside of a closed figure
•
Importance
culling
(HW) View-frustum culling
•
Given a primitive
– triangle, segment, point
•
Is it inside the view frustum?
– (or partly inside- conservative!)
y
x
• Better working in normalized
coordinates
(HW) View-frustum Culling: where?
...as usual, only from this step!
Final pixels
Software View-frustum Culling
•
Idea: do it before pushing the triangles in the
rendering pipeline
•
Divide the scene into blocks
– Most scenes are naturally organized in blocks
Forms of Culling
•
Occlusion
culling
– Not visible ... because it is covered
•
View-frustum
culling
– Not visible... because it is outside the view frustum
•
Backface
culling
– Not visible... because it is in the inside of a closed figure
•
Importance
culling
Occlusion Culling
•
Very important form of culling
•
Can discard lots of primitives
– Mostly the primitives composing the
– environment
•
Where can we apply it ?
Final pixels
Hidden surfaces removal
•
Closer objects must cover thode more far
away
Hidden surfaces removal
•
Different from
occlusion culling
– Can only remove whole triangles (or groups of
triangles)
– It is only an optimization
•
Back-face culling is not enough
– example:
non back-facing
surfaces, not totally,
Hidden surfaces removal
•
Solution 1:
– Split any triangle into a visible and an occluded
part?
• By performing a clipping
How to decide when a triangle occludes another one?
One triangle is clipped and what about the other?
Hidden surfaces removal
•
Solution 2:
– Draw only whole triangles, but in the
right order
Painter’s algorithm (depth sorting)
•
Given a scene (composed of primitives)
– Sort the primitives by depth
• From the farthest away to the closest one to the viewpoint
– Draw them all (according to the ordering)
Painter’s algorithm (depth sorting)
Where?
y
v
0v
1v
0
v
1Before feeding the triangles.
Executed by the CPU !
Final pixels
Painter’s algorithm (depth sorting)
•
Given a scene (composed of primitives)
– Sort the primitives by depth
• From the farthest away to the closest one to the viewpoint
– Draw them all (according to the ordering)
Sorting
!
Pseudolinear
complexity wrt the
number of primitives.
The primitive has more than
one depth value!
Painter’s algorithm (depth sorting)
•
Should we draw C or D?
•
Does there exist a
“right order"?
D
ep
th
z
minPrimitives
B
z
maxA
E
D
C
Painter’s algorithm (depth sorting)
• The primitive A can be drawn first
•
Should we draw C or D?
•
Does there exist a “right order"?
– NO!
• intersections
Painter’s algorithm (depth sorting)
•
Computationally expensive
– sorting: (n log (n))
– Made in software!
•
Poorly integrated in the HW schema
– Works in eye coordinates
...but before the HW projection ?!
– Needs to work globally on the scene, not parallelizable
•
Difficult to test
– When the intervals overlap
•
It also uses clipping
Painter’s algorithm (depth sorting)
•
Only used when the primitives are already
sorted
– During the preprocessing phase
•
Example: ground represented as an
Hidden surfaces removal
•
Solution 3:
– Remove the hidden surfaces with a
FRAGMENT TEST
– "
Z-buffer
“ algorithm
z-buffer
Algorithm
fr
a
gm
e
nt
s
(c
an
di
da
te
p
ix
el
s)
V
e
rt
ic
es
(p
oi
nt
s
in
R
3)
P
ro
je
ct
e
d
ve
rt
ic
e
s
(p
oi
nt
s
in
R
2)
ZV
er
te
x
c
om
pu
ta
tio
ns
F
ra
gm
en
t
co
m
pu
ta
tio
ns
set-up
set-up
set-up
rasterizer
triangoli
Segments
rasterizer
rasterizer
punti
Triangles
rasterizer
Points
rasterizer
Screen
buffer
Depth
buffer
RGB values
fr
ag
m
en
ts
(c
an
di
da
te
p
ix
el
s)
V
er
tic
es
(p
oi
nt
s
in
R
3)
P
ro
je
ct
e
d
ve
rt
ic
es
(p
oi
nt
s
in
R
2)
ZV
er
te
x
c
om
pu
ta
tio
ns
F
ra
gm
en
t
co
m
pu
ta
tio
ns
set-up
set-up
set-up
rasterizer
triangoli
Segments
rasterizer
rasterizer
punti
Triangles
rasterizer
Points
rasterizer
Screen
buffer
Depth
buffer
z-buffer
Algorithm
Transform.
Add the
resulting z
As an
attribute
Interpolate
s
the z
(likewise
other
attributes)
depth test
Fragment with screen coordinates
(x,y)
and interpolated z:
if ( z <= DepthBuffer[x,y] ) {
WriteFragment
fr
a
gm
e
nt
s
(c
an
di
da
te
p
ix
el
s)
V
e
rt
ic
es
(p
oi
nt
s
in
R
3)
P
ro
je
ct
e
d
ve
rt
ic
e
s
(p
oi
nt
s
in
R
2)
ZV
er
te
x
c
om
pu
ta
tio
ns
F
ra
gm
en
t
co
m
pu
ta
tio
ns
set-up
set-up
set-up
rasterizer
triangoli
Segments
rasterizer
rasterizer
punti
Triangles
rasterizer
Points
rasterizer
Screen
buffer
Depth
buffer
z-buffer
Algorithm
z-buffer
Algorithm
:
example
64 64 64 64 64 64 64 6464 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64
5 5
5
5 5 5 5 5 5 5 64 5 5 5 5 5 5 64 64 5 5 5 5 5 64 64 64 5 5 5 5 64 64 64 64 5 5 5 64 64 64 64 64 5 5 64 64 64 64 64 64 5 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64
+
=
5 5 5 5 5 5 5 64 5 5 5 5 5 5 64 64 5 5 5 5 5 64 64 64 5 5 5 5 64 64 64 64 5 5 5 64 64 64 64 64 5 5 64 64 64 64 64 64 5 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64
7
2 7
5 5 5 5 5 5 5 64 5 5 5 5 5 5 64 64 5 5 5 5 5 64 64 64 5 5 5 5 64 64 64 64 4 5 5 7 64 64 64 64 3 4 5 6 7 64 64 64 2 3 4 5 6 7 64 64 64 64 64 64 64 64 64 64
+
=
5 5 5 5 5 5 5 5 5 5 5 5 5z-buffer
Algorithm
:
properties
•
Does not depend on the order of the primitives
•
Works in all cases
– even:
•
Fragment Operation
– Is executed in the
“fragment computations"
•
Well suited for a HW implementation
5 5 5 5 5 5 5 64