光源

VRMLで定義できる光源は次の3種類である。


平行光源   点光源   スポットライト


(1)平行光源(平行な光線)、無限遠点からの光

【文法】
DirectionalLight {
 color        光の色(R G B で指定)
 intensity      光の強さ(0〜1)
 ambientIntensity 環境光の強さ(0〜1) (光の当たっていない部分も光る)
 direction      光の方向 (X Y Z 値で指定)、原点からこの方向に光が照射される
 on           光を出すかどうか(TRUE又はFALSE) 
}

【例】

#VRML V2.0 utf8
DirectionalLight {
  color 1 0 0
  intensity 1.0
  ambientIntensity 1.0
  direction 0 -1 0
  on TRUE
}
Transform{
  translation 0.0 -2.5 0.0
  children[
    Shape {
      geometry Box {
        size 1.0, 1.0, 1.0
      }
      appearance Appearance {
        material Material {
          diffuseColor 1.0 1.0 1.0
        }
      }
    }
  ]
}


実行例


(2)点光源(全ての方向に等しく光を放つ光源)、白熱電灯など

【文法】
PointLight {
 location       光源の位置(X Y Z)
 color         光の色(R G B で指定)
 intensity       光の強さ(0〜1)
 ambientIntensity  環境光の強さ(0〜1) (光の当たっていない部分も光る)
 attenuation     光の減衰率(※参照)
 on           光を出すかどうか(TRUE又はFALSE) 
}

【例】

#VRML V2.0 utf8
PointLight {
  location  2.0 2.0 0.0
  color 1.0 0.0 0.0
  intensity 1.0
  ambientIntensity 1.0
  attenuation 1.0 0.5 0.1
  on TRUE
}
Transform{
  translation 0.0 -2.5 0.0
  children[
    Shape {
      geometry Box {
        size 1.0, 1.0, 1.0
      }
      appearance Appearance {
        material Material {
          diffuseColor 1.0 1.0 1.0
        }
      }
    }
  ]
}

※光の減衰率
   a1 a2 a3、光源との距離を r とすると、明るさは 1 / (a1 + a2* r + a3 * r2) となる。


実行例


(3)スポットライト

【文法】
SpotLight {
 location        光源の位置(X Y Z)
 color         光の色(R G B で指定)
 intensity      光の強さ(0〜1)
 ambientIntensity 環境光の強さ(0〜1) (光の当たっていない部分も光る)
 attenuation     光の減衰率(※参照)
 beamWidth      光の広がり角度(ラジアン) (0〜π/2)
 direction      光の方向 (原点からの向きをX Y Zで指定)
 on           光を出すかどうか(TRUE又はFALSE)
}

【例】

#VRML V2.0 utf8
SpotLight {
  location  2.0 2.0 0.0
  color 1.0 0.0 0.0
  intensity 1.0
  ambientIntensity 1.0
  attenuation 1.0 0.5 0.1
  beamWidth 0.1
  direction -0.2 -2.0 0.0
  on TRUE
}
Transform{
  translation 0.0 -2.5 0.0
  children[
    Shape {
      geometry Box {
        size 1.0, 1.0, 1.0
      }
      appearance Appearance {
        material Material {
          diffuseColor 1.0 1.0 1.0
        }
      }
    }
  ]
}

※光の減衰率
   a1 a2 a3、光源との距離を r とすると、明るさは 1 / (a1 + a2* r + a3 * r2) となる。

実行例