@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
126 lines (108 loc) • 5.32 kB
JavaScript
import { compute_mie_particle_properties_rgb } from "./compute_mie_particle_properties_rgb.js";
import { ri_air } from "./ri_air.js";
import { ri_ammonium_sulfate } from "./ri_ammonium_sulfate.js";
import { ri_brine } from "./ri_brine.js";
import { ri_dust } from "./ri_dust.js";
import { ri_pollen } from "./ri_pollen.js";
import { ri_smoke } from "./ri_smoke.js";
import { ri_soot } from "./ri_soot.js";
import { ri_water } from "./ri_water.js";
/**
* Helper function to build a standard particle definition.
* Assumes the medium is air (n=1.0).
* Computes the spectrally-averaged RGB Mie properties.
* @param {number} diameter_m (in meters)
* @param {function(result:number[], wavelength:number):number[]} refraction refraction [n, k] - Complex refractive index of the particle. (n=real, k=imaginary)
*/
function make(diameter_m, refraction){
const radius = diameter_m * 0.5;
// perform the full spectral sweep (380nm-780nm) and integrate against sRGB CMFs.
const mie = compute_mie_particle_properties_rgb(
radius,
refraction,
ri_air,
);
return {
diameter: diameter_m,
radius,
particle_refraction: refraction,
cross_section_scattering: mie.scattering_coefficients, // [R_sca, G_sca, B_sca]
cross_section_extinction: mie.extinction_coefficients, // [R_ext, G_ext, B_ext]
extinction_intercept: mie.extinction_intercept,
g: mie.g,
albedo: mie.albedo,
}
}
// TODO we can pre-compute these, as integration can be a little time intense
/**
* 📚 A standard library of common atmospheric particles for use in rendering.
*
* This list provides physically-based, wavelength-dependent presets.
*
* Note: the medium is Air.
* @enum
*/
export const MIE_PARTICLES_STANDARD = {
// --- 💧 Water-Based (Haze, Fog, Clouds) ---
/**
* Continental haze (ammonium sulfate surrogate)
* SMALL — faint land/city haze: distant skyline slightly washed out on a sunny day.
*/
CONTINENTAL_HAZE_SMALL: make(0.1e-6, ri_ammonium_sulfate), // 100 nm
/** MEDIUM — typical daytime urban/valley haze with gentle desaturation. */
CONTINENTAL_HAZE_MEDIUM: make(0.5e-6, ri_ammonium_sulfate), // 500 nm
/** LARGE — thicker land haze; think post‑inversion murk softening hills. */
CONTINENTAL_HAZE_LARGE: make(1.0e-6, ri_ammonium_sulfate), // 1.0 µm
/**
* Maritime haze (sea‑salt/brine)
* SMALL — light coastal humidity haze over the ocean.
*/
MARITIME_HAZE_SMALL: make(0.1e-6, ri_brine), // 100 nm
/** MEDIUM — bright, milky air on a breezy beach or around harbors. */
MARITIME_HAZE_MEDIUM: make(0.5e-6, ri_brine), // 500 nm
/** LARGE — thick marine layer look before it becomes fog. */
MARITIME_HAZE_LARGE: make(1.0e-6, ri_brine), // 1.0 µm
/** Larger droplets that create classic white fog and clouds */
/** SMALL — light mist: dawn over a lake, waterfall spray, breath fog. */
FOG_DROPLET_SMALL: make(2.0e-6, ri_water), // 2.0 µm
/** MEDIUM — typical road fog reducing visibility to a few hundred meters. */
FOG_DROPLET_MEDIUM: make(10.0e-6, ri_water), // 10.0 µm
/** LARGE — bright, thick cloud core or dense sea fog. */
CLOUD_DROPLET_LARGE: make(20.0e-6, ri_water), // 20.0 µm
// --- 🔥 Combustion (Smoke & Soot) ---
/**
* Biomass Smoke (e.g., Wood, Wildfire) — "Brown Carbon"
* SMALL — fresh wood‑smoke right above the flames.
*/
SMOKE_PARTICLE_SMALL: make(0.4e-6, ri_smoke), // 400 nm
/** MEDIUM — typical wildfire/chimney smoke drifting across a valley. */
SMOKE_PARTICLE_MEDIUM: make(0.8e-6, ri_smoke), // 800 nm
/** LARGE — aged regional smoke layers that turn the sun orange. */
SMOKE_PARTICLE_LARGE: make(2e-6, ri_smoke), // 2000 nm
/**
* Soot (e.g., Diesel Exhaust) — "Black Carbon"
* SMALL — very dark sooty exhaust: candle wick zone or fresh tailpipe soot.
*/
SOOT_PARTICLE_SMALL: make(0.05e-6, ri_soot), // 50 nm (Primary particle)
/** MEDIUM — traffic/industrial pollution haze mixing into city air. */
SOOT_AGGREGATE_MEDIUM: make(0.2e-6, ri_soot), // 200 nm (Clumped)
/** LARGE — heavy dirty smoke near source: burning oil/tires. */
SOOT_AGGREGATE_LARGE: make(0.4e-6, ri_soot), // 400 nm (Clumped)
// --- 💨 Solid Particulates (Dust & Pollen) ---
/**
* Mineral Dust (e.g., Desert, Sand)
* SMALL — far‑range dusty air softening distant mountains.
*/
FINE_DUST_SMALL: make(1.5e-6, ri_dust), // 1.5 µm
/** MEDIUM — moving dust clouds from vehicles or field winds. */
COARSE_DUST_MEDIUM: make(5.0e-6, ri_dust), // 5.0 µm
/** LARGE — sandstorm wall: near‑camera blowing sand/tan curtains. */
COARSE_DUST_LARGE: make(15.0e-6, ri_dust), // 15.0 µm
/**
* Pollen (Organic)
* MEDIUM — seasonal pollen haze; yellow‑green tint in spring air.
*/
POLLEN_PARTICLE_MEDIUM: make(20.0e-6, ri_pollen), // 20.0 µm
/** LARGE — visible puffs from trees (e.g., pine) or catkins in forests. */
POLLEN_PARTICLE_LARGE: make(30.0e-6, ri_pollen), // 30.0 µm
}