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