code wiki / (root) / nx_atmosphere.nx

nx_atmosphere.nx

buildroot/runtime/nx_atmosphere.nx

21973 B579 linesdepth 2pulls 4 transitivereach 297 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_atmosphere.nx -- atmospheric scattering math primitives. Per honest audit 2026-05-16: visual quality of a world depends on atmospheric depth, fog distribution, and sky color. This primitive ships substrate-native math for: - Per-body atmospheric coefficients (Rayleigh + Mie scaling) - Beer-Lambert extinction along a viewing distance - Sky color as a function of zenith + sun angles (Preetham-style) - Fog density as a function of altitude Used by the rasterizer (queued) and by atmospheric quality graders. genealogy_id: rayleigh_1871 + mie_1908 + preetham_1999_practical_sky + hosek_wilkie_2012_analytic_skylight lineage_id: nx_atmosphere_scattering_q14_v1

dependencies 4 imports · 93 importers

nx_syscalls.nx nx_itrig.nx nx_vecmath.nx nx_tier.nx nx_atmosphere.nx nx_atm_trans_gate.nx nx_atmsky_gate.nx nx_craft_before_placement_t316.nx nx_game_page_affine_candidate_t361 nx_game_page_authored_material_t54 nx_game_page_body_t138.nx nx_game_page_canonical_t135.nx nx_game_page_catwalk_lighting_cand nx_game_page_emit.nx nx_game_page_emit_sand_review.nx

diagram shows first 10 each side; +0 more imports, +83 more importers in the complete lists below.

imports: nx_syscalls.nxnx_itrig.nxnx_vecmath.nxnx_tier.nx

imported by: nx_atm_trans_gate.nxnx_atmsky_gate.nxnx_craft_before_placement_t316.nxnx_game_page_affine_candidate_t361.nxnx_game_page_authored_material_t54.nxnx_game_page_body_t138.nxnx_game_page_canonical_t135.nxnx_game_page_catwalk_lighting_candidate_t316.nxnx_game_page_emit.nxnx_game_page_emit_sand_review.nxnx_game_page_eye_t138.nxnx_game_page_gait_candidate_t139.nxnx_game_page_garment_t132.nxnx_game_page_gpu_timing_current_candidate.nxnx_game_page_gpu_timing_pool_candidate.nxnx_game_page_hair_attachment_candidate_t263.nxnx_game_page_hair_attachment_t283.nxnx_game_page_hair_guides_candidate_t263.nxnx_game_page_hair_t138.nxnx_game_page_host_candidate_t341.nxnx_game_page_identity_candidate.nxnx_game_page_imported_body_t45.nxnx_game_page_imported_t262.nxnx_game_page_inspection_distance_t235.nxnx_game_page_inspection_t142.nxnx_game_page_integrated_t73.nxnx_game_page_knight_bind_t25.nxnx_game_page_knight_feedback_t28.nxnx_game_page_knight_feedback_t29.nxnx_game_page_knight_support_t31.nxnx_game_page_knight_support_t31_before_t44.nxnx_game_page_length_diag_t140.nxnx_game_page_lit_candidate_t181.nxnx_game_page_material_body_t61.nxnx_game_page_material_candidate_t181.nxnx_game_page_material_compose_t55.nxnx_game_page_material_schema_candidate_t181.nxnx_game_page_metadata_candidate_t220.nxnx_game_page_mip_candidate_t241.nxnx_game_page_motion_candidate_t328.nxnx_game_page_motion_inventory_candidate_t330.nxnx_game_page_move_t72.nxnx_game_page_owned_candidate_t181.nxnx_game_page_pipeline_t64.nxnx_game_page_pre_inspection_t142.nxnx_game_page_pre_toon_region_t143.nxnx_game_page_procedural_review_candidate_t333.nxnx_game_page_recovery_feedback_t28.nxnx_game_page_recovery_t23.nxnx_game_page_rig_comparison_t332.nxnx_game_page_rig_inspection_t230.nxnx_game_page_rig_observation_candidate_t331.nxnx_game_page_scene_light_candidate_t364.nxnx_game_page_search_t53.nxnx_game_page_shared_candidate_t340.nxnx_game_page_skin_t138.nxnx_game_page_static_candidate_t338.nxnx_game_page_toon_region_candidate_t143.nxnx_game_page_visitors_inspection_t142.nxnx_game_page_visitors_t140.nxnx_game_page_workbench_candidate_t342.nxnx_game_page_workspace_body_t49.nxnx_game_page_workspace_body_t59.nxnx_game_page_workspace_t48.nxnx_movement_base_engine_t139.nxnx_movement_base_page_t139.nxnx_wasm_craft.nxnx_wasm_craft_body_t137.nxnx_wasm_craft_contact_candidate.nxnx_wasm_craft_dunes_t70.nxnx_wasm_craft_gait_candidate.nxnx_wasm_craft_gait_candidate_t139.nxnx_wasm_craft_imported_body_t41.nxnx_wasm_craft_imported_body_t42.nxnx_wasm_craft_imported_body_t49.nxnx_wasm_craft_imported_t262.nxnx_wasm_craft_inspection_bounds_t181.nxnx_wasm_craft_inspection_distance_t218.nxnx_wasm_craft_inspection_t142.nxnx_wasm_craft_journal_index_t21.nxnx_wasm_craft_journal_index_t21_before_t44.nxnx_wasm_craft_lookup_candidate.nxnx_wasm_craft_move_t72.nxnx_wasm_craft_pre_inspection_t142.nxnx_wasm_craft_recovery_t20.nxnx_wasm_craft_relief_adopt_t143.nxnx_wasm_craft_relief_save_t143.nxnx_wasm_craft_relief_t143.nxnx_wasm_craft_residency_t44.nxnx_wasm_craft_turn_candidate_t139.nxnx_wasm_craft_visitors_canonical_t142.nxnx_wasm_craft_visitors_inspection_t142.nxnx_wasm_craft_visitors_t140.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_atmosphere_rayleigh_q14 nx_atmosphere_mie_q14 _atm_exp_neg_q14 nx_atmosphere_extinction_q nx_atmosphere_rayleigh_q14 ↻ nx_atmosphere_mie_q14 ↻ _atm_exp_neg_q14 ↻ nx_atmosphere_fog_density_ nx_atmosphere_mie_q14 ↻ _atm_exp_neg_q14 ↻ sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ nx_atmosphere_sky_color_q1 nx_atm_airmass_q it_cos4096 it_sin4096 nx_atm_channel_q nx_atm_beta_permil _atm_exp_neg_q14 ↻

structs

none

consts

27const NX_EXPNEG_E1_Q14: i64 = 6029
28const NX_EXPNEG_E2_Q14: i64 = 2212
29const NX_T2_E1_LO_Q14: i64 = 5800
30const NX_T2_E1_HI_Q14: i64 = 6200
32const NX_ATM_Q: nx_int = 16384
45const NX_LAMBDA_R_NM: nx_int = 680
46const NX_LAMBDA_G_NM: nx_int = 550
47const NX_LAMBDA_B_NM: nx_int = 440
52const NX_AIRMASS_MAX: nx_int = 38
55const NX_TAU_BLUE_PERMIL: nx_int = 700
124const NX_BODY_SUN_LOCAL: nx_int = 0 // local alias for SUN
125const NX_BODY_MERCURY_LOCAL: nx_int = 1
126const NX_BODY_VENUS_LOCAL: nx_int = 2
127const NX_BODY_EARTH_LOCAL: nx_int = 3
128const NX_BODY_MARS_LOCAL: nx_int = 4
129const NX_BODY_TITAN_LOCAL: nx_int = 16
299const ATM_Q16: nx_int = 65536
301const ATM_RB_Q16: nx_int = 416808960 // 6360 km [bytes] both sources
303const ATM_RT_Q16: nx_int = 423362560 // 6460 km [bytes] hillaire (bruneton says 6420; divergence adopted+named in the spec)
305const ATM_PRO_Q16: nx_int = 655 // PLANET_RADIUS_OFFSET 0.01 km [bytes]
309const ATM_SRAY_R_Q24: nx_int = 97336
311const ATM_SRAY_G_Q24: nx_int = 227447
313const ATM_SRAY_B_Q24: nx_int = 555289
315const ATM_SMIE_EXT_Q24: nx_int = 74485
317const ATM_SOZ_R_Q24: nx_int = 10905
319const ATM_SOZ_G_Q24: nx_int = 31557
321const ATM_SOZ_B_Q24: nx_int = 1426
323const ATM_INV_HRAY_Q16: nx_int = 8192 // 1/(8 km) [bytes] scale height
325const ATM_INV_HMIE_Q16: nx_int = 54613 // 1/(1.2 km) [bytes]
329const ATM_OZ_SLOPE_Q16: nx_int = 4369
331const ATM_OZ_LO_Q16: nx_int = 43691
333const ATM_OZ_HI_Q16: nx_int = 174763
335const ATM_OZ_PEAK_KM_Q16: nx_int = 1638400 // 25 km
337const ATM_LOG2E_Q16: nx_int = 94548 // [derived] log2(e)*65536
339const ATM_LN2_Q16: nx_int = 45426 // [derived] ln(2)*65536
341const ATM_TRANS_SAMPLES: nx_int = 500 // [bytes] bruneton_functions trapezoid count
343const ATM_SUNLUT_N: nx_int = 64 // sun-zenith LUT rows emitted to the page (Q16 mu in [0,1])
345const ATM_POW32: nx_int = 4294967296

functions

60func nx_atm_beta_permil(lambda_nm: nx_int) -> nx_int
68func nx_atm_airmass_q(zenith_angle_q14: nx_int) -> nx_int
90func nx_atm_display_255(radiance_q: nx_int) -> nx_int
called by 3: mainwc_specwc_spec calls 1: vm_isqrt
104func nx_atm_channel_q(lambda_nm: nx_int, airmass_q: nx_int) -> nx_int
131func nx_atmosphere_rayleigh_q14(body_id: nx_int) -> nx_int
140func nx_atmosphere_mie_q14(body_id: nx_int) -> nx_int
153func _atm_exp_neg_q14(x_q14: nx_int) -> nx_int
179func nx_atmosphere_extinction_q14(
198func nx_atmosphere_fog_density_q14(
217func nx_atmosphere_sky_color_q14(
353func atm_expneg_q16(x_q16: nx_int) -> nx_int
385func atm_dens_q16(species: nx_int, h_q16: nx_int) -> nx_int
called by 2: mainatm_trans_q16 calls 1: atm_expneg_q16
415func atm_trans_q16(r_q16: nx_int, mu_q16: nx_int, out_rgb: *i64)
493func atm_sun_rgb_q16(mu_q16: nx_int, out_rgb: *i64)
called by 1: atm_bake_sun_lut calls 1: atm_trans_q16
503func atm_bake_sun_lut(out_rgb: *i64)
521func main() -> i64