Add Oren-Nayar and fix bugs

This commit is contained in:
hal8174 2024-12-27 19:11:02 +01:00
parent 3a37a72f56
commit 745b7d2602
7 changed files with 137 additions and 28 deletions

View file

@ -1,6 +1,10 @@
use rand::Rng;
use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene};
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
use ray_tracing_material::{
diffuse::DiffuseMaterial,
microfacet::{BeckmannDistribution, Microfacet},
oren_nayar::OrenNayar,
};
use std::fmt::Debug;
use crate::{
@ -12,6 +16,11 @@ use super::ExampleScene;
pub fn scene<R: Rng + Debug + 'static>() -> ExampleScene<R> {
let f = || {
let color = Color::new(0.2, 0.2, 0.9);
// let m = DiffuseMaterial::new(color);
// let m = Microfacet::new(BeckmannDistribution::new(0.5), color);
let m = OrenNayar::new(0.5, color);
let obj = ObjData::new("ray-tracing-scene/obj/stanford_dragon.obj").unwrap();
let mut triangles = obj
@ -20,7 +29,7 @@ pub fn scene<R: Rng + Debug + 'static>() -> ExampleScene<R> {
.collect::<Vec<_>>();
let materials = vec![
BVHMaterial::new_material(DiffuseMaterial::new(Color::new(0.2, 0.2, 0.9))),
BVHMaterial::new_material(m),
BVHMaterial::new_light(AreaLight::new(Color::white() * 30.0)),
];
@ -50,7 +59,7 @@ pub fn scene<R: Rng + Debug + 'static>() -> ExampleScene<R> {
ExampleScene {
scene: f,
camera_pos: Pos3::new(0.0, 0.0, -400.0),
camera_pos: Pos3::new(-150.0, 100.0, 250.0),
camera_look_at: Pos3::new(0.0, 0.0, 0.0),
camera_up: Dir3::up(),
horizontal_fov: 90.0_f32.to_radians(),