Add scene and renderer selection to egui
This commit is contained in:
parent
d4bf1845cb
commit
1bfef16afa
6 changed files with 200 additions and 100 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use crate::{camera::Camera, prelude::*, scene::Scene};
|
||||
|
||||
pub trait ClassicalRenderer<R: Rng, S: Scene<R>, C: Camera<R>> {
|
||||
|
|
@ -5,3 +7,19 @@ pub trait ClassicalRenderer<R: Rng, S: Scene<R>, C: Camera<R>> {
|
|||
fn width(&self) -> u32;
|
||||
fn height(&self) -> u32;
|
||||
}
|
||||
|
||||
impl<R: Rng, S: Scene<R>, C: Camera<R>, T: ClassicalRenderer<R, S, C> + ?Sized>
|
||||
ClassicalRenderer<R, S, C> for Box<T>
|
||||
{
|
||||
fn render_pixel(&self, scene: &S, camera: &C, x: u32, y: u32, rng: &mut R) -> Color {
|
||||
self.deref().render_pixel(scene, camera, x, y, rng)
|
||||
}
|
||||
|
||||
fn width(&self) -> u32 {
|
||||
self.deref().width()
|
||||
}
|
||||
|
||||
fn height(&self) -> u32 {
|
||||
self.deref().height()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::ops::Deref;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub trait Scene<R: Rng> {
|
||||
|
|
@ -91,3 +93,18 @@ impl<'sc, R: Rng> LightSample<'sc, R> {
|
|||
Frame::from_normal(self.normal)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Scene<R> + ?Sized, R: Rng> Scene<R> for Box<T> {
|
||||
fn intersect(&self, ray: Ray, min: Float, max: Float) -> Option<Intersection<'_, R>> {
|
||||
self.deref().intersect(ray, min, max)
|
||||
}
|
||||
|
||||
fn sample_light(
|
||||
&self,
|
||||
w_in: Dir3,
|
||||
intersection: &Intersection<'_, R>,
|
||||
rng: &mut R,
|
||||
) -> Option<LightSample<'_, R>> {
|
||||
self.deref().sample_light(w_in, intersection, rng)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue