cs 6958 lecture 7 triangles bvh
play

CS 6958 LECTURE 7 TRIANGLES, BVH January 29, 2014 Triangles 2 - PowerPoint PPT Presentation

CS 6958 LECTURE 7 TRIANGLES, BVH January 29, 2014 Triangles 2 Lets try to derive an intersection test Barycentric Coordinates 3 1 2 3 0 1 , 2 , 3 1 1 1 + 2 + 3 = 1 2


  1. CS 6958 LECTURE 7 TRIANGLES, BVH January 29, 2014

  2. Triangles 2  Let’s try to derive an intersection test

  3. 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

  4. 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

  5. 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𝑨 𝑨

  6. 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!

  7. Scalar Triple Product 7  Scalar triple product 𝐡 βˆ™ 𝐢 Γ— 𝐷 = 𝐢 βˆ™ 𝐷 Γ— 𝐡 = 𝐷 βˆ™ 𝐡 Γ— 𝐢  Also expressed as a determinant 𝐡 𝑦 𝐡 𝑧 𝐡 𝑨 𝐢 𝑦 𝐢 𝑧 𝐢 𝑨 𝐷 𝑦 𝐷 𝑧 𝐷 𝑨  This comes in handy 𝐡 π‘ˆ = 𝐡

  8. Faster Solution 8 βˆ’π‘Š βˆ’π‘Š βˆ’π‘Š 𝑦 𝑦 𝑦 𝑓 1𝑦 𝑓 1𝑧 𝑓 1𝑨 π‘’π‘“π‘œπ‘π‘› = 𝑓 2𝑦 𝑓 2𝑧 𝑓 2𝑨 = βˆ’π‘Š βˆ™ 𝑓 1 Γ— 𝑓 2 = βˆ’π‘“ 1 βˆ™ 𝑓 2 Γ— π‘Š = 𝑓 1 βˆ™ π‘Š Γ— 𝑓 2 π‘’π‘“π‘œπ‘π‘› = 𝑓 1 βˆ™ π‘Š Γ— 𝑓 2 𝑒 = 𝑓 2 βˆ™ 𝑑 Γ— 𝑓 1 π‘’π‘“π‘œπ‘π‘› 𝑐 1 = 𝑑 βˆ™ π‘Š Γ— 𝑓 2 π‘’π‘“π‘œπ‘π‘› 𝑐 1 = π‘Š βˆ™ 𝑑 Γ— 𝑓 1 π‘’π‘“π‘œπ‘π‘›

  9. Ray-Triangle Intersection 9 𝑓 1 = 𝑄 1 βˆ’ 𝑄 3 𝑓 2 = 𝑄 2 βˆ’ 𝑄 3 𝑠 1 = π‘Š Γ— 𝑓 2 π‘’π‘“π‘œπ‘π‘› = 𝑓 1 βˆ™ 𝑠 1 if( 𝑏𝑐𝑑 π‘’π‘“π‘œπ‘π‘› < πœ— ) miss, return;

  10. 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;

  11. 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

  12. 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

  13. Normals 13  Flat shaded triangles 𝑂 = 𝑓 1 Γ— 𝑓 2  Smooth shaded (per-vertex normals) 𝑂 = 𝑐 1 𝑂 1 + 𝑐 2 𝑂 2 + 1 βˆ’ 𝑐 1 βˆ’ 𝑐 2 𝑂 3

  14. Updates to Hitrecord 14  include barycentric coordinates  include computed normal ο‚€ alternatively, save per-vertex normals and interpolate before shading

  15. Which Operation Most Costly? 15 foreach frame foreach pixel foreach sample generate ray intersect ray with objects shade intersection point

  16. End 16

Recommend


More recommend