UnderwaterFogEffectDescクラスは、カメラと見えている物の間にある水で視界を曇らせる Descriptor です。各ピクセルの深度を読み、視線のうち水面より下の区間に指数関数フォグを積分し、水が散乱させる太陽光を足し、水面より上には何もしません。濃さは地図の面から水面までの水柱あたりで与えるので、2 m の浸水も 30 m の海も同じ数値で表せます。カメラが水面より上にある間、パスは止まります。
Properties
Section titled “Properties”visible
Section titled “visible”Type: boolean | undefined
Description: エフェクトの表示/非表示を制御します。visible に関わらず、カメラが水面より上にある間もパスは止まります。
Default: true
waterLevel
Section titled “waterLevel”Type: number | ((pos: LatLng) => number | undefined)
Description: 水面の位置を、楕円体高(メートル)で指定します。数値は水平な水面、関数は位置ごとの水面高を返し、水が無い場所では undefined を返します。毎フレーム、カメラの真下で評価されます。必須です。
Example:
{ underwaterFog: { waterLevel: 58, }}{ underwaterFog: { waterLevel: (pos) => floodLevelAt(pos), }}waterStrength
Section titled “waterStrength”Type: Vector3 | undefined
Description: 水柱全体を縦に横切った時の光学的深さを、チャンネル別(x 赤、y 緑、z 青)に指定します。光は水柱を通ると exp(-strength) 倍になるので、1.5 なら約 5 分の 1 が通ります。赤を青より強くすると澄んだ海水のように遠くが青緑に沈み、青を赤より強くすると濁ります。
Default: new Vector3(1.5, 1.5, 1.5)
Example:
{ underwaterFog: { waterStrength: new Vector3(2, 1.25, 0.9), }}waterFalloff
Section titled “waterFalloff”Type: number | undefined
Description: 水面に向かって水が薄くなる速さで、0 以上です。水面の密度は地図の面の exp(-waterFalloff) 倍になり、0 で一様になります。水柱全体の濃さは waterStrength のままです。
Default: 0
Example:
{ underwaterFog: { waterFalloff: 0.5, }}sunIntensity
Section titled “sunIntensity”Type: number | undefined
Description: 水がカメラへ散乱させる太陽光の強さを、空の光に対する比で指定します。0 で無効になります。太陽の方向は view.atmosphere に従い、空の光と太陽光はどちらも太陽の高度に従います。夜の水中では何も散乱せず、水は暗くなります。
Default: 1
Example:
{ underwaterFog: { sunIntensity: 2, }}phaseG
Section titled “phaseG”Type: number | undefined
Description: 水の散乱の Henyey-Greenstein 非対称パラメータです(-1 より大きく 1 未満)。水は前方散乱するので、0.7 から 0.9 で太陽の周りに明るい輪ができます。0 で等方になります。
Default: 0.8
Example:
{ underwaterFog: { phaseG: 0.6, }}bottomRatio
Section titled “bottomRatio”Type: number | undefined
Description: 底面の層が地図の面から占める、水柱の割合です。[0, 1] の範囲で指定します。
Default: 0.04
Example:
{ underwaterFog: { bottomRatio: 0.1, }}bottomStrength
Section titled “bottomStrength”Type: number | undefined
Description: 底面の層を縦に横切った時の光学的深さです。0 で地図はそのまま描かれ、上げると地面の上に泥の層ができます。
Default: 0
Example:
{ underwaterFog: { bottomStrength: 1, }}Type: Color | undefined
Description: 水が散乱させる光の色です。トーンマッピング前の光なので、view.toneMappingExposure が 10 の時は色を 10 で割ると指定どおりに見えます。
Default: new Color().setStyle("#2d7a86")
Example:
{ underwaterFog: { color: new Color().setStyle("#5a3f1c"), }}bottomColor
Section titled “bottomColor”Type: Color | undefined
Description: 底面の層が散乱させる光の色です。color と同じく、トーンマッピング前の光で、上にある水と底面の層で暗くなります。
Default: color
Example:
{ underwaterFog: { bottomColor: new Color().setStyle("#241808"), }}Performance
Section titled “Performance”- 1 ピクセルあたり固定 8 ステップの積分を行うフルスクリーン 1 パスです。コストはシーンやオプションに依存しません。
- カメラが水面より上にある間はパスが無効になり、コストはかかりません。
- カメラの真下の水位は 1 フレームに 1 回だけ解決されるので、
waterLevelに渡す関数は軽い物にしてください。
Usage Examples
Section titled “Usage Examples”街を水没させる
Section titled “街を水没させる”import ThreeView, { Color } from "@navaramap/three";import { UnderwaterFogEffectDesc } from "@navaramap/three-default-descs";import { DefaultPlugin, type DefaultDescriptions,} from "@navaramap/three-default-plugin";import { Vector3 } from "three";
const view = new ThreeView<DefaultDescriptions>();view.addPlugin(new DefaultPlugin());await view.init();
const STREET = 56; // 楕円体高(メートル)const level = STREET + 2;
// 浸水する街区const blocks = view.addSource({ type: "geojson", data: { type: "Feature", properties: null, geometry: { type: "Polygon", coordinates: [ [ [139.699, 35.661], [139.699, 35.658], [139.702, 35.658], [139.702, 35.661], [139.699, 35.661], ], ], }, },});
// 水面: 上面が水位になる薄い水のスラブview.addLayer({ type: "vector", source: blocks, polygon: { color: new Color().setStyle("#5a3f1c"), height: level - 0.2, extrudedHeight: 0.2, clampToGround: false, water: true, },});
// 濁った水: 泥が青から奪うので、遠くほど暖色に寄るview.addEffect<UnderwaterFogEffectDesc>({ underwaterFog: { waterLevel: level, waterStrength: new Vector3(0.7, 0.8, 1), waterFalloff: 0.5, color: new Color().setStyle("#5a3f1c"), },});水位を上げる
Section titled “水位を上げる”import ThreeView from "@navaramap/three";import { UnderwaterFogEffectDesc } from "@navaramap/three-default-descs";import { DefaultPlugin, type DefaultDescriptions,} from "@navaramap/three-default-plugin";
const view = new ThreeView<DefaultDescriptions>();view.addPlugin(new DefaultPlugin());await view.init();
const fog = view.addEffect<UnderwaterFogEffectDesc>({ underwaterFog: { waterLevel: 58 },});
// 水位がカメラの高さを越えた時点でフォグに入るfunction setWaterLevel(level: number) { fog.update({ underwaterFog: { waterLevel: level } });}データから水位を取る
Section titled “データから水位を取る”import ThreeView, { type LatLng } from "@navaramap/three";import { UnderwaterFogEffectDesc } from "@navaramap/three-default-descs";import { DefaultPlugin, type DefaultDescriptions,} from "@navaramap/three-default-plugin";
const view = new ThreeView<DefaultDescriptions>();view.addPlugin(new DefaultPlugin());await view.init();
// 浸水範囲と、その水面の楕円体高const FLOOD = { west: 139.699, east: 139.702, south: 35.658, north: 35.661 };const FLOOD_LEVEL = 58;const floodLevelAt = ({ lng, lat }: LatLng) => lng >= FLOOD.west && lng <= FLOOD.east && lat >= FLOOD.south && lat <= FLOOD.north ? FLOOD_LEVEL : undefined;
// 毎フレーム、カメラの真下について問われる。水が無ければ undefinedview.addEffect<UnderwaterFogEffectDesc>({ underwaterFog: { waterLevel: floodLevelAt, },});import ThreeView, { Color } from "@navaramap/three";import { UnderwaterFogEffectDesc } from "@navaramap/three-default-descs";import { DefaultPlugin, type DefaultDescriptions,} from "@navaramap/three-default-plugin";import { Vector3 } from "three";
const view = new ThreeView<DefaultDescriptions>();view.addPlugin(new DefaultPlugin());await view.init();
// 海面の楕円体高。ここではジオイド高const SEA_LEVEL = 36.7;
// 赤が先に消えるので、遠くほど青緑に沈むview.addEffect<UnderwaterFogEffectDesc>({ underwaterFog: { waterLevel: SEA_LEVEL, waterStrength: new Vector3(2, 1.25, 0.9), waterFalloff: 0.5, color: new Color().setStyle("#2d7a86"), },});- このエフェクトは水面を描きません。上面が水位になる水のポリゴン(
water: true)を足すと、水面を下から見られます。 - 1 フレームの全体に使う水位は、カメラの真下の 1 つだけです。視界の中で水位が変わる場所では、フォグはその水位の平面で終わります。カメラが水際の乾いた地面に立っている時、フォグは出ません。
- カメラは水面の 0.2 m 上で水から出ます。水面に乗ったカメラでパスが明滅しないためです。
- カメラの真下の地図の面は地形から取ります。水位が地形と同じかそれ以下の場所では、水は無い扱いです。地形レイヤーが無い場合と読み込み前は、水柱を 10 m と見なします。
- パスは transparent パスの前に走るので、透過メッシュはフォグの上に描かれます。
- SSR と FogLight、および Clouds エフェクトが無い時の SSAO と LensFlare も transparent パスの直前に置かれるので、追加した順に走ります。それらが描いた物も水でかすむように、このエフェクトはそれらの後に追加してください。