CS 6958 LECTURE 7 TRIANGLES, BVH January 29, 2014
Triangles 2 ο¨ Letβs try to derive an intersection test
Barycentric Coordinates 3 π 1 π 2 π 3 π 0 β€ π 1 , π 2 , π 3 β€ 1 π 1 π 1 + π 2 + π 3 = 1 π 2 π 3 π = π 1 π 1 + π 2 π 2 + π 3 π 3 π = π 1 π 1 + π 2 π 2 + 1 β π 1 β π 2 π 3
Barycentric Coordinates 4 π 1 π 2 π 3 π 0 β€ π 1 , π 2 , π 3 β€ 1 π 1 π 1 + π 2 + π 3 = 1 π 2 π 3 π = π 1 π 1 + π 2 π 2 + π 3 π 3 π = π 1 π 1 + π 2 π 2 + 1 β π 1 β π 2 π 3 π + π’π = π 1 π 1 + π 2 π 2 + 1 β π 1 β π 2 π 3
Barycentric Coordinates 5 π + π’π = π 1 π 1 + π 2 π 2 + 1 β π 1 β π 2 π 3 βπ’π + π 1 π 1 β π 3 + π 2 π 2 β π 3 = π β π 3 π 1 π 1 = π 1 β π 3 π 2 = π 2 β π 3 π‘ = π β π 3 π 2 π 3 π βπ π 1π¦ π 2π¦ π‘ π¦ π’ π¦ π 1 βπ π 1π§ π 2π§ π 1 π‘ π§ = π§ π 2 π 3 π‘ π¨ π 2 βπ π 1π¨ π 2π¨ π¨
Solution β Cramerβs Rule 6 βπ π‘ π¦ π 2π¦ βπ π 1π¦ π‘ π¦ π‘ π¦ π 1π¦ π 2π¦ π¦ π¦ βπ π‘ π§ π 2π§ βπ π 1π§ π‘ π§ π‘ π§ π 1π§ π 2π§ π§ π§ βπ π‘ π¨ π 2π¨ βπ π 1π¨ π‘ π¨ π‘ π¨ π 1π¨ π 2π¨ π¨ π¨ π’ = , π 1 = , π 2 = βπ π 1π¦ π 2π¦ βπ π 1π¦ π 2π¦ βπ π 1π¦ π 2π¦ π¦ π¦ π¦ βπ π 1π§ π 2π§ βπ π 1π§ π 2π§ βπ π 1π§ π 2π§ π§ π§ π§ βπ π 1π¨ π 2π¨ βπ π 1π¨ π 2π¨ βπ π 1π¨ π 2π¨ π¨ π¨ π¨ ο¨ In reality too slow for intersections, but we can do better!
Scalar Triple Product 7 ο¨ Scalar triple product π΅ β πΆ Γ π· = πΆ β π· Γ π΅ = π· β π΅ Γ πΆ ο¨ Also expressed as a determinant π΅ π¦ π΅ π§ π΅ π¨ πΆ π¦ πΆ π§ πΆ π¨ π· π¦ π· π§ π· π¨ ο¨ This comes in handy π΅ π = π΅
Faster Solution 8 βπ βπ βπ π¦ π¦ π¦ π 1π¦ π 1π§ π 1π¨ πππππ = π 2π¦ π 2π§ π 2π¨ = βπ β π 1 Γ π 2 = βπ 1 β π 2 Γ π = π 1 β π Γ π 2 πππππ = π 1 β π Γ π 2 π’ = π 2 β π‘ Γ π 1 πππππ π 1 = π‘ β π Γ π 2 πππππ π 1 = π β π‘ Γ π 1 πππππ
Ray-Triangle Intersection 9 π 1 = π 1 β π 3 π 2 = π 2 β π 3 π 1 = π Γ π 2 πππππ = π 1 β π 1 if( πππ‘ πππππ < π ) miss, return;
Ray-Triangle Intersection 10 π 1 = π 1 β π 3 π 2 = π 2 β π 3 π 1 = π Γ π 2 πππππ = π 1 β π 1 if( πππ‘ πππππ < π ) miss, return; πππ€πΈππππ = 1 πππππ s = π β π 3 π 1 = π‘ β π 1 πππ€πΈππππ if( π 1 < 0 β₯ π 1 > 1 ) miss, return;
Ray-Triangle Intersection 11 π 1 = π 1 β π 3 π 2 = π 2 β π 3 π 1 = π Γ π 2 πππππ = π 1 β π 1 if( πππ‘ πππππ < π ) miss, return; πππ€πΈππππ = 1 πππππ s = π β π 3 π 1 = π‘ β π 1 πππ€πΈππππ if( π 1 < 0 β₯ π 1 > 1 ) miss, return; π 2 = π‘ Γ π 1 π 2 = π β π 2 πππ€πΈππππ if( π 2 < 0 β₯ π 1 + π 2 > 1 ) miss, return; t = π 2 β π 2 πππ€πΈππππ hit! save π 1 and π 2 for interpolation
Operation add / sub / mult compare divide π 1 = π 1 β π 3 3 12 π 2 = π 2 β π 3 3 π 1 = π Γ π 2 9 πππππ = π 1 β π 1 5 if( πππ‘ πππππ < π ) miss, return; 2 πππ€πΈππππ = 1 πππππ 1 s = π β π 3 3 π 1 = π‘ β π 1 πππ€πΈππππ 6 if( π 1 < 0 β₯ π 1 > 1 ) miss, return; 2 π 2 = π‘ Γ π 1 9 π 2 = π β π 2 πππ€πΈππππ 6 if( π 2 < 0 β₯ π 1 + π 2 > 1 ) miss, return; 1 2 t = π 2 β π 2 πππ€πΈππππ 6 hit! save π 1 and π 2 for interpolation 2 total 20 / 29 / 45 / 51 2 / 4 / 6 / 8 0 / 1 / 1 / 1
Normals 13 ο¨ Flat shaded triangles π = π 1 Γ π 2 ο¨ Smooth shaded (per-vertex normals) π = π 1 π 1 + π 2 π 2 + 1 β π 1 β π 2 π 3
Updates to Hitrecord 14 ο¨ include barycentric coordinates ο¨ include computed normal ο€ alternatively, save per-vertex normals and interpolate before shading
Which Operation Most Costly? 15 foreach frame foreach pixel foreach sample generate ray intersect ray with objects shade intersection point
End 16
Recommend
More recommend