gamma
This commit is contained in:
parent
89ad39b3e4
commit
33b3707064
|
@ -2,7 +2,7 @@ use std::fs::File;
|
|||
use std::io::{BufWriter};
|
||||
|
||||
use crate::hittable::HittableList;
|
||||
use crate::math_utils::clamp;
|
||||
use crate::math_utils::{clamp, linear_to_gamma};
|
||||
use crate::ppm_writer::PPMWriter;
|
||||
use crate::types_defined::{Camera, Color, Point, Ray, Vec3};
|
||||
use rand::rngs::ThreadRng;
|
||||
|
@ -83,12 +83,12 @@ impl<'a> Camera<'a> {
|
|||
|
||||
// clamp color rgb
|
||||
let color_clamped = Color::new(
|
||||
clamp(color.x, 0.0, 1.0),
|
||||
clamp(color.y, 0.0, 1.0),
|
||||
clamp(color.z, 0.0, 1.0),
|
||||
clamp(linear_to_gamma(color.x), 0.0, 1.0),
|
||||
clamp(linear_to_gamma(color.y), 0.0, 1.0),
|
||||
clamp(linear_to_gamma(color.z), 0.0, 1.0),
|
||||
);
|
||||
|
||||
self.ppm_file_writer.write(color.to_color());
|
||||
let _ = self.ppm_file_writer.write(color_clamped.to_color());
|
||||
|
||||
|
||||
// content
|
||||
|
|
|
@ -7,4 +7,12 @@ pub fn clamp(value: f32, low: f32, high: f32) -> f32 {
|
|||
return high;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
pub fn linear_to_gamma(value: f32) -> f32 {
|
||||
if value > 0.0 {
|
||||
value.sqrt()
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue