Minor cleanup and tidying; no change in functionality.
This commit is contained in:
parent
2b3d350fbb
commit
d98144ab74
16
src/image.rs
16
src/image.rs
|
|
@ -13,8 +13,8 @@ pub struct ImageRgbU8 {
|
|||
impl ImageRgbU8 {
|
||||
pub fn new(width: u32, height: u32) -> ImageRgbU8 {
|
||||
ImageRgbU8 {
|
||||
width: width,
|
||||
height: height,
|
||||
width,
|
||||
height,
|
||||
pixel_data: vec![0; (width * height * 3) as usize],
|
||||
}
|
||||
}
|
||||
|
|
@ -73,8 +73,8 @@ pub struct ImageRgbF<T: RealField> {
|
|||
impl<T: RealField> ImageRgbF<T> {
|
||||
pub fn new(width: u32, height: u32) -> ImageRgbF<T> {
|
||||
ImageRgbF {
|
||||
width: width,
|
||||
height: height,
|
||||
width,
|
||||
height,
|
||||
pixel_data: vec![convert(0.0); (width * height * 3) as usize],
|
||||
}
|
||||
}
|
||||
|
|
@ -272,7 +272,7 @@ mod tests {
|
|||
let mut image_out = ImageRgbU8::new(1, 1);
|
||||
image_in.set_colour(0, 0, ColourRgbF::new(1.0, 1.0, 1.0));
|
||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
||||
assert!(image_out.get_colour(0, 0).values == [0xff, 0xff, 0xff]);
|
||||
assert!(image_out.get_colour(0, 0).values == [0xff, 0xff, 0xff]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -282,7 +282,7 @@ mod tests {
|
|||
let mut image_out = ImageRgbU8::new(1, 1);
|
||||
image_in.set_colour(0, 0, ColourRgbF::new(2.0, 2.0, 2.0));
|
||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
||||
assert!(image_out.get_colour(0, 0).values == [0xff, 0xff, 0xff]);
|
||||
assert!(image_out.get_colour(0, 0).values == [0xff, 0xff, 0xff]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -292,7 +292,7 @@ mod tests {
|
|||
let mut image_out = ImageRgbU8::new(1, 1);
|
||||
image_in.set_colour(0, 0, ColourRgbF::new(0.0, 2.0, 0.0));
|
||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
||||
assert!(image_out.get_colour(0, 0).values == [0x0, 0xff, 0x0]);
|
||||
assert!(image_out.get_colour(0, 0).values == [0x0, 0xff, 0x0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -302,7 +302,7 @@ mod tests {
|
|||
let mut image_out = ImageRgbU8::new(1, 1);
|
||||
image_in.set_colour(0, 0, ColourRgbF::new(0.5, 0.0, 0.0));
|
||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
||||
assert!(image_out.get_colour(0, 0).values == [0x7f, 0x0, 0x0]);
|
||||
assert!(image_out.get_colour(0, 0).values == [0x7f, 0x0, 0x0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl<T: RealField> Integrator<T> for WhittedIntegrator<T> {
|
|||
.iter()
|
||||
.map(|light| {
|
||||
match sampler
|
||||
.sample(&Ray::new(info.location, light.direction).bias(convert(0.0000001)))
|
||||
.sample(&Ray::new(info.location, light.direction).bias(convert(0.000_000_1)))
|
||||
{
|
||||
Some(_) => self.ambient_light,
|
||||
None => {
|
||||
|
|
@ -53,7 +53,7 @@ impl<T: RealField> Integrator<T> for WhittedIntegrator<T> {
|
|||
let world_space_direction = bsdf_to_world_space * direction;
|
||||
match sampler.sample(
|
||||
&Ray::new(info.location, world_space_direction)
|
||||
.bias(convert(0.0000001)),
|
||||
.bias(convert(0.000_000_1)),
|
||||
) {
|
||||
Some(recursive_hit) => {
|
||||
info.material.bsdf()(
|
||||
|
|
|
|||
|
|
@ -115,9 +115,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let mut event_pump = sdl_context.event_pump()?;
|
||||
let mut i = 0;
|
||||
'running: loop {
|
||||
let tile_size = 128;
|
||||
for tile_row in 0..1 + (output_image.get_height() + 1) / tile_size {
|
||||
for tile_column in 0..1 + (output_image.get_width() + 1) / tile_size {
|
||||
let tile_size = 256;
|
||||
for tile_row in 0..=(output_image.get_height() + 1) / tile_size {
|
||||
for tile_column in 0..=(output_image.get_width() + 1) / tile_size {
|
||||
let row_start = tile_row * tile_size;
|
||||
let row_end = min(tile_row * tile_size + tile_size, output_image.get_height());
|
||||
let column_start = tile_column * tile_size;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl<T: RealField> Ray<T> {
|
|||
}
|
||||
|
||||
pub fn point_at(&self, t: T) -> Vector3<T> {
|
||||
return self.origin + self.direction * t;
|
||||
self.origin + self.direction * t
|
||||
}
|
||||
|
||||
pub fn bias(&self, amount: T) -> Ray<T> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue