#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct NerfConfig {
pub n_layers: usize,
pub hidden_dim: usize,
pub n_freq_pos: usize,
pub n_freq_dir: usize,
pub near: f64,
pub far: f64,
pub n_samples: usize,
pub n_importance: usize,
}
impl Default for NerfConfig {
fn default() -> Self {
Self {
n_layers: 8,
hidden_dim: 256,
n_freq_pos: 10,
n_freq_dir: 4,
near: 2.0,
far: 6.0,
n_samples: 64,
n_importance: 128,
}
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct NgpConfig {
pub n_levels: usize,
pub n_features_per_level: usize,
pub log2_hashmap_size: usize,
pub base_resolution: usize,
pub finest_resolution: usize,
}
impl Default for NgpConfig {
fn default() -> Self {
Self {
n_levels: 16,
n_features_per_level: 2,
log2_hashmap_size: 19,
base_resolution: 16,
finest_resolution: 512,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct Ray {
pub origin: [f64; 3],
pub direction: [f64; 3],
}
impl Ray {
pub fn new(origin: [f64; 3], direction: [f64; 3]) -> Option<Self> {
let mag = (direction[0] * direction[0]
+ direction[1] * direction[1]
+ direction[2] * direction[2])
.sqrt();
if mag < 1e-12 {
return None;
}
Some(Self {
origin,
direction: [direction[0] / mag, direction[1] / mag, direction[2] / mag],
})
}
#[inline]
pub fn at(&self, t: f64) -> [f64; 3] {
[
self.origin[0] + t * self.direction[0],
self.origin[1] + t * self.direction[1],
self.origin[2] + t * self.direction[2],
]
}
}
#[derive(Debug, Clone)]
pub struct SamplePoint {
pub position: [f64; 3],
pub t: f64,
pub density: f64,
pub color: [f64; 3],
}
impl SamplePoint {
pub fn new(position: [f64; 3], t: f64, density: f64, color: [f64; 3]) -> Self {
Self {
position,
t,
density: density.max(0.0),
color: [
color[0].clamp(0.0, 1.0),
color[1].clamp(0.0, 1.0),
color[2].clamp(0.0, 1.0),
],
}
}
}
#[derive(Debug, Clone)]
pub struct VolumeRenderResult {
pub color: [f64; 3],
pub depth: f64,
pub transmittance: f64,
pub weights: Vec<f64>,
}