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 {
|
impl ImageRgbU8 {
|
||||||
pub fn new(width: u32, height: u32) -> ImageRgbU8 {
|
pub fn new(width: u32, height: u32) -> ImageRgbU8 {
|
||||||
ImageRgbU8 {
|
ImageRgbU8 {
|
||||||
width: width,
|
width,
|
||||||
height: height,
|
height,
|
||||||
pixel_data: vec![0; (width * height * 3) as usize],
|
pixel_data: vec![0; (width * height * 3) as usize],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,8 +73,8 @@ pub struct ImageRgbF<T: RealField> {
|
||||||
impl<T: RealField> ImageRgbF<T> {
|
impl<T: RealField> ImageRgbF<T> {
|
||||||
pub fn new(width: u32, height: u32) -> ImageRgbF<T> {
|
pub fn new(width: u32, height: u32) -> ImageRgbF<T> {
|
||||||
ImageRgbF {
|
ImageRgbF {
|
||||||
width: width,
|
width,
|
||||||
height: height,
|
height,
|
||||||
pixel_data: vec![convert(0.0); (width * height * 3) as usize],
|
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);
|
let mut image_out = ImageRgbU8::new(1, 1);
|
||||||
image_in.set_colour(0, 0, ColourRgbF::new(1.0, 1.0, 1.0));
|
image_in.set_colour(0, 0, ColourRgbF::new(1.0, 1.0, 1.0));
|
||||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
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]
|
#[test]
|
||||||
|
|
@ -282,7 +282,7 @@ mod tests {
|
||||||
let mut image_out = ImageRgbU8::new(1, 1);
|
let mut image_out = ImageRgbU8::new(1, 1);
|
||||||
image_in.set_colour(0, 0, ColourRgbF::new(2.0, 2.0, 2.0));
|
image_in.set_colour(0, 0, ColourRgbF::new(2.0, 2.0, 2.0));
|
||||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
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]
|
#[test]
|
||||||
|
|
@ -292,7 +292,7 @@ mod tests {
|
||||||
let mut image_out = ImageRgbU8::new(1, 1);
|
let mut image_out = ImageRgbU8::new(1, 1);
|
||||||
image_in.set_colour(0, 0, ColourRgbF::new(0.0, 2.0, 0.0));
|
image_in.set_colour(0, 0, ColourRgbF::new(0.0, 2.0, 0.0));
|
||||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
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]
|
#[test]
|
||||||
|
|
@ -302,7 +302,7 @@ mod tests {
|
||||||
let mut image_out = ImageRgbU8::new(1, 1);
|
let mut image_out = ImageRgbU8::new(1, 1);
|
||||||
image_in.set_colour(0, 0, ColourRgbF::new(0.5, 0.0, 0.0));
|
image_in.set_colour(0, 0, ColourRgbF::new(0.5, 0.0, 0.0));
|
||||||
target.apply_tone_mapping(&image_in, &mut image_out);
|
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()
|
.iter()
|
||||||
.map(|light| {
|
.map(|light| {
|
||||||
match sampler
|
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,
|
Some(_) => self.ambient_light,
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -53,7 +53,7 @@ impl<T: RealField> Integrator<T> for WhittedIntegrator<T> {
|
||||||
let world_space_direction = bsdf_to_world_space * direction;
|
let world_space_direction = bsdf_to_world_space * direction;
|
||||||
match sampler.sample(
|
match sampler.sample(
|
||||||
&Ray::new(info.location, world_space_direction)
|
&Ray::new(info.location, world_space_direction)
|
||||||
.bias(convert(0.0000001)),
|
.bias(convert(0.000_000_1)),
|
||||||
) {
|
) {
|
||||||
Some(recursive_hit) => {
|
Some(recursive_hit) => {
|
||||||
info.material.bsdf()(
|
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 event_pump = sdl_context.event_pump()?;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
'running: loop {
|
'running: loop {
|
||||||
let tile_size = 128;
|
let tile_size = 256;
|
||||||
for tile_row in 0..1 + (output_image.get_height() + 1) / tile_size {
|
for tile_row in 0..=(output_image.get_height() + 1) / tile_size {
|
||||||
for tile_column in 0..1 + (output_image.get_width() + 1) / tile_size {
|
for tile_column in 0..=(output_image.get_width() + 1) / tile_size {
|
||||||
let row_start = tile_row * tile_size;
|
let row_start = tile_row * tile_size;
|
||||||
let row_end = min(tile_row * tile_size + tile_size, output_image.get_height());
|
let row_end = min(tile_row * tile_size + tile_size, output_image.get_height());
|
||||||
let column_start = tile_column * tile_size;
|
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> {
|
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> {
|
pub fn bias(&self, amount: T) -> Ray<T> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue