Fix camera for egui renderer
This commit is contained in:
parent
1bfef16afa
commit
632cb97007
3 changed files with 8 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ pub trait Camera<R: Rng> {
|
|||
fn height(&self) -> u32;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BasicCamera {
|
||||
width: u32,
|
||||
height: u32,
|
||||
|
|
@ -55,10 +56,11 @@ impl BasicCamera {
|
|||
impl<R: Rng> Camera<R> for BasicCamera {
|
||||
fn forward(&self, x: u32, y: u32, rng: &mut R) -> Ray {
|
||||
// normalize x and y to -0.5 to 0.5
|
||||
let x = ((x as Float + rng.gen::<Float>()) / (self.width as Float)) - 0.5;
|
||||
let y = ((y as Float + rng.gen::<Float>()) / (self.height as Float)) - 0.5;
|
||||
|
||||
let dir = self.dir + x * self.h + y * self.v;
|
||||
let x_float = ((x as Float + rng.gen::<Float>()) / (self.width as Float)) - 0.5;
|
||||
let y_float = ((y as Float + rng.gen::<Float>()) / (self.height as Float)) - 0.5;
|
||||
|
||||
let dir = self.dir + x_float * self.h + y_float * self.v;
|
||||
|
||||
Ray::new(self.pos, dir.normalize(), 0.0)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ pub fn render_thread(
|
|||
e.camera_up,
|
||||
e.horizontal_fov,
|
||||
);
|
||||
dbg!(&camera);
|
||||
buffer = vec![0.0; settings.width as usize * settings.height as usize * 3];
|
||||
renderer = (RENDERER[settings.renderer_id].1)(settings.width, settings.height);
|
||||
samples = 0;
|
||||
|
|
@ -106,7 +107,7 @@ pub fn render_thread(
|
|||
|
||||
buffer.par_chunks_mut(3).enumerate().for_each(|(i, c)| {
|
||||
let x = (i % settings.width as usize) as u32;
|
||||
let y = (i / settings.height as usize) as u32;
|
||||
let y = (i / settings.width as usize) as u32;
|
||||
|
||||
let mut rng = SmallRng::seed_from_u64(
|
||||
(x + y * settings.width) as u64
|
||||
|
|
|
|||
|
|
@ -58,5 +58,5 @@ fn main() -> ImageResult<()> {
|
|||
|
||||
let r = PathTracerImportance::new(400, 400);
|
||||
|
||||
render_image(&r, &s.scene, &c, "test.exr", 1048)
|
||||
render_image(&r, &(s.scene)(), &c, "test.exr", 1048)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue