Advanced Computer Graphics Spring 2014

41
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology

description

Advanced Computer Graphics Spring 2014. K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology. Triangle/Triangle Intersection (ERIT ’ s Method). Compute п 2 :n 2  x + d 2 , the plane in which T 2 lies. - PowerPoint PPT Presentation

Transcript of Advanced Computer Graphics Spring 2014

Page 1: Advanced Computer Graphics  Spring 2014

Advanced Computer Graphics Spring 2014

K. H. KoSchool of Mechatronics

Gwangju Institute of Science and Technology

Page 2: Advanced Computer Graphics  Spring 2014

2

Triangle/Triangle Intersection(ERIT’s Method)1. Compute п2:n2x + d2, the plane in which T2 lies.

2. Trivially reject if all points of T1 are on the same side of п2.

3. If the triangles are coplanar, use the coplanar triangle-triangle test used in the interval overlap method.

4. Compute the intersection between п2 and T1, which clearly is a line segment that is coplanar with п2.

5. If this line segment intersects or is totally contained in T2, then T1 and T2 intersect; otherwise, they do not.

Page 3: Advanced Computer Graphics  Spring 2014

3

Triangle/Triangle Intersection(ERIT’s Method) Steps 1 and 2 are the same as for the interval

overlap method. Step 4 requires computation of two points, p and

q, in п2 representing the line of intersection. We have the signed distances from the points of T1 and

п2 from step 2, p and q can be computed by First finding points of T1 that lie on different sides of п2. When such a pair, say with index i1 and i2, has been found,

the intersection point p is

12

21

1

1 iiuu

u

i uudd

dup

ii

i

Page 4: Advanced Computer Graphics  Spring 2014

4

Triangle/Triangle Intersection(ERIT’s Method) Step 4 requires computation of two points, p and

q, in п2 representing the line of intersection. The point q is computed similarly, with another pair of

indices found in the same manner. Step 5 is accomplished by

First projecting T2, p and q onto the coordinate plane (x=0, y=0, z=0) where the area of T2 is maximized.

Both points of the projected line must be tested against each half-plane formed by each triangle edge of T2.

The line formed by the edge of the triangle divides the plane into two sides.

Page 5: Advanced Computer Graphics  Spring 2014

5

Triangle/Triangle Intersection(ERIT’s Method)

If both points are outside any triangle edge of T2, the triangles do not intersect.

If either endpoint is inside all three triangle edges of T2, the triangles must intersect.

It is possible that neither endpoint is inside T2, nor both fully outside any half plane. For this case, each edge of T2 must be tested for intersection with the line segment pq.

Finding an intersection at any time implies that the triangles intersect.

Otherwise the triangles are disjoint.

Page 6: Advanced Computer Graphics  Spring 2014

6

Triangle/Box Overlap An algorithm for determining whether a

triangle intersects an axis-aligned box. Can be used to build voxel-spaces, test

triangles against boxes in collision detection, and test polygons against canonical view volumes, etc.

Consider an axis-aligned bounding box (AABB), defined by a center c, and a vector of half lengths, h, and a triangle Δu0u1u2.

Page 7: Advanced Computer Graphics  Spring 2014

7

Triangle/Box Overlap To simplify the tests, we first move the

box and the triangle. The box is centered around the origin, i.e. vi

= ui – c, i∈{0,1,2}.

Page 8: Advanced Computer Graphics  Spring 2014

8

Triangle/Box Overlap To test against an oriented box, we would first

rotate the triangle vertices by the inverse box transform, then use the test.

Based on the separating axis theorem, we test the following 13 axes:

[3 tests] e0=(1,0,0), e1=(0,1,0), e2=(0,0,1). Namely, test the AABB against the minimal AABB around the triangle.

[1 test] n, the normal of Δu0u1u2. We use a plane/AABB overlap test.

[9 tests] aij=ei ⅹfi, i,j ∈ {0,1,2}, where f0 = v1 – v0, f1 = v2- v1, and f2 = v0 –v2, the edge vectors.

Page 9: Advanced Computer Graphics  Spring 2014

9

Triangle/Box Overlap Derivation of one of the nine tests in Step 3.

When i = 0 and j = 0 -> a00 = e0ⅹf0 = (0,-f0z,f0y) We project the triangle vertices onto a00.

p0 = a00ᆞ v0 = v0zv1y – v0yv1z. p1 = a00ᆞ v1 = v0zv1y – v0yv1z = p0. p2 = a00ᆞ v2 = (v1y-v0y)v2z – (v1z-v0z)v2y.

Find min(p0,p2) (=min(p0,p1,p2)) and max(p0,p2) (=max(p0,p1,p2))

After the projection of the triangle onto a, we need to project the box onto a as well. We compute a “radius”, called r, of the box projected on

a as

Page 10: Advanced Computer Graphics  Spring 2014

10

Triangle/Box Overlap Derivation of one of the nine tests in

Step 3. We compute a “radius”, called r, of the box

projected on a as r = hx|ax| + hy|ay| + hz|az| = hy|ay| + hz|az|

ax = 0 for this particular axis.

Therefore, this axis test becomes if (min(p0,p2) > r or max(p0,p2) < -r) return false.

Page 11: Advanced Computer Graphics  Spring 2014

11

Triangle/Box Overlap As soon as a separating axis is found,

the algorithm terminates and returns “no overlap”.

If all tests pass, i.e. there is no separating axis, then the triangle overlaps the box.

Page 12: Advanced Computer Graphics  Spring 2014

12

BV/BV Intersection Tests A closed volume that totally contains a set

of objects is called a bounding volume (BV) for the set. The purpose of a BV is to provide simpler

intersection tests and make more efficient rejections.

Bounding volumes that are commonly used Sphere, AABB, k-DOP and OBB.

A fundamental operation is to test whether or not two bounding volumes overlap.

More complex BVs could have a tighter fit.

Page 13: Advanced Computer Graphics  Spring 2014

13

Sphere/Sphere Intersection For spheres, the intersection test is

simple and quick. Compute the distance between the two

spheres’ centers and then reject if this distance is greater than the sum of the two spheres’ radii.

Otherwise, they intersect. In implementation of this algorithm, the

squared distances of the various quantities are used.

Page 14: Advanced Computer Graphics  Spring 2014

14

Sphere/Box Intersection A sphere and an AABB

Find the point on the AABB that is closest to the sphere’s center, c.

One dimensional tests are used. One for each of the three axes of the AABB. The sphere’s center coordinate for an axis is tested against

the bounds of the AABB. If it is outside the bounds, the distance between the

sphere center and the box along this axis is computed and squared.

After we have done this along the three axes, the sum of these squared distances is compared to the squared radius, r2, of the sphere.

If the sum is less than the squared radius, the closest point is inside the sphere and the box overlaps.

Page 15: Advanced Computer Graphics  Spring 2014

15

Sphere/Box Intersection A sphere and an AABB

For sphere/OBB intersection, first transform the sphere’s center into the OBB’s space.

Now this center point is expressed in terms of the OBB’s axes. So the OBB can be treated as an AABB.

Page 16: Advanced Computer Graphics  Spring 2014

16

BV/BV Intersection AABB/AABB Intersection

The test for intersection between two AABBs is trivial.

Page 17: Advanced Computer Graphics  Spring 2014

17

BV/BV Intersection k-DOP/k-DOP Intersection

If two k-DOPs, A and B, are to be tested for intersection, then test all pairs of slabs (SA

i,SBi) for overlap.

si = SAi∩SB

i is a one-dimensional interval overlap test.

If at any time si = Φ (the empty set), then the BVs are disjoint and the test is terminated.

Otherwise, the slab overlap tests continues. If and only if all si ≠ Φ, 1≤ i ≤ k/2, then the BVs are

considered to be overlapping.

Page 18: Advanced Computer Graphics  Spring 2014

18

BV/BV Intersection OBB/OBB Intersection

Use the separating axis theorem. Given two OBBs, A and B, the test is done in the

coordinate system formed by A’s center and axes. This means that the origin is ac = (0,0,0) and that the

main axes in this coordinate system are au=(1,0,0), av=(0,1,0) and aw=(0,0,1).

B is assumed to be located relative to A, with a translation t and a rotation (matrix) R.

The separating axis theorem says that it is sufficient to find one axis that separates A and B to be sure that they are disjoint (do not overlap).

Page 19: Advanced Computer Graphics  Spring 2014

19

BV/BV Intersection OBB/OBB Intersection

Fifteen axes have to be tested. Three from the faces of A Three from the faces of B 9 from combinations of edges from A and B

Page 20: Advanced Computer Graphics  Spring 2014

20

BV/BV Intersection OBB/OBB Intersection

Page 21: Advanced Computer Graphics  Spring 2014

21

BV/BV Intersection

OBB/OBB Intersection A potential separating axis is

denoted as l and adopt the notation from the figure.

The “radii,” dA and dB, of the OBBs on the axis, l, are obtained by simple projections.

If and only if, l is a separating axis, then the intervals on the axis should be disjoint. That is the condition should hold

},,{

},,{

wvui

iBiB

wvui

iAiA

hd

hd

lb

la

BA dd lt

Page 22: Advanced Computer Graphics  Spring 2014

22

BV/BV Intersection

OBB/OBB Intersection If any of these 15 tests is positive, the OBBs

are disjoint (A ∩ B = Φ) Testing the axes in different orders has an

impact on performance.

Page 23: Advanced Computer Graphics  Spring 2014

23

View Frustum Intersection

One of the few operations called during bounding-volume-hierarchy (scene-graph) cull traversal is the intersection test between the view frustum and a bounding volume. These operations are thus critical to fast

execution. They should determine whether the BV is

totally inside (inclusion), totally outside (exclusion) , or whether it intersects the frustum.

Page 24: Advanced Computer Graphics  Spring 2014

24

View Frustum Intersection

Page 25: Advanced Computer Graphics  Spring 2014

25

View Frustum Intersection

We need the three returns outside / inside / intersect.

If a BV is found to be totally outside the view frustum, then that BV’s subtree will not be traversed further and none of its geometry will be rendered.

If the BV is totally inside, then no more frustum/BV tests need to be computed for that subtree and every renderable leaf will be drawn.

For a partially visible BV, the BV’s subtree is tested recursively against the frustum.

The complete test is called an exclusion / inclusion / intersection test.

The intersection could be too costly to compute. -> the BV is classified as “probably-inside”.

Page 26: Advanced Computer Graphics  Spring 2014

26

View Frustum Intersection

The complete test is called an exclusion / inclusion / intersection test. If a BV cannot be excluded successfully,

there are two choices. Treat the probably inside state as an inclusion. ->

everything inside the BV is rendered. Test each node in the subtree in turn for

exclusion. Neither choice is particularly good, some

attempt at quickly differentiating between intersection and inclusion is often worthwhile, even if the test is imperfect.

Page 27: Advanced Computer Graphics  Spring 2014

27

View Frustum Intersection

The quick classification tests do not have to be perfect for scene-graph culling. For differentiating exclusion from inclusion,

all that is required is that the test err on the side of inclusion. Objects which should actually be excluded can

erroneously be included. -> cost extra time Object that should be included should never be

quickly classified as excluded by the tests. -> rendering errors will occur.

Page 28: Advanced Computer Graphics  Spring 2014

28

View Frustum Intersection

An intersection test method between a frustum and a general object.

The idea is to transform the test from a BV/frustum test to a point/volume test.

Page 29: Advanced Computer Graphics  Spring 2014

29

View Frustum Intersection

The creation of the new volumes is independent of the position of the actual BV. It is dependent solely on the position of the

point relative to the BV. A BV with an arbitrary position can be

tested against the same volumes.

Page 30: Advanced Computer Graphics  Spring 2014

30

View Frustum Intersection(Frustum/Sphere Intersection)

A frustum for an orthographic view is a box, so the overlap test in this case becomes a sphere/OBB intersection and can be solved using the algorithm (Sphere/box intersection algorithm).

To further test whether the sphere is entirely inside the box, we treat the box as hollow when we are finding the closest point.

Page 31: Advanced Computer Graphics  Spring 2014

31

View Frustum Intersection(Frustum/Sphere Intersection)

We select the origin of the sphere as the point p to trace. If the sphere, with radius r, is moved along the inside and

along the outside of the frustum and as close to the frustum as possible, then the trace of p gives us the volumes that are needed to reformulate the frustum / sphere test.

The actual volumes are shown in the middle figure.

Page 32: Advanced Computer Graphics  Spring 2014

32

View Frustum Intersection(Frustum/Sphere Intersection)

Using the volume, the exact test can be done. If p is outside the dark gray volume, then the sphere is

outside the frustum. If p is inside the dark gray area, then the sphere is

inside the frustum. For the sake of efficiency, we use the

approximation that appears on the right side of the figure.

The dark gray volume has been extended so as to avoid the more complicated computations that the rounded corners would require.

Page 33: Advanced Computer Graphics  Spring 2014

33

View Frustum Intersection(Frustum/Sphere Intersection)

The outer volume consists of the planes of the frustum moved r distance units outwards in the direction of the frustum plane normal, and that the inner volume can be created by moving the planes of the frustum r distance units inwards in the direction of the frustum plane normals.

Assume that the plane equations of the frustum are such that the positive half-space is located outside of the frustum.

An actual implementation would loop over the six planes of the frustum and for each frustum plane, compute the signed distance from the sphere’s center to the plane.

Page 34: Advanced Computer Graphics  Spring 2014

34

View Frustum Intersection(Frustum/Sphere Intersection)

To reduce the number of planes that must be tested for a symmetric frustum, an octant test can be added to the view frustum test. The frustum is divided into eight octants,

much as an octree is subdivided.

Page 35: Advanced Computer Graphics  Spring 2014

35

View Frustum Intersection(Frustum/Sphere Intersection)

We only need to test against the three outer planes of the octant that the sphere center is in.

This test can be used to speed up the frustum tests for AABBs and OBBs.

Page 36: Advanced Computer Graphics  Spring 2014

36

View Frustum Intersection(Frustum/Cylinder Intersection)

The cylinder is treated as a line segment and the frustum is increased in size by the sphere’s radius.

Instead of increasing the frustum by a uniform radius in all directions, the axis of the cylinder is used to determine how the radius affects each frustum plane.

The absolute value of the dot product of the cylinder’s axis direction and the frustum plane’s normal is multiplied by the cylinder radius. This result is how much the frustum plane is moved outward.

Given the expanded frustum and the line segment representing the cylinder, it is simply a matter of intersecting the line segment with the frustum to determine whether the cylinder overlaps the frustum.

Page 37: Advanced Computer Graphics  Spring 2014

37

View Frustum Intersection(Frustum/Box Intersection)

If the view’s projection is orthographic, testing can be done using OBB/OBB intersection testing.

For general frustum/box intersection testing The test is similar to the frustum/sphere test in that the

OBB or AABB bounding box is checked against the six view frustum planes.

If all corner points of the bounding box are outside of one such plane, then the bounding box is guaranteed to be outside the frustum.

We can test two bounding box corners against a particular plane to find out on which side of the plane the box is, or whether it is intersecting the plane.

Page 38: Advanced Computer Graphics  Spring 2014

38

View Frustum Intersection(Frustum/Box Intersection)

The algorithm tests the box against each of the six frustum planes in turn.

If the box is outside one such plane, the box is outside the frustum and the test is terminated.

If the box is inside all six planes then the box is inside the frustum.

Else it is considered as intersecting the frustum. Since the plane/box test is more expensive than

the plane/sphere test, there is often a gain in using the octant test.

This test would immediately discard three of the six frustum planes.

Page 39: Advanced Computer Graphics  Spring 2014

39

View Frustum Intersection(Frustum Plane Extraction)

In order to do view frustum culling, the plane equations for the six different sides of the frustum are needed.

Assume that the view matrix is V and that the projection matrix is P.

The composite transform is then M = PV. A point s (sw=1) is transformed into t as t=Ms.

t may have tw ≠ 1 due to perspective projection.

All components in t are divided by tw in order to obtain a point u with uw = 1.

Page 40: Advanced Computer Graphics  Spring 2014

40

View Frustum Intersection(Frustum Plane Extraction)

For points inside the view frustum, it holds that -1≤ui≤1 for i∈ x,y,z, i.e. the point u is inside a unit cube.

For the right side of the left plane of the unit-cube, for which -1 ≤ ux. -1 ≤ ux <-> -1 ≤ tx/tw <-> tx + tw ≥ 0 <-> (m0, ᆞ s) + (m3ᆞ s) ≥ 0 <-> (m0, + m3,)ᆞ s ≥ 0.

The last equation denotes a plane equation of the left plane of the view frustum. The left plane in the unit-cube has been

transformed back to world coordinates.

Page 41: Advanced Computer Graphics  Spring 2014

41

View Frustum Intersection(Frustum Plane Extraction)

All the planes are