Added noise

This commit is contained in:
connor committed 2026-10-16 15:05:04 -04:00
1 parent 970551b4e1
commit 1ed95982ad
14 files changed
+687 -22

No files matched your search

+11 -2
View File
@@ -59,14 +59,21 @@ struct RenderArgs {
lighting: LightingTier,
/// Camera fidelity tier: C0, or C1 (adds pixels that collect light over their area,
/// for graded edges and continuous thin parts, lens distortion, lens blur, and the
/// Sun, Moon and Earth where light time and aberration make them appear, and at
/// lighting L1 stars).
/// Sun, Moon and Earth where light time and aberration make them appear, detector
/// noise, and at lighting L1 stars).
#[arg(long, default_value = "C0")]
camera: CameraTier,
/// From camera C1: render each pixel as N x N finer ones (1 to 4; default 2), which
/// the lens blur then acts on before they are averaged into the pixel.
#[arg(long, value_name = "N")]
supersampling: Option<u32>,
/// From camera C1: the seed of the detector's noise.
#[arg(long, default_value_t = 0)]
seed: u64,
/// From camera C1: the frame number the noise is drawn for; the same seed and frame
/// give the same image.
#[arg(long, default_value_t = 0)]
frame: u64,
/// Device: auto, gpu, cpu, or part of an adapter's name.
#[arg(long, default_value = "auto")]
adapter: String,
@@ -221,6 +228,7 @@ fn render(args: &RenderArgs) -> Result<(), String> {
dn_in_place: None,
supersampling: args.supersampling,
stars,
noise_seed: args.seed,
};
let start = Instant::now();
let mut renderer = Renderer::new(camera, options).map_err(|e| e.to_string())?;
@@ -236,6 +244,7 @@ fn render(args: &RenderArgs) -> Result<(), String> {
let mut frame = None;
for _ in 0..timings.unwrap_or(1).max(1) {
let start = Instant::now();
renderer.set_frame_number(args.frame);
let rendered = renderer
.submit(&scene, &observer)
.and_then(|p| p.wait())
+18 -1
View File
@@ -68,6 +68,12 @@ pub struct CameraFile {
pub bias: Option<f64>,
pub full_well: Option<f64>,
pub adc_bits: Option<u32>,
/// From camera C1: read noise in electrons RMS.
pub read_noise: Option<f64>,
/// From camera C1: dark current in electrons per second.
pub dark_current: Option<f64>,
/// From camera C1: whether the electrons collected carry shot noise.
pub shot_noise: Option<bool>,
/// The Gaussian blur's sigma in pixels, from camera C1: one for every channel, one
/// per channel, or 0 for none.
pub psf_sigma: Option<Sigma>,
@@ -163,6 +169,11 @@ impl SceneFile {
if let Some(bits) = c.adc_bits {
camera.detector.adc_bits = bits;
}
set(&mut camera.detector.read_noise, c.read_noise);
set(&mut camera.detector.dark_current, c.dark_current);
if let Some(shot) = c.shot_noise {
camera.detector.shot_noise = shot;
}
if let Some([u, v]) = c.principal_point {
camera.principal_point = Some(Vector2::new(u, v));
}
@@ -441,13 +452,19 @@ mod tests {
#[test]
fn camera_overrides_apply() {
let file: SceneFile = toml::from_str(&format!(
"{MINIMAL}\n[camera]\nwidth = 640\nexposure = 2e-3\nadc_bits = 10\n"
"{MINIMAL}\n[camera]\nwidth = 640\nexposure = 2e-3\nadc_bits = 10\nread_noise = 2.5\n\
dark_current = 0\nshot_noise = false\n"
))
.unwrap();
let camera = file.camera();
assert_eq!((camera.width, camera.height), (640, 1080));
assert_eq!(camera.exposure, 2e-3);
assert_eq!(camera.detector.adc_bits, 10);
let d = camera.detector;
assert_eq!(
(d.read_noise, d.dark_current, d.shot_noise),
(2.5, 0.0, false)
);
for (line, psf) in [
(