• 沒有找到結果。

Shape interface

N/A
N/A
Protected

Academic year: 2022

Share "Shape interface"

Copied!
34
0
0

加載中.... (立即查看全文)

全文

(1)

Shapes

Digital Image Synthesis Yung-Yu Chuang

9/27/2005

with slides by Pat Hanrahan

(2)

Shapes

• Shape: raw geometry properties of the primitive

• Primitive=Shape+Material

• Source code in core/shape.* and shapes/*

• pbrt provides the following shape plug-ins:

– quadrics: sphere, cone, cylinder, disk, hyperboloid, paraboloid (surface described by quadratic

polynomials in x, y, z) – triangle mesh

– height field – NURBS

– Loop subdivision surface

(3)

Shape

class Shape : public ReferenceCounted { public:

<Shape Interface>

const Transform ObjectToWorld, WorldToObject;

const bool reverseOrientation, transformSwapsHandedness;

}

• All shapes are defined in object coordinate space

(4)

Shape interface

• BBox ObjectBound(;

• BBox WorldBound() { (can be overridden)

return ObjectToWorld(ObjectBound());

}

• bool CanIntersect() returns whether this shape can do intersection test; if not, the shape must provide

void Refine(vector<Reference<Shape>>&refined)

• bool Intersect(const Ray &ray,

float *tHit, DifferentialGeometry *dg)

• bool IntersectP(const Ray &ray)

(5)

Shape interface

• float Area()

• void GetShadingGeometry(

const Transform &obj2world,

const DifferentialGeometry &dg, DifferentialGeometry *dgShading)

• No back culling for that it doesn’t save much for ray tracing and it is not physically correct

for object instancing

(6)

Surfaces

• Implicit: F(x,y,z)=0

you can check

• Explicit: (x(u,v),y(u,v),z(u,v)) you can enumerate

• Quadric

[ ]

0

1

1 =

⎥⎥

⎥⎥

⎢⎢

⎢⎢

⎥⎥

⎥⎥

⎢⎢

⎢⎢

z y x

J I

G D

I H

F C

G F

E B

D C

B A

z y

x

(7)

Sphere

• A sphere of radius r at the origin

• Implicit: x2+y2+z2-r2=0

• Parametric: f(θ,ψ) x=rsinθcosψ

y=rsinθsinψ z=rcosθ

mapping f(u,v) over [0,1]2 ψ=uψmax

θ=θmax+v(θmaxmax)

(8)

Sphere

(9)

Sphere (construction)

class Sphere: public Shape {

……

private:

float radius;

float phiMax;

float zmin, zmax;

float thetaMin, thetaMax;

}

Sphere(const Transform &o2w, bool ro,

float rad, float zmin, float zmax, float phiMax);

• Bounding box for sphere, only z clipping

(10)

Algebraic solution

• Perform in object space, WorldToObject(r, &ray)

• Assume that ray is normalized for a while

2 2

2

2 y z r

x + + =

(

ox + tdx

)

2 +

(

oy + tdy

)

2 +

(

oz + tdz

)

2 = r2

2 + Bt + C = 0 At

2 2

2

z y

x d d

d

A = + +

) (

2 dxox dyoy dzoz

B = + +

2 2

2

2 o o r

o

C = x + y + z

Step 1

(11)

Algebraic solution

A

AC B

t B

2

2 4

0

=

A

AC B

t B

2

2 4

1

+

=

If (B2-4AC<0) then the ray misses the sphere

Step 2

Step 3

Calculate t0 and test if t0<0

Step 4

Calculate t1 and test if t1<0

(12)

Geometric solution

1. Origin inside? ox2 + o2y + oz2 > r2

(13)

Geometric solution

2. find the closest point, t=-O‧D if t<0 and O outside return false

t

t

(14)

Geometric solution

3. find the distance to the origin, d2=O2-t2 if s2=r2-d2<0 return false;

t

r

r d

O

s

(15)

Geometric solution

4. calculate intersection distance, if (origin outside) then t-s

else t+s

t

r

d

O

s

t

r d

O s

(16)

Sphere intersection

• Use algebraic solution, why?

• Consider numeric stability

(17)

Partial sphere

• Have to test sphere intersection against clipping parameters

• Partial derivatives

• Area

) 0 , ,

( max y max x u

p = φ φ

) sin ,

sin ,

cos )(

(θmax θmin z φ z φ r θ v

p =

) ( max min

max r z z

A = φ

(18)

Cylinder φ

max

φ = u

φ cos r

x =

φ sin r

y =

) (

max min

min

v z z

z

z = + −

(19)

Cylinder

(20)

Cylinder (intersection)

2 2

2 y r

x + =

(

ox + tdx

)

2 +

(

oy + tdy

)

2 = r2

2 + Bt + C = 0 At

2 2

y

x d

d

A = +

) (

2 dxox dyoy

B = +

2 2

2 o r

o

C = x + y

(21)

Disk φ

max

φ = u

φ cos )

) 1

(( v r vr x = −

i

+

h z =

φ sin )

) 1

(( v r vr

y = −

i

+

(22)

Disk

(23)

Disk (intersection)

h-Oz

h t

Dz D z h Oz

t D

D

=

)

( z

z

O D h

t = D

z z

D O h D

t'= t =

(24)

Other quadrics

(25)

Triangle mesh

The most commonly used shape. In pbrt, it can be supplied by users or tessellated from other shapes.

(26)

Triangle mesh

class TriangleMesh : public Shape {

int ntris, nverts;

int *vertexIndex;

Point *p;

Normal *n;

Vector *s;

float *uvs;

}

x,y,z x,y,z x,y,z x,y,z x,y,z vi[3*i]

vi[3*i+1]

vi[3*i+2]

p

Note that p is stored in world space to save transformations. n and s are in object space.

(27)

Triangle mesh

• ObjectBound and WorldBound

Void TriangleMesh::Refine(vector<Reference<Shape>>

&refined) {

for (int i = 0; i < ntris; ++i)

refined.push_back(new Triangle(ObjectToWorld, reverseOrientation, (TriangleMesh *)this, i));

}

(28)

1. Intersect ray with plane

2. Check if point is inside triangle

Ray triangle intersection

(29)

Algebraic Method 0

:

: 0

= +

+

=

d N

P Plane

tV P

P Ray

Substituting for P, we get:

(

P0 + tV

)

N + d = 0

Solution:

( )

(

V NN

)

d

t P

+

= − 0

tV P

P =

0

+

Ray plane intersection

(30)

Algebraic Method

( )

( )

FALSE return

d N

P if

N P

d

N Normalize

V V

N

P T

V

P T

V

1 0

1 1 0

1

1 1 2

1

2 2

1 1

<

+

=

×

=

=

=

For each side of triangle:

end

Ray triangle intersection I

(31)

Parametric Method

( ) ( )

( ) ( )

triangle inside

is P then

and if

T T

T T

P

Compute

0 . 1 0

. 0 0

. 1 0

. 0

: ,

1 3

1 2

− +

=

β α

β α

β α

Ray triangle intersection II

(32)

Ray triangle intersection III

(33)

Fast minimum storage intersection

2 1

)

0

1

( u v V uV vV tD

O + = − − + + 1

and

0

, vu + vu

[

1 0 2 0

] O V

0

v u t V

V V

V

D = −

⎥ ⎥

⎢ ⎢

(34)

Fast minimum storage intersection

0 1

1

V V

E = − E

2

= V

2

V

0

T = OV

0

E

2

D

P = × Q = T × E

1

⎥ ⎥

⎢ ⎢

= ⋅

⎥ ⎥

⎢ ⎢

D Q

T P

E Q

E v P

u

t

2

1

1

參考文獻

相關文件

But for double integrals, we want to be able to integrate a function f not just over rectangles but also over regions D of more general shape, such as the one illustrated in

Partial Volume Segmentation with Voxel Histograms; Higher Order Statistics for Tissue Segmentation; III Quantification; Two-dimensional Shape and Texture

• The solution to Schrödinger’s equation for the hydrogen atom yields a set of wave functions called orbitals..  Each orbital has a characteristic shape

If the bootstrap distribution of a statistic shows a normal shape and small bias, we can get a confidence interval for the parameter by using the boot- strap standard error and

• How social media shape our relationship to and understanding of breaking news events. – How do we know if information shared on social media

 Retrieval performance of different texture features according to the number of relevant images retrieved at various scopes using Corel Photo galleries. # of top

• How social media shape our relationship to and understanding of breaking news events. – How do we know if information shared on social media

For HSK: If a test taker is late and the listening test has not begun, test takers can enter the test room and take the test; if a test taker is late and the listening test has