tut4

advertisement
Normal Estimation and
Clipping Methods
Images were taken from the book: “Interactive Computer Graphics” by Angel and Shreiner
Normal Vectors
• How to compute the normal per planar face?
𝑛 𝑇 =
π‘₯𝑗 − π‘₯𝑖 × π‘₯π‘˜ − π‘₯𝑖
π‘₯𝑗 − π‘₯𝑖 × (π‘₯π‘˜ − π‘₯𝑖 )
Normal Vectors
• However, vertex normals are not well defined
• Nevertheless, assume the shape is smooth
𝑛 𝑣 =
𝑇∈𝒩1 (𝑣) πœ” 𝑇 𝑛
𝑇
𝑇∈𝒩1 (𝑣) πœ” 𝑇 𝑛
𝑇
• How to choose πœ” 𝑇 ? E.g., πœ” 𝑇 = 1, 𝑇 , πœƒπ‘‡
Normal Vectors
• How to transform normal vectors?
• Using the transformation matrix won’t work!
Normal Vectors
• How to transform normal vectors?
• The following should hold
𝑛 ⋅ 𝑑 = 0 = 𝐺𝑛 ⋅ 𝑀𝑑
• Thus, 𝐺 T 𝑀 = I ⇒ 𝐺 = 𝑀−1
T
Clipping
• When and how to perform clipping?
• Wireframe rendering:
– Clipping can be done in screen coordinates
– Cull/Draw the triangle if it is outside/inside
– Border triangles:
• Line-Segment clipping or
• Ignore pixels
Line-Segment Clipping
• Given two endpoints π‘₯1 , 𝑦1
T
and π‘₯2 , 𝑦2
• Line segment in parametric form: 𝛼 ∈ 0,1
π‘₯ 𝛼 = 1 − 𝛼 π‘₯1 + 𝛼π‘₯2 ,
𝑦 𝛼 = 1 − 𝛼 𝑦1 + 𝛼𝑦2 .
T
π‘₯ 𝛼 = 1 − 𝛼 π‘₯1 + 𝛼π‘₯2 ,
𝑦 𝛼 = 1 − 𝛼 𝑦1 + 𝛼𝑦2 .
Line-Segment Clipping
• Liang–Barsky [TOG ‘84] Clipping
• Defer computation of line intersection asmuch-as-possible
π‘₯ 𝛼 = π‘₯1 + 𝛼(π‘₯2 − π‘₯1 ),
𝑦 𝛼 = 𝑦1 + 𝛼(𝑦2 − 𝑦1 ).
Liang–Barsky Clipping
• A point is in the clip window if
π‘₯min ≤ π‘₯1 + 𝛼Δπ‘₯ ≤ π‘₯max ,
𝑦min ≤ 𝑦1 + 𝛼Δ𝑦 ≤ 𝑦max .
π‘₯ 𝛼 = π‘₯1 + 𝛼(π‘₯2 − π‘₯1 ),
𝑦 𝛼 = 𝑦1 + 𝛼(𝑦2 − 𝑦1 ).
Liang–Barsky Clipping
• A point is in the clip window if
π›Όπ‘π‘˜ ≤ π‘žπ‘˜ , π‘˜ = 1,2,3,4
• Where
𝑝1 = −Δπ‘₯,
𝑝2 = Δπ‘₯,
𝑝3 = −Δ𝑦,
𝑝4 = Δ𝑦,
π‘ž1 = π‘₯1 − π‘₯min
π‘ž2 = π‘₯max − π‘₯1
π‘ž3 = 𝑦1 − 𝑦min
π‘ž4 = 𝑦max − y1
left
right
bottom
top
π›Όπ‘π‘˜ ≤ π‘žπ‘˜
Liang–Barsky Clipping
• Determine the final line segment
– Find π‘˜ for which π‘π‘˜ < 0, then 𝛼1 = max
π‘žπ‘˜
0,
π‘π‘˜
.
– Find π‘˜ for which π‘π‘˜ > 0, then 𝛼2 = min
π‘žπ‘˜
1,
π‘π‘˜
.
– Similarly for 𝛼3 and 𝛼4
Polygon Clipping
• Follows directly from line-clipping
• Apply clipping to the edges of the polygon
• Clipping a convex polygon against a convex
polygon results in at most one convex object
Polygon Clipping
• We can implement a clipping pipeline
• Each clipper clips against one window’s edge
Polygon Clipping
• Example of pipeline clipping
Clipping
• When and how to perform clipping?
• Scan Conversion
– Perform clipping before perspective division
– The visible volume
𝑀 ≥ π‘₯ ≥ −𝑀,
𝑀 ≥ 𝑦 ≥ −𝑀,
𝑀 ≥ 𝑧 ≥ −𝑀.
Clipping
• For each model
– Determine if it is inside/outside the view volume
• Intersect its bounding box with the view volume
– For each boundary model
• Perform polygon-clipping for each triangle
• Thus, extend our clipping to three dimensions
Bounding Box
• How to compute the bounding box?
• Find the minimal/maximal coordinates
3D Polygon Clipping
• Extend Liang–Barsky with the equation
𝑧 𝛼 = 1 − 𝛼 𝑧1 + 𝛼𝑧2
• Add near and far clippers in the pipeline
• Need to adjust intersection computations…
3D Polygon Clipping
• Plane–Line intersection is given by
𝑛 ⋅ 𝑝0 − 𝑝1
𝛼=
𝑛 ⋅ 𝑝2 − 𝑝1
Suggested Readings
• Transforming Normals:
– http://www.lighthouse3d.com/tutorials/glsl-tutorial/the-normal-matrix/
– http://www.unknownroad.com/rtfm/graphics/rt_normals.html
• Interactive Computer Graphics, Chapter 6
• Liang–Barsky Clipping:
– http://en.wikipedia.org/wiki/Liang%E2%80%93Barsky_algorithm
Download