• 検索結果がありません。

1 1 F 1 D 1 F D 8 a b c d E a b E c d 4 A 4 A B B EF DE 9 7-5/ /4 D 11 1 FA 9 AB B 7 5

N/A
N/A
Protected

Academic year: 2021

シェア "1 1 F 1 D 1 F D 8 a b c d E a b E c d 4 A 4 A B B EF DE 9 7-5/ /4 D 11 1 FA 9 AB B 7 5"

Copied!
12
0
0

読み込み中.... (全文を見る)

全文

(1)

コンピュータグラフィックス特論

(ビジュアルコンピューティング論)

(エンターテインメントテクノロジー研究Ⅱ)

Hidden surface removal

T. Nishita

CG画像生成パイプライン

„

画像生成過程

CG画像生成パイプライン

„

画像生成過程

代表的方法

• Z-Buffer法

• Zソート法

• スキャンライン法

• レイトレーシング法

Zバッファ法

• Zバッファを無限遠で初期化 • 各ポリゴンについて – 透視変換 – 各画素(i,j)について • Z値の計算 • If(z < zbuff(i,j) )

– 描画 – Zbuff(i,j) = z • ほとんどのハードに搭載 • ポリゴンならどんな場合もOK

Depth Buffer法(Z-buffer法)

CG-ARTS

(2)

2 4 6 8 10 12 2 4 6 8 10 12 14 16 A B C D E F a b c d -5/2 0 1 2 3 4 5 7 6 8 9 10 11 7 9 11 7 6/4 λ 11 13 0 λ λ λ λ λ λ λ 9 2 0 3 7 5 76/4 λ EF DE CD FA AB BC Yma x Xmi n 1/ m λ λ λ 2 4 6 8 10 12 2 4 6 8 10 12 14 16 A B C D E F a b c d 0 2 9 9 2 FA EF AET -5/2 Scan line 9 6/4 10 11 DE 11 13CD0 λ Scan line 10 6/4 12 11 11 13 DE CD AET 0 λ

走査変換の方法

奥行きの計算

曲面のzバッファ法

スキャンライン法

• 全てのポリゴンを透視

変換

• 各スキャンラインにつ

いて

– スキャンライン平面と ポリゴンの交線算出 – 陰線消去して描画

• 一次元の問題に帰着

• ポリゴンなら

どんな場

合もOK

曲面のスキャンライン法

曲面の再分割近似法

曲面を独立に処理するために発生する隙間 曲面の近似

(3)

Zソート法

• 全てのポリゴンについて (例えば)重心位置のZ値 を計算 • Z値の大きい順にソート • 各ポリゴンについて – 透視変換 – 描画(各画素の内容を上 書き) • 単純だがうまくいかない 場合がある

Zソート法;Depth Sort法

(painter’s algorithm

)

• 物体を視点からの距離にしたがってsortする

• 遠い物体から順に重ね書きをする

• 距離によるsortが可能であれば,きわめて高

• 遠景,中景,近景がはっきりしているときに有

優先順位アルゴリズム

サイクリックな優先順位 問題が生じる場合

優先順位アルゴリズム

クラスタ間の優先順位の決定 クラスタ間の優先順位の決定 BSP(Binary Space-Partitioning)法と呼ばれる

レイトレーシング法

• 各画素について

– 視線を算出 – 視線と全物体の交点 計算 – 視点に最も近い交点 を算出 – 描画

• ポリゴンでなくともよい

• 反射/屈折を表現

• 一般には,とても遅い

レイトレーシング法(光線追跡法)

(4)

光線追跡法の特徴

• 計算量が多い → 高速化

• algorithmがsimple

• 不必要な光線は追跡しない

• 重要性の少ない光線の追跡が多い

for すべてのpixel P do Pと視点Vを通る直線をLとする; for すべての物体O do LとOの交点を求める; if ひとつでも交点があった then 視点にもっとも近い交点をIとする; Iと光源Sとの間に他の物体がある then PにOの色+環境光をぬる else Iにshadingの計算を行い, Pにその色をぬる else Pに背景色をぬる;

影の表示

CG-ARTS

光線追跡法

CG-ARTS

Ray Tree

光の反射

(5)

反射光・屈折光の追跡

I V Q P N T S R R N T T+R T+R=2N(N・T) R=2N(N・T)-T

主な物体の屈折率

空気 1.00 水 1.33 ガラス 1.5∼1.7 ダイヤ 2.42

追跡打ち切りの基準

• 交点がなかった

• 拡散反射面にぶつかった

• 強さが一定のしきい値以下になった

• 反射回数が一定のしきい値以上になった

(6)

光線追跡法の高速化

• hardwareによる方法

– 並列computerの利用

• algorithmの工夫による方法

– bounding volume法 → 交点計算1回あたりの

平均時間削減

– 空間分割法 → 交点計算の回数削減

Bounding Volume法

CG-ARTS

空間分割法

CG-ARTS

領域細分アルゴリズム

長方形領域への分割例 ウィンドウと多角形の関係

Ray Casting

•A simple form of Ray Tracing

View plane Eye position Simplest method is ray casting Simplest method is ray casting Rays through view plane

(7)

Ray Casting

• To create each sample …

– Construct ray from eye position through view plane – Find first surface intersected by ray through pixel – Compute color sample based on surface radiance

Ray Casting

• For each sample …

– Construct ray from

eye position through

view plane

– Find first surface

intersected by ray

through pixel

– Compute color

sample based on

surface radiance

Samples on view plane Eye position Rays through view plane

Ray Casting

• Simple implementation:

Image RayCast(Camera camera, Scene scene, int width, int height) {

Image image = new Image(width, height); for (int i = 0; i < width; i++) {

for (int j = 0; j < height; j++) {

Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit);

} } return image; }

Image RayCast(Camera camera, Scene scene, int width, int height) {

Image image = new Image(width, height); for (int i = 0; i < width; i++) {

for (int j = 0; j < height; j++) {

Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit);

} } return image; }

Constructing

Ray

Through a Pixel

right back Up direction P0 towards View Plane P V Ray: P = P0+ tV Ray: P = P0+ tV

Constructing Ray Through a

Pixel

• 2D Example

d Θ towards P0 right right = towards x up Θ = frustum half-angle d = distance to view plane

P1 = P0+ d*towards – d*tan(Θ)*right P2 = P0+ d*towards + d*tan(Θ)*right P1 P2 2*d*t an (Θ) P P = P1 + (i/width + 0.5) * (P2 - P1) = P1 + (i/width + 0.5) * 2*d*tan (Θ)*right V = (P - P0) / ||P - P0|| V Ray: P = P0+ tV Ray:P = P0+ tV

Ray Casting

• Simple implementation:

Image RayCast(Camera camera, Scene scene, int width, int height) {

Image image = new Image(width, height); for (int i = 0; i < width; i++) {

for (int j = 0; j < height; j++) {

Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit);

} } return image; }

Image RayCast(Camera camera, Scene scene, int width, int height) {

Image image = new Image(width, height); for (int i = 0; i < width; i++) {

for (int j = 0; j < height; j++) {

Ray ray = ConstructRayThroughPixel(camera, i, j);

Intersection hit = FindIntersection(ray, scene);

image[i][j] = GetColor(hit); }

} return image; }

(8)

Ray-Scene Intersection

• Intersections with geometric primitives

– Sphere

– Triangle

– Groups of primitives (scene)

光線と球との交点

• 球の表現:

– 球の中心: – 球の半径:

• 直線の表現:

– ピクセル: – 視点: 0 ) ( ) ( ) ( 2+ 2+ 2 2= r z z y y x x C C C Q Q P L Q Q P L Q Q P L z t z z t z y t y y t y x t x x t x Q t Q P tP Q t t L + − = + − = + − = + − = + − = ) ( ) ( , ) ( ) ( , ) ( ) ( ) ( ) 1 ( ) (          ) , , (xC yC zC C= r ) , , (xP yP zP P= ) , , (xQ yQ zQ Q=

球面の式に直線の式を代入

{

} {

}

{

}

{

}

{

}

{

( ) ( ) ( )

}

0 ) )( ( ) )( ( ) )( ( 2 ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ≡ − − + − + − + − − + − − + − − + − + − + − = − − + − + − + − + − + − = − − + − + − r z z y y x x t z z z z y y y y x x x x t z z y y x x r z z t z z y y t y y x x t x x r z z y y x x C Q C Q C Q C Q Q P C Q Q P C Q Q P Q P Q P Q P C Q Q P C Q Q P C Q Q P C C C         

2次方程式の係数

αγ

β

αγ

β

γ

β

α

γ

β

α

=

=

+

+

=

+

+

=

+

+

=

=

+

+

2 2 2 2 2 2 2 2 2 2

)

2

/

(

'

4

,

)

(

)

(

)

(

)},

)(

(

)

)(

(

)

)(

{(

2

,

)

(

)

(

)

(

0

D

D

r

z

z

y

y

x

x

z

z

z

z

y

y

y

y

x

x

x

x

z

z

y

y

x

x

t

t

C Q C Q C Q C Q Q P C Q Q P C Q Q P Q P Q P Q P

 あるいは 

     

交点の算出

• D<0 のときは交点なし.D≧0 のときは交

わる.

• 交わるとき,2次方程式の解を t

1

,t

2

とする

と,L(t

1

), L(t

2

) が交点.

• 視点に近い交点は小さい方の解に対応す

る.

α αγ β β 2 4 2 − − = t

別解; 光線と球との交点

Ray-Sphere Intersection(1)

Ray: P = P0+ tV Sphere: |P - C|2- r 2 = 0 P0 V C P r P’

(9)

Ray-Sphere Intersection (2)

Ray: P = P0+ tV

Sphere: |P - C|2- r 2 = 0

Substituting for P, we get: |P0+ tV - C|2- r 2 = 0

Solve quadratic equation: at2+ bt + c = 0 where: a = |V|2= 1 b = 2 V • (P0- C) c = |P0- C|2- r 2 P = P0+ tV P0 V C P r P’ If ray direction is normalized!

Ray-Sphere Intersection (3)

P0 V C P r

N = (P - C) / ||P - C||

N

• Need normal vector at intersection

for lighting calculations

Ray-Triangle Intersection

• First, intersect ray with plane

• Then, check if point is inside triangle

P P0 V

Ray-Plane Intersection

Ray: P = P0+ tV Plane: P • N + d = 0

Substituting for P, we get: (P0+ tV) • N + d = 0 Solution: t = -(P0• N + d) / (V • N) N P P0 V P = P0+ tV

Ray-Triangle Intersectio

• Check if point is inside triangle

parametrically

P

P Compute α, β:

P = α (T2-T1) + β (T3-T1)

Check if point inside triangle. 0 ≤ α ≤ 1 and 0 ≤ β ≤ 1 α + β ≤ 1 V α β T1 T2 T3

Other Ray-Primitive Intersections

• Cone, cylinder, ellipsoid:

– Similar to sphere

• Box

– Intersect 3 front-facing planes, return closest

• Convex polygon

– Same as triangle (check point-in-polygon algebraically)

• Concave polygon

– Same plane intersection

(10)

Bezier Clipping

1.0 -2.0 -4.0 0.0 2.0 4.0 6.0 f (1, -3) (2/3, -4) (1/3, 6) (0, 2) max t (b) after clipping -2.0 -4.0 0.0 2.0 4.0 6.0 f 2/3 1/3 t min t 2/3 1/3 1.0t

Σ

=

f

k=0

B

3

f

k 3 k

(t )

(t )

f0 f2 f1 f3 24x3-42x2+12x+2= 0

f(x)=

(i/n,fk):control point

t max-tmin 1st; 0.5555 2nd; 0.0083 3rd; 0.0003 (a) original

Bezier Clipping

(multiple roots)

(1/3, 6) f f1 -2.0 -4.0 0.0 2.0 4.0 6.0 f 1.0 2/3 1/3 t 1.0t -2.0 -4.0 0.0 2.0 4.0 6.0 f t=1/2

java applet

Curve-Line intersection

Σ

=

f

k=0

B

3

f

k 3 k

(t )

(t)

Σ

=

x

k=0

B

3

x

k 3 k

(t )

(t)

Σ

=

y

k=0

B

3

y

k 3 k

(t )

(t)

d(x,y)=ax+by+c fk=axk+byk+c curve P0 P1 P2 P3 f1 f2 f3 f0 line -2.0 -4.0 0.0 2.0 4.0 6.0 f (1, -3) (1/3, 6) (0, 2) max t min t 2/3 1/3 1.0 f0 f f1 t

Curve/curve Intersection

Fat line P Q Q P

(a) clip Q by Fatline of P (b) clip P by Fatline of Q

Applications to 3D Rendering

parametric surfaces

・hidden surface removal ・hidden line removal

- raytracing - scan line algorithm

implicit surfaces

implicit surfaces

raytracing

rendering curved surfaces

rendering curved surfaces

Bezier Patch, B-spline, NURBS

algebraic surface

metaball

(blobs)

x=x(u,v), y=y(u,v), z=z(u,v)

f(x,y,z) = 0

Previous work for parametric patches

Raytracing

Raytracing

Whitted(1980): bicubic patches

subdivision approach

Kajiya(1982): bicubic patches

numerical solution

Nishita(1990):trimmed rational Bezier patches Bezier clipping

Scanline algorithm

Scanline algorithm

Lane(1980): subdivision of curved surface into polygons at every scan line

Nishita(1991):modification of Lane's method (subdivision into subpatches at every scan line)

(11)

Raytracing for Trimmed Patchs

x

y (x,y) v

(u,v)

screen parametric domain

trimmed patch

ray/patch intersection for bicubic patch;

degree 18 of polynominal should be solved

u 0 Lv V‚P u Lu 6 ‚V 10 V0 8 9 v 1 P02 d02 d22 P20 P00 P22 d00 -2 2 7 6 5 -8 -9 -10 0 d um ax um in -1 1 u ( a ) ( b )

Bezier Clipping for Bezier Patch

x u v w x B u B v w B u B v i ijij j i j i ij j i j ( , ) ( ) ( ) ( ) ( ) == = = = ∑ ∑ ∑ ∑ 0 3 0 3 3 3 0 3 0 3 3 3 y u v w y B u B v w B u B v i ijij j i j i ij j i j ( , ) ( ) ( ) ( ) ( ) == = = = ∑ ∑ ∑ ∑ 0 3 0 3 3 3 0 3 0 3 3 3 L x yu( , )=a xu +b yu d u vu d B u B v i ij j i j ( , )= ( ) ( ) = = ∑ ∑ 0 3 0 3 3 3 d u vu d B u B v i ij j i j ( , )= ( ) ( ) = = ∑ ∑ 0 3 0 3 3 3 dij=a xu ij+b yu ij

Line

Surface

Bezier Clipping for Bezier Patch

f u umin umax f01 f02 f00 f11 f10 f12 f20 f21 f22 0.5 1.0 P u v umin umax

Extract intervals

Iterative clipping

Raytracing

using Bezier Clipping

Scan Line Algorithm for Bezier

Patches

scan line

subpatch

Lane(1980): subdivision of curved surface into polygons at every scan line

scan line

Nishita(1991): subdivision into subpatches at

Scanline algorithm

using Bezier Clipping

(12)

Metaball

Modeling of curved surfaces

Modeling of curved surfaces

metaballs; Nishimura(1985)

blobs; Blinn(1980)

P P 1 2

isosurface

degree six field function

problem: ray/isosurface intersection

Metaball

r

:density

q

T

:threshold

1 P 2 f(r) Ri 0.0 1.0 T Pi Ri r r

f

=

Σ

i i=0 n

(

x,y,z

)

q

i

f

−T

=0

:density

q

T

:threshold

isosurface f(0)=1, f '(0)=0, f(Ri)=0, f '(Ri)=0, f(Ri/2)=1/2

degree six field function;

f(0)=1, f '(0)=0, f(Ri)=0, f '(Ri)=0, f(Ri/2)=1/2

degree six field function;

curved surfaces defined by

curved surfaces defined by

metaballs

metaballs

:density

q

:threshold

T

Intersection Test between Ray and

Metaball

f f1 d0 d1 d3 d4 d5 d6 0 T -A B C t viewpoint t isosurface d2 2 f P1 P 2

only one intersection point closest to viewpoint is required

=0

=d

d

0 1

=d =d

5 6

+5)

(8

d

3

=

a

i 2

45

a

i

16

27

=d

d

2 4

=

a

i 2

Σ

=

(s

i

f

i i k=0

)

B

6

d

k 6 k

(s

i

)

計算時間の比較

Rendering法の比較

Z-buffer 法 scan line 法 光線追跡法

速 度 やや速 速 遅

memory 量 多 少 少

手 順 単純 複雑 単純

反射・屈折 困難 困難 容易

参照

関連したドキュメント

また適切な音量で音が聞 こえる音響設備を常設設 備として備えている なお、常設設備の効果が適 切に得られない場合、クラ

[r]

世界的流行である以上、何をもって感染終息と判断するのか、現時点では予測がつかないと思われます。時限的、特例的措置とされても、かなりの長期間にわたり

* 施工手順 カッター目地 10mm

OFFI CI AL SCORE CERTI FI CATE GTEC (4技能) (CBT可). Test Repor t For m I ELTS™(Academi c

※ MSCI/S&amp;P GICSとは、スタン ダード&プアーズとMSCI Inc.が共 同で作成した世界産業分類基準 (Global Industry Classification

Visual Studio 2008、または Visual Studio 2010 で開発した要素モデルを Visual Studio

(2)