9. フォトンマッピング

フォトンマッピング(photon mapping)は、光の反射や屈折により生じる集光などを表現するこができる技術である。これを使うと、虫めがねやガラスコップを通過する光の様子などをリアルに表現できる。フォトンマッピングは光源からフォトン(光子)を大量に飛ばしその行先を追跡することで、光のリアルな映像表現を実現している。

フォトンマッピングの設定には次の3つがある。

グローバルなフォトン設定 グローバル設定におけるフォトン設定は、放たれるフォトンの数やフォトン収集範囲や数など、フォトンマッピング全体に関係することを設定する。
物体のフォトン設定 物体におけるフォトン設定では、集光模様を生じさせる原因となる物体を設定したりするなど、各物体に対するフォトンマッピングを設定する。
光源のフォトン設定 光源におけるフォトン設定では、フォトンが発射される光源を設定する。

※ フォトンマッピングを使用するにはこれらの3つの設定を適切に行う。

※ フォトン設定にはいろいろなパラメータがある。フォトンマッピングの計算は時間がかかるため、そのパラメータの多くは時間短縮のためのものが多い。高画質設定にすると計算時間が長くなる。

※ インテリア機能にある光の分散についても、フォトンマッピングの利用で正確な表現が可能になっている。(光がガラスを透過し集光している様子の簡易的な表現であれば、メディアの中のインテリア機能だけでも表現できる。)


9.1 グローバルなフォトン設定

< photons の構文/グローバル設定 >

global_settings { photons { spacing PHOTON_SPACING | count PHOTONS_TO_SHOOT [ gather MIN_GATHER, MAX_GATHER ] [ media MAX_STEPS [, FACTOR ] ] [ jitter JITTER_AMOUNT ] [ max_trace_level PHOTON_TRACE_LEVEL ] [ adc_bailout PHTON_ADC_BAILOUT ] [ save_file "filename" | load_file "filename" ] [ autostop AUTOSTOP_FRACTION ] [ expand_thresholds PERCENT_INCREASE, EXPAND_MIN ] [ radius GATHER_RADIUS, MULTIPLIER, GATHER_RADIUS_MEDIA, MULTIPLIER ] } }
photons フォトンマッピングのキーワード(グローバル設定)
spacing PHOTON_SPACING フォトン間の距離を設定 ▷「9.1-1 フォトン間隔」参照
count PHOTONS_TO_SHOOT フォトン数の設定 ▷「9.1-2 フォトン数」参照
gather MIN_GATHER, MAX_GATHER 各点で収集するフォトンの最大値と最小値を設定、最小値、最大値を整数で設定する。通常は変更の必要なし。[デフォルト:20,100 ]
media MAX_STEPS [, FACTOR] メディアに対してフォトンを有効にする。MAX_STEPSは、区間あたりに割り当てられるフォトンの最大値の設定である。FACTORは通常のspacingとの比であり、メディアのspacingとなる。[デフォルト:0 ]
jitter JITTER_AMOUNT サンプリングで使用されるゆらぎの量を設定、通常は設定不要 [デフォルト:0.4 ]
max_trace_level PHOTON_TRACE_LEVEL フォトンの最大反射・屈折回数の設定 [デフォルト:5 ] ▷「4.7 max_trace_level」参照
adc_bailout PHTON_ADC_BAILOUT 反射・屈折計算の精度の設定 [デフォルト:1/255 ](約0.0039) ▷「4.1 ADC_bailout」参照
save_file "filename" フォトンマップを設定名でファイルに保存、load_file と同時に使用できない。
load_file "filename" フォトンマップを設定ファイルから読み込む、save_file と同時に使用できない。
autostop AUTOSTOP_FRACTION フォトンの発射の自動停止。設定された割合(0.0~1.0)のフォトンが標的物体に全く当たらないとき、フォトン発射を中止する。1つでも当たるとこの機能は解除される。
expand_thresholds PERCENT_INCREASE, EXPAND_MIN より正確にフォトンを収集するための収集半径の増加割合PERCENT_INCREASE(20%がディフォルト)、この値でもあまりフォトンを収集できないとEXPAND_MIN(40%がディフォルト)で再収集を行う。
radius GATHER_RADIUS, MULTIPLIER, GATHER_RADIUS_MEDIA, MULTIPLIER フォトンの収集半径と半径調整用の乗数、メディア用のフォトンの収集半径と半径調整用の乗数の設定をする。省略すると、この値は自動設定される。

spacing count はどちらか一方を必ず使用する。同時に両方使用すると、count の設定が使われる。両方とも使用しないとエラーになる。

load_file を使用するとフォトンマップが読込まれフォトンマップの作成済みの状態になり、フォトンの発射は全く行われないことに注意する。

※ すべてのフォトンの最終密度を大体同じにするということが重要である。ある部分で高密度のフォトンを使用し、他の部分で低密度なフォトンを使用すると、望ましくない斑点模様が発生したりする。また、フォトン密度に大きい相違があると、シーンのレンダリングに大変な時間がかかる原因になったりする。

※ 各パラメータの設定値により画質が決まる。設定値により計算時間は大幅に異なる。このため計算時間を考慮すると、最適な設定はシーンや目的画質により異なってくる。


9.1-1 フォトン間隔(spacing)

発射されるフォトン間のおおよその距離を設定する。間隔が短いほどたくさんのフォトンが生成される。この設定により生成フォトン数が異なってくる。一般的にフォトン数が多いと高画質になるが計算時間が長くなる。

(a) potons { spacing 0.01 }
(b) potons { spacing 0.1 }
図9.1-1 フォトン間隔(spacing)による集光の違い

上図は、フォトン間隔(フォトン数)による違いを示している。右の図はフォトンの数が少ないため集光部分が乱れており、周辺に斑点のような薄い模様が発生している。

//-------------- Fig. 9.1-1a spacing 0.01 //-------------- Fig. 9.1-1b spacing 0.1 #version 3.7 #include "colors.inc" #include "textures.inc" global_settings { assumed_gamma 2.2 photons { spacing 0.01 // <<<----- fig. 9.1-1 (a) // spacing 0.1 // <<<----- fig. 9.1-1 (b) } } //---------------------camera & light camera{ location< 5,-18,10> sky<0,0,1> right <-image_width/image_height,0,0> look_at<1.5,0,0.8> angle 46 } light_source {<-30,20,40>, color White*1.8 } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } } //-------------------ground plane {z, 0 pigment {color rgb<0.65,0.5,0.4>} } //----------------------object sphere{<0,0,3.2> 3 material{M_Glass3} photons { target collect off reflection on refraction on } }


9.1-2 フォトン数(count)

生成するフォトン数を設定する。フォトンが透明体に衝突すると2つに分かれるため、総フォトン数はこの設定値と一致するとは限らない。一般的にフォトン数が多いと高画質になるが計算時間が長くなる。

(a) potons { count 200000 }
(b) potons { count 10000 }
図9.1-2 フォトン数(count)による集光の違い

上図は、フォトン数(フォトン間隔)の違いを示している。右の図はフォトンの数が少ないため集光模様がぼやけている。

//--------------- Fig. 9.1-2a count 200000 //--------------- Fig. 9.1-2b count 10000 #version 3.7 #include "colors.inc" #include "textures.inc" #include "metals.inc" global_settings { assumed_gamma 2.2 photons { count 200000 // <<<------ Fig. 9.1-2 (a) // count 10000 // <<<------ Fig. 9.1-2 (b) } } //---------------------camera & light camera{ location<10,-15,15> sky<0,0,1> right <-image_width/image_height,0,0> look_at<0,0,0> angle 46 } light_source {<30, 20, 40>, color White*1.5 } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } } //-------------------ground plane {z, 0 pigment {color rgb<0.5,0.6,0.4>*1.5} } //----------------------object cylinder{<0,0,0>,<0,0,2>,5 open texture { T_Gold_1A } photons { target collect off reflection on } }


9.2 物体のフォトン設定

< photons の構文/物体設定 >

object{ photons { [ target [SPACING_MULTIPLIER ] ] [ refraction on|off ] [ reflection on|off ] [ collect on|off ] [ pass_through ] } }
photons
フォトンマッピングのキーワード(物体)
target [SPAACING_MULTIPLIER] フォトンを発射の目標となる物体の設定。SPAACING_MULTIPLIERは物体に対するフォトン密度調節を行う。0.5であれば、フォトン間隔は他の物体の1/2となる。▷「9.2-1 目標物体」参照
refraction on|off 屈折を有効にするスイッチ(その物体に衝突したフォトンが屈折するかしないかの設定) [デフォルト:off ] ▷「9.2-2 物体フォトン屈折」
reflection on|off 反射を有効にするスイッチ(その物体に衝突したフォトンが反射するかしないかの設定) [デフォルト:off ]
collect on|off 物体にフォトンの収集を指示するスイッチ [デフォルト:on ] ▷「9.2-3 フォトン収集」参照
pass_through 物体にフォトンが通り抜けることを指示するスイッチ

※ 目標物体でなければ、通常この物体にフォトン文を記述する必要はない。しかし、フォトンが衝突しないと思われる物体には、correct off を使用し、フォトンの収集をしないようにすると計算時間が速くなる。

※ 透明体(ガラス)の物体には、通常 correct off を使用する。

※ 物体と光源のフォトン設定に同じパラメータ(反射と屈折のスイッチ)がある。その物体とその光源のフォトンの振る舞いは次のように解釈される。

物体と光源ともに記述なし▷ off 設定となる。
物体に on|off の記述、光源は記述なし▷ その物体の設定に従う。
物体は記述なし、光源に on|off の記述▷ その光源の設定に従う。
物体と光源の on|off の記述が一致▷ その設定に従う。
物体と光源の on|off の記述が不一致 ▷ off 設定となる。
 


9.2-1 目標物体(target)

フォトンが発射される目標となる物体を設定する。設定されることでその物体に対してフォトンが放たれ、その結果、集光模様が発生したりする。この設定がないと、その物体に対してフォトンが発射されない。

次の図9.2.1の画像は、target記述の有無による違いである。左側の画像では両方のリングに target を記述している。右側の画像では、リングに記述なしの場合である。ずいぶん様子が異なることがわかる。

(a) 2つのリング target 記述
(b) 2つのリング target 記述無し
図9.2-1 目標物体(target)の有無よる集光の違い

//-------------------- Fig. 9.2-1a taget //-------------------- Fig. 9.2-1b no taget // Fig. 9.2-1b target : comment out #version 3.7 #include "colors.inc" #include "metals.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.01} } //---------------------camera & light camera{ location< 5,18,18> sky<0,0,1> right <-image_width/image_height,0,0> look_at<0,0,1> angle 46 } light_source {<-30, 20, 40>, color White*1.3 } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } } //-------------------ground plane {z, 0 pigment {color rgb<0.5,0.6,0.4>*1.5} } //================================= object cylinder{<-2,0,0>,<-2,0,2>,5 open texture { T_Gold_1A} photons { // target // <<<-----------------target collect off reflection on } } cylinder{<2,0,0>,<2,0,2>,5 open texture { T_Gold_1A} photons { // target // <<<-------------------target collect off reflection on } }


9.2-2 フォトンの反射・屈折(reflection・refraction)

その物体に衝突したフォトンが反射や屈折するかしないかの設定をする。このスイッチは、鏡面・透明の場合にのみ意味がある。ディフォルトは off である。物体にこのスイッチを記述していない場合は、光源のフォトン反射や屈折スイッチの記述があればその設定に従う。

(a)反射・屈折(有り)
reflection on / refraction on
(b)反射・屈折(無し)
reflection off / refraction off
又は 記述省略
図9.2-2 反射と屈折の有無よる光の違い

上図9.2-2は反射・屈折のスイッチによる違いを表した。ガラスの球では、フォトンによる光の集光の様子を示し、鏡面の直方体では反射光の様子を示した。

//------------------------ Fig. 9.2-2a on // glass sphere : reflection refraction // box : reflection #version 3.7 #include "colors.inc" #include "textures.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.01 } } //---------------------camera & light camera{ location< 5,-18,15> sky<0,0,1> right <-image_width/image_height,0,0> look_at<3,10,0.8> angle 48 } light_source {<-30,-20,40>, color White*1.3 } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } } //-------------------ground plane {z, 0 pigment {color rgb<0.5,0.65,0.4>} } //============================= object sphere{<0,0,3.2> 3 material{M_Glass3} photons { target collect off reflection on // <<<-----Fig. 9.2-2a on refraction on // <<<-----Fig. 9.2-2a on } } box{0,1 scale <15,2,7> pigment{White*0.5} finish{reflection 0.7} translate <-5,10,0> photons { target collect off reflection on // <<<------Fig. 9.2-2a on } }
//------------------------ Fig. 9.2-2b off // glass sphere : reflection refraction // box : reflection #version 3.7 #include "colors.inc" #include "textures.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.01 } } //---------------------camera & light camera{ location< 5,-18,15> sky<0,0,1> right <-image_width/image_height,0,0> look_at<3,10,0.8> angle 48 } light_source {<-30,-20,40>, color White*1.3 } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } } //-------------------ground plane {z, 0 pigment {color rgb<0.5,0.65,0.4>} } //================================ object sphere{<0,0,3.2> 3 material{M_Glass3} photons { target collect off // reflection on // <<<-----Fig. 9.2-2b off // refraction on // <<<-----Fig. 9.2-2b off } } box{0,1 scale <15,2,7> pigment{White*0.5} finish{reflection 0.7} translate <-5,10,0> photons { target collect off // reflection on // <<<------Fig. 9.2-2b off } }


9.2-3 フォトン収集(collect)

その物体が、輝度計算のためのフォトンを収集するかしないかの設定をする。ディフォルトは on である。一般的には目標物体(target)の設定をしたときは、off でよい。目標物体でない他の物体にこの記述をすると、フォトンの収集を行わないため、その物体上に集光模様は表れなくなる。

次の図9.2-4の画像は、2つの直方体の上にリングが乗っている。左側の画像は直方体にフォトン文を記述していない通常の場合のものである。右側の画像では、手前の直方体にはフォトン文で collect off が設定されておりフォトンの収集が行われなかった。このためリング反射光が表現されていない。

(a) 両ボード ollect on
(b) 前側のボード collect off
図9.2-3 フォトン収集(collect)よる集光の違い

//-------------------- Fig. 9.2-3 correct #version 3.7 #include "colors.inc" #include "textures.inc" #include "metals.inc" #include "Woods.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.01} } //---------------------camera & light camera{ location< 5,18,16> sky<0,0,1> right <-image_width/image_height,0,0> look_at<0.5,1,1> angle 46 } light_source {<-30, 20, 40>, color White*1.5 } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } } //-------------------ground plane {z, -2 pigment {color rgb<0.5,0.6,0.4>*1.5} } //----------------------object cylinder{<0,0,0>,<0,0,2>,5 open texture { T_Gold_1A} photons { target collect off reflection on refraction on } } //============================================ object box{<-8,-8,-2><8,-2.5,0> texture {T_Wood7 rotate y*90 scale 5} } box{<-8,-2,-2><8,3,0> texture {T_Wood13 rotate y*90 scale 15} photons { collect on //----------Fig. 9.2-3a // collect off //----------Fig. 9.2-3b } }


9.3 光源のフォトン設定

< photons の構文/光源設定 >

light_source { photons { [ refraction on | off ] [ reflection on | off ] [ area_light ] } }
photons フォトンマッピングのキーワード(光源)
refraction on|off 屈折を有効にするスイッチ(その光源から放たれるフォトンが、屈折する性質を持つか持たないかの設定) [デフォルト:off ]
reflection on|off 反射を有効にするスイッチ(その光源から放たれるフォトンが、反射する性質を持つか持たないかの設定) [デフォルト:off ]
area_light 面光源を使用したときに記述する。面光源を使用してもこの設定がないと点光源として取り扱われる。 ▷「9.3-1 面光源」参照

※ 通常の場合、目標物体に refraction on や reflection on の記述をするので、光源にフォトン文を記述する必要はない。(面光源のみ例外的に記述が必要)特定の光源からのフォトン発射を中止したい場合に、refraction off やreflection off などを記述する。

※ 物体と光源のフォトン設定に同じパラメータ(反射と屈折のスイッチ)がある。その物体とその光源のフォトンの振る舞いは次のように解釈される。

物体と光源ともに記述なし▷ off 設定となる。
物体に on|off の記述、光源は記述なし▷ その物体の設定に従う。
物体は記述なし、光源に on|off の記述▷ その光源の設定に従う。
物体と光源の on|off の記述が一致▷ その設定に従う。
物体と光源の on|off の記述が不一致 ▷ off 設定となる。
 


9.3-1 面光源(area_light)

照明に面光源を使用した場合のフォトンマッピングについて示す。Pov-Rayでは面光源は点光源の集合体として取り扱われる。面光源の設定に使用される点光源の数を多くしたほどリアルな陰影が表現できる。

〇 グローバル設定 spacing 0.1
  (a) 光源設定 面光源 3x3の点光源
  (b) 光源設定 面光源 10x10の点光源
〇 グローバル設定 spacing 0.01
  (c) 光源設定 面光源 3x3の点光源
  (d) 光源設定 面光源 10x10の点光源

(a) spacing 0.1/面光源 3x3

(b) spacing 0.1/面光源 10x10

(c) spacing 0.01/面光源 3x3

(d) spacing 0.01/面光源 10x10

図9.3-1 フォトンの密度と面光源の組み合わせ

上記の例では、(d)が最も高画質になる。高画質にするためには、フォトンをより大量に放出し面光源に多くの点高原を使用すればよいが、計算時間の増大を招くので、適切に設定する必要がある。

//-------------------- Fig. 9.3-1a #version 3.7 #include "colors.inc" #include "metals.inc" #include "textures.inc" #include "Woods.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.1 } // <<<----------Fig. 9.3-1a } //---------------------camera & light camera { location < 8,15, 16> sky <0,0,1> right <-image_width/image_height,0,0> look_at < 6, -4, 0> angle 60 } //=========================== area light light_source { <-30,20,35> color White area_light<20,0,0>,<0,20,0> 3,3 // <<<---Fig. 9.3-1a jitter photons { area_light } } //=========================== object 1 cylinder{<0,0,0>,<0,0,2>, 4.5 open texture{ T_Gold_4B} photons{ target collect off reflection on } } //=========================== object 2 sphere{<10,2,3.2>, 3 material{M_Glass3} photons{ target collect off reflection on refraction on } } //=========================== object 3 box{-3, 3 texture{T_Wood7 scale 4 } scale <0.8,0.8,1> translate<5,-9,3> } //-------------------ground plane{z 0 pigment {color rgb<0.7,1,0.7>*1.5} } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } }
//-------------------- Fig. 9.3-1b #version 3.7 #include "colors.inc" #include "metals.inc" #include "textures.inc" #include "Woods.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.1 } //-----------Fig. 9.3-1b } //---------------------camera & light camera { location < 8,15, 16> sky <0,0,1> right <-image_width/image_height,0,0> look_at < 6, -4, 0> angle 60 } //=========================== area light light_source { <-30,20,35> color White area_light<20,0,0>,<0,20,0> 10,10 // <<<---Fig. 9.3-b jitter photons { area_light } } //=========================== object 1 cylinder{<0,0,0>,<0,0,2>, 4.5 open texture{ T_Gold_4B} photons{ target collect off reflection on } } //=========================== object 2 sphere{<10,2,3.2>, 3 material{M_Glass3} photons{ target collect off reflection on refraction on } } //=========================== object 3 box{-3, 3 texture{T_Wood7 scale 4 } scale <0.8,0.8,1> translate<5,-9,3> } //-------------------ground plane{z 0 pigment {color rgb<0.7,1,0.7>*1.5} } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } }
//-------------------- Fig. 9.3-1c #version 3.7 #include "colors.inc" #include "metals.inc" #include "textures.inc" #include "Woods.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.01 } //-----------Fig. 9.3-1c } //---------------------camera & light camera { location < 8,15, 16> sky <0,0,1> right <-image_width/image_height,0,0> look_at < 6, -4, 0> angle 60 } //=========================== area light light_source { <-30,20,35> color White area_light<20,0,0>,<0,20,0> 3,3 // <<<---Fig. 9.3-1c jitter photons { area_light } } //=========================== object 1 cylinder{<0,0,0>,<0,0,2>, 4.5 open texture{ T_Gold_4B} photons{ target collect off reflection on } } //=========================== object 2 sphere{<10,2,3.2>, 3 material{M_Glass3} photons{ target collect off reflection on refraction on } } //=========================== object 3 box{-3, 3 texture{T_Wood7 scale 4 } scale <0.8,0.8,1> translate<5,-9,3> } //-------------------ground plane{z 0 pigment {color rgb<0.7,1,0.7>*1.5} } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } }
//-------------------- Fig. 9.3-1d #version 3.7 #include "colors.inc" #include "metals.inc" #include "textures.inc" #include "Woods.inc" global_settings { assumed_gamma 2.2 photons {spacing 0.01 } //-----------Fig. 9.3-1d } //---------------------camera & light camera { location < 8,15, 16> sky <0,0,1> right <-image_width/image_height,0,0> look_at < 6, -4, 0> angle 60 } //=========================== area light light_source { <-30,20,35> color White area_light<20,0,0>,<0,20,0> 10,10 //<<<---Fig. 9.3-1d jitter photons { area_light } } //=========================== object 1 cylinder{<0,0,0>,<0,0,2>, 4.5 open texture{ T_Gold_4B} photons{ target collect off reflection on } } //=========================== object 2 sphere{<10,2,3.2>, 3 material{M_Glass3} photons{ target collect off reflection on refraction on } } //=========================== object 3 box{-3, 3 texture{T_Wood7 scale 4 } scale <0.8,0.8,1> translate<5,-9,3> } //-------------------ground plane{z 0 pigment {color rgb<0.7,1,0.7>*1.5} } //---------------------sky sky_sphere{ pigment{ wrinkles color_map{ [ 0.3 color rgb<0.3,0.4,1.2>] [ 0.9 White ] } scale <1, 0.2, 0.2> } }


(End) 9.フォトンマッピング