Initial Commit
This commit is contained in:
64 files changed
+13419
No files matched your search
@@ -0,0 +1,157 @@
|
||||
#! Contains `photometry`: light as an eye sees it, in the units lights are named
|
||||
#! by, and converted between them, so a game's lights are given as real ones
|
||||
#! are: a bulb by its lumens, the sun by the lux it lights the ground with, the
|
||||
#! sky by its luminance, and a camera by its exposure value.
|
||||
#!
|
||||
#! ```
|
||||
#! lumens lm luminous flux: all the light a source gives, every way at once, as a bulb is sold by
|
||||
#! candela cd, lm/sr luminous intensity: the light a source gives one way, in each steradian of it
|
||||
#! lux lx, lm/m² illuminance: the light falling on a surface, as a meter on it reads
|
||||
#! nits cd/m² luminance: the light a surface gives back toward an eye, or a sky gives
|
||||
#! EV100 exposure value at ISO 100: how a camera is set for a scene's light, each step twice the light
|
||||
#! ```
|
||||
#!
|
||||
#! Angles are radians, and a cone's angle is its half, from its axis to its
|
||||
#! edge, as glTF's spot lights give theirs.
|
||||
|
||||
import std::math;
|
||||
module malunal::photometry;
|
||||
|
||||
# π, as the `f32` nearest it.
|
||||
const pi: f32 = 3.14159265;
|
||||
|
||||
#! The solid angle of a cone, in steradians: 2π(1 - cos angle), of its angle
|
||||
#! from its axis to its edge. Of π, it's a sphere's, 4π.
|
||||
pub def solid_angle_of(angle: f32): f32 {
|
||||
return 2 * pi * (1 - math::cos(angle));
|
||||
}
|
||||
|
||||
#! The candela of a light giving so many lumens within a cone, alike every way
|
||||
#! within it: its lumens over the cone's solid angle. Of the angle left out, π,
|
||||
#! it shines every way, as a bare bulb does, so it's its lumens over 4π; of a
|
||||
#! narrower cone, its light is gathered into it, as a torch's reflector gathers
|
||||
#! its bulb's, and it's brighter each way.
|
||||
pub def candela_of_lumens(flux: f32, angle: f32 = pi): f32 {
|
||||
return flux / solid_angle_of(angle);
|
||||
}
|
||||
|
||||
#! The lumens of a light of so many candela within a cone, alike every way
|
||||
#! within it, or every way, of the angle left out.
|
||||
pub def lumens_of_candela(intensity: f32, angle: f32 = pi): f32 {
|
||||
return intensity * solid_angle_of(angle);
|
||||
}
|
||||
|
||||
#! The lumens of a lamp drawing so many watts, of how many lumens each watt of
|
||||
#! its kind gives, as `efficacy` names them.
|
||||
pub def lumens_of_watts(power: f32, lumens_per_watt: f32): f32 {
|
||||
return power * lumens_per_watt;
|
||||
}
|
||||
|
||||
#! The watts a lamp of so many lumens draws, of how many lumens each watt of
|
||||
#! its kind gives.
|
||||
pub def watts_of_lumens(flux: f32, lumens_per_watt: f32): f32 {
|
||||
return flux / lumens_per_watt;
|
||||
}
|
||||
|
||||
#! The lux a light of so many candela gives a surface so far from it, facing
|
||||
#! it: its candela over the square of the distance. A surface turned from it is
|
||||
#! given the cosine of the angle as much.
|
||||
pub def lux_of_candela(intensity: f32, distance: f32): f32 {
|
||||
return intensity / (distance * distance);
|
||||
}
|
||||
|
||||
#! How far from a light of so many candela a surface facing it is given so many
|
||||
#! lux: the square root of its candela over them, as far as it lights as much
|
||||
#! as is seen.
|
||||
pub def distance_of_lux(intensity: f32, illuminance: f32): f32 {
|
||||
return math::sqrt(intensity / illuminance);
|
||||
}
|
||||
|
||||
#! The nits a matte surface lit by so many lux gives back, every way alike, of
|
||||
#! the fraction of what falls on it it gives back: what falls on it, by that
|
||||
#! fraction, over π. White gives back all of it, and an 18% grey card, a
|
||||
#! photograph's middle grey, 0.18.
|
||||
pub def nits_of_lux(illuminance: f32, reflectance: f32 = 1): f32 {
|
||||
return illuminance * reflectance / pi;
|
||||
}
|
||||
|
||||
#! The lux lighting a matte surface that gives back so many nits, of the
|
||||
#! fraction of what falls on it it gives back: π times its nits, over that
|
||||
#! fraction. Of the fraction left out, it's the lux a sky of so many nits, alike
|
||||
#! every way, lights the ground with.
|
||||
pub def lux_of_nits(luminance: f32, reflectance: f32 = 1): f32 {
|
||||
return luminance * pi / reflectance;
|
||||
}
|
||||
|
||||
#! Illuminances, in lux, of the ground or a floor, about as each is lit.
|
||||
pub struct lux {}
|
||||
|
||||
#! A moonless, overcast night, lit by starlight.
|
||||
pub const lux::starlight: f32 = 0.0001;
|
||||
#! A moonless clear night, lit by the sky's own glow.
|
||||
pub const lux::moonless_night: f32 = 0.002;
|
||||
#! A full moon on a clear night.
|
||||
pub const lux::full_moon: f32 = 0.2;
|
||||
#! The end of civil twilight, under a clear sky.
|
||||
pub const lux::twilight: f32 = 3.4;
|
||||
#! A family's living room.
|
||||
pub const lux::living_room: f32 = 50;
|
||||
#! An office building's hallway.
|
||||
pub const lux::hallway: f32 = 80;
|
||||
#! A very dark overcast day.
|
||||
pub const lux::dark_overcast: f32 = 100;
|
||||
#! An office's desks.
|
||||
pub const lux::office: f32 = 400;
|
||||
#! Sunrise or sunset on a clear day.
|
||||
pub const lux::sunrise: f32 = 400;
|
||||
#! An overcast day.
|
||||
pub const lux::overcast: f32 = 1000;
|
||||
#! Full daylight, out of the sun.
|
||||
pub const lux::daylight: f32 = 20000;
|
||||
#! Direct sunlight, at noon.
|
||||
pub const lux::direct_sunlight: f32 = 100000;
|
||||
|
||||
#! Luminances, in nits, about as each is seen.
|
||||
pub struct nits {}
|
||||
|
||||
#! The sky of a clear day, out of the sun, which lights the ground with about
|
||||
#! 22,000 lux.
|
||||
pub const nits::clear_sky: f32 = 7000;
|
||||
|
||||
#! Luminous fluxes, in lumens, about as each is sold or burns.
|
||||
pub struct lumens {}
|
||||
|
||||
#! A candle, of a candela every way.
|
||||
pub const lumens::candle: f32 = 12.566371;
|
||||
#! A bulb as bright as a 40-watt incandescent bulb, as LED bulbs are sold.
|
||||
pub const lumens::bulb_40w: f32 = 450;
|
||||
#! As bright as a 60-watt incandescent bulb.
|
||||
pub const lumens::bulb_60w: f32 = 800;
|
||||
#! As bright as a 75-watt incandescent bulb.
|
||||
pub const lumens::bulb_75w: f32 = 1100;
|
||||
#! As bright as a 100-watt incandescent bulb.
|
||||
pub const lumens::bulb_100w: f32 = 1600;
|
||||
|
||||
#! Luminous intensities, in candela.
|
||||
pub struct candela {}
|
||||
|
||||
#! A candle's, every way, which the candela was first named for.
|
||||
pub const candela::candle: f32 = 1;
|
||||
|
||||
#! How many lumens each watt a lamp draws gives, by its kind, about, as
|
||||
#! `lumens_of_watts` takes them.
|
||||
pub struct efficacy {}
|
||||
|
||||
#! The most a watt gives, as green light of 555 nm, by which the lumen is
|
||||
#! defined.
|
||||
pub const efficacy::most: f32 = 683;
|
||||
#! An incandescent bulb's.
|
||||
pub const efficacy::incandescent: f32 = 14;
|
||||
#! A halogen bulb's.
|
||||
pub const efficacy::halogen: f32 = 20;
|
||||
#! A compact fluorescent bulb's.
|
||||
pub const efficacy::fluorescent: f32 = 60;
|
||||
#! A white LED's.
|
||||
pub const efficacy::led: f32 = 100;
|
||||
#! Sunlight's, of each watt of it falling on the ground.
|
||||
pub const efficacy::sunlight: f32 = 93;
|
||||
Reference in new issue
Block a user