Run latest rustfmt on code. No functional changes.

This commit is contained in:
Nathan Vegdahl 2018-12-08 13:23:44 -08:00
parent e9b495e729
commit 589a67caa4
14 changed files with 133 additions and 116 deletions

View File

@ -87,7 +87,8 @@ impl<'a> Camera<'a> {
(x * tfov) - (orig.x() / focus_distance),
(y * tfov) - (orig.y() / focus_distance),
1.0,
).normalized();
)
.normalized();
Ray::new(orig * transform, dir * transform, time, wavelength, false)
}

View File

@ -181,12 +181,14 @@ impl Image {
.add_channel("G", openexr::PixelType::HALF)
.add_channel("B", openexr::PixelType::HALF)
.set_compression(openexr::header::Compression::PIZ_COMPRESSION),
).unwrap();
)
.unwrap();
wr.write_pixels(
openexr::FrameBuffer::new(self.res.0 as u32, self.res.1 as u32)
.insert_channels(&["R", "G", "B"], &image),
).unwrap();
)
.unwrap();
}
}

View File

@ -36,7 +36,8 @@ impl<'a> RectangleLight<'a> {
.map(|d| BBox {
min: Point::new(d.0 * -0.5, d.1 * -0.5, 0.0),
max: Point::new(d.0 * 0.5, d.1 * 0.5, 0.0),
}).collect();
})
.collect();
RectangleLight {
dimensions: arena.copy_slice(&dimensions),
colors: arena.copy_slice(&colors),
@ -181,7 +182,8 @@ impl<'a> SurfaceLight for RectangleLight<'a> {
(u - threshhold) / (1.0 - threshhold),
)
}
}.into_point();
}
.into_point();
let shadow_vec = sample_point - arr;
let spectral_sample =
(col * surface_area_inv as f32 * 0.5).to_spectral_sample(wavelength);

View File

@ -35,7 +35,8 @@ impl<'a> SphereLight<'a> {
.map(|r| BBox {
min: Point::new(-*r, -*r, -*r),
max: Point::new(*r, *r, *r),
}).collect();
})
.collect();
SphereLight {
radii: arena.copy_slice(&radii),
colors: arena.copy_slice(&colors),

View File

@ -91,7 +91,8 @@ fn main() {
.help("Input .psy file")
.takes_value(true)
.required_unless_one(&["dev", "use_stdin"]),
).arg(
)
.arg(
Arg::with_name("spp")
.short("s")
.long("spp")
@ -103,7 +104,8 @@ fn main() {
.and(Ok(()))
.or(Err("must be an integer".to_string()))
}),
).arg(
)
.arg(
Arg::with_name("max_bucket_samples")
.short("b")
.long("spb")
@ -115,21 +117,24 @@ fn main() {
.and(Ok(()))
.or(Err("must be an integer".to_string()))
}),
).arg(
)
.arg(
Arg::with_name("crop")
.long("crop")
.value_name("X1 Y1 X2 Y2")
.help(
"Only render the image between pixel coordinates (X1, Y1) \
and (X2, Y2). Coordinates are zero-indexed and inclusive.",
).takes_value(true)
)
.takes_value(true)
.number_of_values(4)
.validator(|s| {
usize::from_str(&s)
.and(Ok(()))
.or(Err("must be four integers".to_string()))
}),
).arg(
)
.arg(
Arg::with_name("threads")
.short("t")
.long("threads")
@ -137,31 +142,37 @@ fn main() {
.help(
"Number of threads to render with. Defaults to the number of logical \
cores on the system.",
).takes_value(true)
)
.takes_value(true)
.validator(|s| {
usize::from_str(&s)
.and(Ok(()))
.or(Err("must be an integer".to_string()))
}),
).arg(
)
.arg(
Arg::with_name("stats")
.long("stats")
.help("Print additional statistics about rendering"),
).arg(
)
.arg(
Arg::with_name("dev")
.long("dev")
.help("Show useful dev/debug info."),
).arg(
)
.arg(
Arg::with_name("serialized_output")
.long("serialized_output")
.help("Serialize and send render output to standard output.")
.hidden(true),
).arg(
)
.arg(
Arg::with_name("use_stdin")
.long("use_stdin")
.help("Take scene file in from stdin instead of a file path.")
.hidden(true),
).get_matches();
)
.get_matches();
// Print some misc useful dev info.
if args.is_present("dev") {

View File

@ -701,7 +701,8 @@ mod tests {
A {}
B {}
"#,
).unwrap();
)
.unwrap();
let i = dt.iter_children_with_type("A");
assert_eq!(i.count(), 3);
@ -717,7 +718,8 @@ mod tests {
A {}
B {}
"#,
).unwrap();
)
.unwrap();
let i = dt.iter_internal_children_with_type("A");
assert_eq!(i.count(), 2);
@ -733,7 +735,8 @@ mod tests {
A []
B {}
"#,
).unwrap();
)
.unwrap();
let i = dt.iter_leaf_children_with_type("A");
assert_eq!(i.count(), 2);

View File

@ -207,9 +207,7 @@ fn parse_output_info(tree: &DataTree) -> Result<String, PsyParseError> {
type_name,
contents,
byte_offset,
}
if type_name == "Path" =>
{
} if type_name == "Path" => {
// Trim and validate
let tc = contents.trim();
if tc.chars().count() < 2 {
@ -271,9 +269,7 @@ fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyP
type_name,
contents,
byte_offset,
}
if type_name == "Resolution" =>
{
} if type_name == "Resolution" => {
if let IResult::Done(_, (w, h)) =
closure!(terminated!(tuple!(ws_u32, ws_u32), eof!()))(contents.as_bytes())
{
@ -294,9 +290,7 @@ fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyP
type_name,
contents,
byte_offset,
}
if type_name == "SamplesPerPixel" =>
{
} if type_name == "SamplesPerPixel" => {
if let IResult::Done(_, n) = ws_u32(contents.as_bytes()) {
found_spp = true;
spp = n;
@ -316,9 +310,7 @@ fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyP
type_name,
contents,
byte_offset,
}
if type_name == "Seed" =>
{
} if type_name == "Seed" => {
if let IResult::Done(_, n) = ws_u32(contents.as_bytes()) {
seed = n;
} else {
@ -370,9 +362,7 @@ fn parse_camera<'a>(arena: &'a MemArena, tree: &'a DataTree) -> Result<Camera<'a
type_name,
contents,
byte_offset,
}
if type_name == "Fov" =>
{
} if type_name == "Fov" => {
if let IResult::Done(_, fov) = ws_f32(contents.as_bytes()) {
fovs.push(fov * (f32::consts::PI / 180.0));
} else {
@ -391,9 +381,7 @@ fn parse_camera<'a>(arena: &'a MemArena, tree: &'a DataTree) -> Result<Camera<'a
type_name,
contents,
byte_offset,
}
if type_name == "FocalDistance" =>
{
} if type_name == "FocalDistance" => {
if let IResult::Done(_, fd) = ws_f32(contents.as_bytes()) {
focus_distances.push(fd);
} else {
@ -412,9 +400,7 @@ fn parse_camera<'a>(arena: &'a MemArena, tree: &'a DataTree) -> Result<Camera<'a
type_name,
contents,
byte_offset,
}
if type_name == "ApertureRadius" =>
{
} if type_name == "ApertureRadius" => {
if let IResult::Done(_, ar) = ws_f32(contents.as_bytes()) {
aperture_radii.push(ar);
} else {
@ -433,9 +419,7 @@ fn parse_camera<'a>(arena: &'a MemArena, tree: &'a DataTree) -> Result<Camera<'a
type_name,
contents,
byte_offset,
}
if type_name == "Transform" =>
{
} if type_name == "Transform" => {
if let Ok(mat) = parse_matrix(contents) {
mats.push(mat);
} else {

View File

@ -31,9 +31,7 @@ pub fn parse_distant_disk_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Radius" =>
{
} if type_name == "Radius" => {
if let IResult::Done(_, radius) = ws_f32(contents.as_bytes()) {
radii.push(radius);
} else {
@ -47,9 +45,7 @@ pub fn parse_distant_disk_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Direction" =>
{
} if type_name == "Direction" => {
if let IResult::Done(_, direction) =
closure!(tuple!(ws_f32, ws_f32, ws_f32))(contents.as_bytes())
{
@ -65,9 +61,7 @@ pub fn parse_distant_disk_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Color" =>
{
} if type_name == "Color" => {
if let IResult::Done(_, color) =
closure!(tuple!(ws_f32, ws_f32, ws_f32))(contents.as_bytes())
{
@ -107,9 +101,7 @@ pub fn parse_sphere_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Radius" =>
{
} if type_name == "Radius" => {
if let IResult::Done(_, radius) = ws_f32(contents.as_bytes()) {
radii.push(radius);
} else {
@ -123,9 +115,7 @@ pub fn parse_sphere_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Color" =>
{
} if type_name == "Color" => {
if let IResult::Done(_, color) =
closure!(tuple!(ws_f32, ws_f32, ws_f32))(contents.as_bytes())
{
@ -165,9 +155,7 @@ pub fn parse_rectangle_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Dimensions" =>
{
} if type_name == "Dimensions" => {
if let IResult::Done(_, radius) =
closure!(tuple!(ws_f32, ws_f32))(contents.as_bytes())
{
@ -183,9 +171,7 @@ pub fn parse_rectangle_light<'a>(
type_name,
contents,
byte_offset,
}
if type_name == "Color" =>
{
} if type_name == "Color" => {
if let IResult::Done(_, color) =
closure!(tuple!(ws_f32, ws_f32, ws_f32))(contents.as_bytes())
{

View File

@ -310,7 +310,8 @@ impl<'a> AssemblyBuilder<'a> {
.approximate_energy()
> 0.0
}
}).cloned()
})
.cloned()
.collect();
// Build light accel

View File

@ -346,7 +346,8 @@ impl SurfaceClosure for LambertClosure {
nor.normalized()
} else {
-nor.normalized()
}.into_vector();
}
.into_vector();
let cos_nv = dot(nn, v).max(-1.0).min(1.0);
@ -626,7 +627,8 @@ impl SurfaceClosure for GTRClosure {
nor.normalized()
} else {
-nor.normalized() // If back-facing, flip normal
}.into_vector();
}
.into_vector();
let aa = -inc.normalized(); // Vector pointing to where "in" came from
let bb = to_light_center.normalized(); // Out
@ -871,7 +873,8 @@ impl SurfaceClosure for GGXClosure {
nor.normalized()
} else {
-nor.normalized() // If back-facing, flip normal
}.into_vector();
}
.into_vector();
let aa = -inc.normalized(); // Vector pointing to where "in" came from
let bb = to_light_center.normalized(); // Out

View File

@ -140,7 +140,8 @@ pub fn surface_point(tri: (Point, Point, Point), bary: (f32, f32, f32)) -> (Poin
let pos_err = (((tri.0.into_vector().abs() * bary.0)
+ (tri.1.into_vector().abs() * bary.1)
+ (tri.2.into_vector().abs() * bary.2))
* fp_gamma(7)).co
* fp_gamma(7))
.co
.h_max();
(pos, pos_err)

View File

@ -170,17 +170,14 @@ impl<'a> Surface for TriangleMesh<'a> {
} else {
// Deformation motion blur, need to interpolate.
let p0_slice = &self.vertices[(tri_indices.0 as usize
* self.time_sample_count)
..((tri_indices.0 as usize + 1)
* self.time_sample_count)];
* self.time_sample_count)
..((tri_indices.0 as usize + 1) * self.time_sample_count)];
let p1_slice = &self.vertices[(tri_indices.1 as usize
* self.time_sample_count)
..((tri_indices.1 as usize + 1)
* self.time_sample_count)];
* self.time_sample_count)
..((tri_indices.1 as usize + 1) * self.time_sample_count)];
let p2_slice = &self.vertices[(tri_indices.2 as usize
* self.time_sample_count)
..((tri_indices.2 as usize + 1)
* self.time_sample_count)];
* self.time_sample_count)
..((tri_indices.2 as usize + 1) * self.time_sample_count)];
let p0 = lerp_slice(p0_slice, wr.time);
let p1 = lerp_slice(p1_slice, wr.time);
@ -229,17 +226,14 @@ impl<'a> Surface for TriangleMesh<'a> {
// Calculate interpolated surface normal, if any
let shading_normal = if let Some(normals) = self.normals {
let n0_slice = &normals[(tri_indices.0 as usize
* self.time_sample_count)
..((tri_indices.0 as usize + 1)
* self.time_sample_count)];
* self.time_sample_count)
..((tri_indices.0 as usize + 1) * self.time_sample_count)];
let n1_slice = &normals[(tri_indices.1 as usize
* self.time_sample_count)
..((tri_indices.1 as usize + 1)
* self.time_sample_count)];
* self.time_sample_count)
..((tri_indices.1 as usize + 1) * self.time_sample_count)];
let n2_slice = &normals[(tri_indices.2 as usize
* self.time_sample_count)
..((tri_indices.2 as usize + 1)
* self.time_sample_count)];
* self.time_sample_count)
..((tri_indices.2 as usize + 1) * self.time_sample_count)];
let n0 = lerp_slice(n0_slice, wr.time).normalized();
let n1 = lerp_slice(n1_slice, wr.time).normalized();

View File

@ -99,8 +99,10 @@ pub fn {}_to_xyz(rgb: (f32, f32, f32)) -> (f32, f32, f32) {{
to_xyz[2][0],
to_xyz[2][1],
to_xyz[2][2]
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
let inv = inverse(to_xyz);
f.write_all(
@ -125,8 +127,10 @@ pub fn xyz_to_{}(xyz: (f32, f32, f32)) -> (f32, f32, f32) {{
inv[2][0],
inv[2][1],
inv[2][2]
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
let e_to_xyz = adapt_to_e(to_xyz, 1.0);
f.write_all(
@ -151,8 +155,10 @@ pub fn {}_e_to_xyz(rgb: (f32, f32, f32)) -> (f32, f32, f32) {{
e_to_xyz[2][0],
e_to_xyz[2][1],
e_to_xyz[2][2]
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
let inv_e = inverse(e_to_xyz);
f.write_all(
@ -177,8 +183,10 @@ pub fn xyz_to_{}_e(xyz: (f32, f32, f32)) -> (f32, f32, f32) {{
inv_e[2][0],
inv_e[2][1],
inv_e[2][2]
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
}
/// Port of the RGBtoXYZ function from the ACES CTL reference implementation.

View File

@ -92,8 +92,10 @@ fn main() {
pub const MAX_DIMENSION: u32 = {};
"#,
NUM_DIMENSIONS
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
// Write the sampling function
f.write_all(
@ -102,8 +104,10 @@ pub const MAX_DIMENSION: u32 = {};
#[inline]
pub fn sample(dimension: u32, index: u32) -> f32 {{
match dimension {{"#
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
for i in 0..NUM_DIMENSIONS {
f.write_all(
@ -111,8 +115,10 @@ pub fn sample(dimension: u32, index: u32) -> f32 {{
r#"
{} => halton{}(index),"#,
i, primes[i]
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
}
f.write_all(
@ -122,8 +128,10 @@ pub fn sample(dimension: u32, index: u32) -> f32 {{
}}
}}
"#
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
// Write the special-cased first dimension
f.write_all(
@ -139,8 +147,10 @@ fn halton2(mut index: u32) -> f32 {{
return (index as f32) * (1.0 / ((1u64 << 32) as f32));
}}
"#
).as_bytes(),
).unwrap();
)
.as_bytes(),
)
.unwrap();
for i in 1..NUM_DIMENSIONS {
// Skip base 2.
@ -186,16 +196,20 @@ fn halton{}(index: u32) -> f32 {{
base,
perm.len(),
perm_string
).as_bytes(),
).unwrap();;
)
.as_bytes(),
)
.unwrap();;
f.write_all(
format!(
r#"
return (unsafe{{*PERM{}.get_unchecked((index % {}) as usize)}} as u32 * {} +"#,
base, pow_base, power
).as_bytes(),
).unwrap();;
)
.as_bytes(),
)
.unwrap();;
// Advance to next set of digits.
let mut div = 1;
@ -207,8 +221,10 @@ fn halton{}(index: u32) -> f32 {{
r#"
unsafe{{*PERM{}.get_unchecked(((index / {}) % {}) as usize)}} as u32 * {} +"#,
base, div, pow_base, power
).as_bytes(),
).unwrap();;
)
.as_bytes(),
)
.unwrap();;
}
f.write_all(
@ -222,8 +238,10 @@ fn halton{}(index: u32) -> f32 {{
div * pow_base,
pow_base,
max_power
).as_bytes(),
).unwrap();;
)
.as_bytes(),
)
.unwrap();;
}
}
@ -255,7 +273,8 @@ fn get_faure_permutation(faure: &Vec<Vec<usize>>, b: usize) -> Vec<usize> {
let f: usize = faure[b - 1][i - ((i > c) as usize)];
f + ((f >= c) as usize)
}).collect();
})
.collect();
} else {
// even
let c = b / 2;
@ -267,7 +286,8 @@ fn get_faure_permutation(faure: &Vec<Vec<usize>>, b: usize) -> Vec<usize> {
} else {
2 * faure[c][i - c] + 1
}
}).collect();
})
.collect();
}
}