Rendering lto orb barely

This commit is contained in:
hal8174 2025-09-14 22:41:52 +02:00
parent 479cf89e8d
commit eeae057204
Signed by: hal8174
SSH key fingerprint: SHA256:NN98ZYwnrreQLSOV/g+amY7C3yL/mS1heD7bi5t6PPw
4 changed files with 97 additions and 64 deletions

View file

@ -248,12 +248,12 @@ fn parse_shape<R>(iter: &mut Tokenizer) -> Result<Statement<R>> {
"loopsubdiv" => {
let t = parse_dict!(iter =>
levels, u32, 3;
indices, Vec<usize>, Vec::new();
indices, Vec<[usize;3]>, Vec::new();
p, Vec<Pos3>, Vec::new();
alpha, ShapeAlpha, ShapeAlpha::None
=>
levels, "integer levels", iter.parse_parameter()?;
indices, "integer indices", iter.parse_list()?;
indices, "integer indices", iter.parse_list_3(|a, b, c|[a, b, c])?;
p, "point3 P", iter.parse_list_3(Pos3::new)?;
alpha, "float alpha", ShapeAlpha::Value(iter.parse_parameter()?);
alpha, "texture alpha", ShapeAlpha::Texture(iter.parse_parameter()?)
@ -263,16 +263,26 @@ fn parse_shape<R>(iter: &mut Tokenizer) -> Result<Statement<R>> {
bail!("indices are a required field")
}
if t.p.is_empty() {
bail!("p is a required field")
if t.p.len() < 3 {
bail!("at least 3 vertices required")
}
eprintln!(
"WARNING: loopsubdiv is bodged. No subdivisions. levels: {}",
t.levels
);
Ok(Statement::Shape(
ShapeType::LoopSubDiv {
levels: t.levels,
indices: t.indices,
p: t.p,
},
ShapeType::TriangleMesh(Bvh::new(
TriangleMesh {
indices: t.indices,
p: t.p,
n: Vec::new(),
s: Vec::new(),
uv: Vec::new(),
},
8,
)),
t.alpha,
))
}

View file

@ -70,11 +70,15 @@ struct PbrtCoatedDiffuseMaterial {
impl<R: Rng> PbrtMaterial<R> for PbrtCoatedDiffuseMaterial {
fn eval(&self, u: Float, v: Float, w_in: Dir3, w_out: Dir3, rng: &mut R) -> Color {
let _ = rng;
let _ = w_out;
let _ = w_in;
let _ = u;
let _ = v;
Color::black()
if w_out.y() >= 0.0 {
match &self.reflectance {
Either::A(v) => *v,
Either::B(t) => t.get(u, v),
}
} else {
Color::black()
}
}
}
@ -202,50 +206,53 @@ pub fn parse_material<R: Rng>(
"texture reflectance", Either::B(parse_2d_spectrum_texture(input, context)?)
]
))),
"coateddiffuse" => Ok(Arc::new(parse_dict2!(input, PbrtCoatedDiffuseMaterial;
albedo, Either::A(Color::black()), [
"rgb albedo", Either::A(texture::parse_rgb(input)?);
"spectrum albedo", Either::A(texture::parse_spectrum(input)?);
"texture albedo", Either::B(parse_2d_spectrum_texture(input, context)?)
];
g, Either::A(0.0), [
"float g", Either::A(input.parse_parameter()?);
"texture g", Either::B(parse_2d_float_texture(input, context)?)
];
maxdepth, 10, ["integer maxdepth", input.parse_parameter()?];
nsamples, 1, ["integer nsamples", input.parse_parameter()?];
thickness, 0.01, ["float thickness", input.parse_parameter()?];
roughness, Either::A(0.0), [
"float roughness", Either::A(input.parse_parameter()?);
"texture roughness", Either::B(parse_2d_float_texture(input, context)?)
];
uroughness, Either::A(0.0), [
"float uroughness", Either::A(input.parse_parameter()?);
"texture uroughness", Either::B(parse_2d_float_texture(input, context)?)
];
vroughness, Either::A(0.0), [
"float vroughness", Either::A(input.parse_parameter()?);
"texture vroughness", Either::B(parse_2d_float_texture(input, context)?)
];
reflectance, Either::A(Color::black()), [
"rgb reflectance", Either::A(texture::parse_rgb(input)?);
"spectrum reflectance", Either::A(texture::parse_spectrum(input)?);
"texture reflectance", Either::B(parse_2d_spectrum_texture(input, context)?)
];
eta, Either::A(Either::A(1.5)), [
"float eta", Either::A(Either::A(input.parse_parameter()?));
"rgb eta", Either::B(Either::A(parse_rgb(input)?));
"spectrum eta", Either::B(Either::A(texture::parse_spectrum(input)?));
"texture eta", {
let n = input.parse_parameter()?;
let t = context.get_texture(&n).ok_or_else(|| miette!("Unknown texture"))?;
match Arc::clone(t).get_2d_spectrum_texture() {
Ok(t) => Either::B(Either::B(t)),
Err(_) => Either::A(Either::B(Arc::clone(t).get_2d_float_texture()?))
}
}
]
))),
"coateddiffuse" => Ok({
eprintln!("WARNING: coateddiffuse has no coating");
Arc::new(parse_dict2!(input, PbrtCoatedDiffuseMaterial;
albedo, Either::A(Color::black()), [
"rgb albedo", Either::A(texture::parse_rgb(input)?);
"spectrum albedo", Either::A(texture::parse_spectrum(input)?);
"texture albedo", Either::B(parse_2d_spectrum_texture(input, context)?)
];
g, Either::A(0.0), [
"float g", Either::A(input.parse_parameter()?);
"texture g", Either::B(parse_2d_float_texture(input, context)?)
];
maxdepth, 10, ["integer maxdepth", input.parse_parameter()?];
nsamples, 1, ["integer nsamples", input.parse_parameter()?];
thickness, 0.01, ["float thickness", input.parse_parameter()?];
roughness, Either::A(0.0), [
"float roughness", Either::A(input.parse_parameter()?);
"texture roughness", Either::B(parse_2d_float_texture(input, context)?)
];
uroughness, Either::A(0.0), [
"float uroughness", Either::A(input.parse_parameter()?);
"texture uroughness", Either::B(parse_2d_float_texture(input, context)?)
];
vroughness, Either::A(0.0), [
"float vroughness", Either::A(input.parse_parameter()?);
"texture vroughness", Either::B(parse_2d_float_texture(input, context)?)
];
reflectance, Either::A(Color::black()), [
"rgb reflectance", Either::A(texture::parse_rgb(input)?);
"spectrum reflectance", Either::A(texture::parse_spectrum(input)?);
"texture reflectance", Either::B(parse_2d_spectrum_texture(input, context)?)
];
eta, Either::A(Either::A(1.5)), [
"float eta", Either::A(Either::A(input.parse_parameter()?));
"rgb eta", Either::B(Either::A(parse_rgb(input)?));
"spectrum eta", Either::B(Either::A(texture::parse_spectrum(input)?));
"texture eta", {
let n = input.parse_parameter()?;
let t = context.get_texture(&n).ok_or_else(|| miette!("Unknown texture"))?;
match Arc::clone(t).get_2d_spectrum_texture() {
Ok(t) => Either::B(Either::B(t)),
Err(_) => Either::A(Either::B(Arc::clone(t).get_2d_float_texture()?))
}
}
]
))
}),
"dielectric" => Ok(Arc::new(parse_dict2!(input, PbrtDielectricMaterial;
eta, Either::A(Either::A(1.5)), [
"float eta", Either::A(Either::A(input.parse_parameter()?));

View file

@ -159,11 +159,6 @@ pub(crate) enum ShapeType {
n: Vec<Dir3>,
uv: Vec<[Float; 2]>,
},
LoopSubDiv {
levels: u32,
indices: Vec<usize>,
p: Vec<Pos3>,
},
Disk {
height: Float,
radius: Float,

View file

@ -121,8 +121,29 @@ impl Pbrt2dSpectrumTexture for SpectrumImageMapTexture {
let (w, h) = self.image.dimensions();
dbg!(u, v, w, h);
todo!()
let (u, v) = match self.wrap {
ImageMapWrap::Repeat => (
if u < 0.0 { 1.0 + u.fract() } else { u.fract() },
if v < 0.0 { 1.0 + v.fract() } else { v.fract() },
),
ImageMapWrap::Black => {
if !(0.0..=1.0).contains(&u) || !(0.0..=1.0).contains(&v) {
return Color::black();
}
(u, v)
}
ImageMapWrap::Clamp => (u.clamp(0.0, 1.0), v.clamp(0.0, 1.0)),
};
let x = u * w as Float;
let y = v * h as Float;
let c = self
.image
.get_pixel((x as u32).clamp(0, w - 1), (y as u32).clamp(0, h - 1));
Color::new(c.0[0], c.0[1], c.0[2])
}
}