Add iridescent material

This commit is contained in:
hal8174 2025-05-23 19:47:08 +02:00
parent d475c1ef04
commit c26a4bece0
Signed by: hal8174
SSH key fingerprint: SHA256:JwuqS+eVfISfKr+DkDQ6NWAbGd1jFAHkPpCM1yCnlTs
8 changed files with 276 additions and 34 deletions

View file

@ -1,4 +1,7 @@
use ray_tracing_core::{prelude::*, scene::Scene};
use ray_tracing_material::iridescent::Iridescent;
use ray_tracing_material::microfacet::{BeckmannDistribution, Microfacet};
use ray_tracing_material::mirror::Mirror;
use std::collections::HashMap;
use std::fmt::Debug;
@ -19,9 +22,21 @@ pub fn example_scenes<R: Rng + Debug + 'static>() -> HashMap<&'static str, Box<d
let mut map: HashMap<&str, Box<dyn ExampleScene<R>>> = HashMap::new();
map.insert("basic_cornel", Box::new(basic_cornell::BasicCornell::new()));
map.insert("cornel2", Box::new(cornell2::Cornell2::new()));
let color = Color::new(0.2, 0.2, 0.9);
let material = Microfacet::new(BeckmannDistribution::new(0.01), color);
map.insert(
"stanford_dragon",
Box::new(stanford_dragon::StanfordDragon::new()),
"stanford_dragon_microfacet",
Box::new(stanford_dragon::StanfordDragon::new(material)),
);
let material = Iridescent::new(300.0, 300.0, 1.0, 1.5, 10);
map.insert(
"stanford_dragon_iridescent",
Box::new(stanford_dragon::StanfordDragon::new(material)),
);
let material = Mirror::new(Color::white());
map.insert(
"stanford_dragon_mirror",
Box::new(stanford_dragon::StanfordDragon::new(material)),
);
map.insert(
"stanford_dragon_as",

View file

@ -4,7 +4,7 @@ use ray_tracing_material::{
microfacet::{BeckmannDistribution, Microfacet},
oren_nayar::OrenNayar,
};
use std::cell::OnceCell;
use std::cell::{Cell, OnceCell};
use crate::{
parse_obj::ObjData,
@ -13,19 +13,21 @@ use crate::{
use super::ExampleScene;
pub struct StanfordDragon<R: Rng> {
pub struct StanfordDragon<R: Rng, M: Material<R>> {
scene: OnceCell<TriangleBVH<R>>,
material: Cell<Option<M>>,
}
impl<R: Rng> StanfordDragon<R> {
pub fn new() -> Self {
impl<R: Rng, M: Material<R>> StanfordDragon<R, M> {
pub fn new(material: M) -> Self {
Self {
scene: OnceCell::new(),
material: Cell::new(Some(material)),
}
}
}
impl<R: Rng + 'static> ExampleScene<R> for StanfordDragon<R> {
impl<R: Rng + 'static, M: Material<R> + 'static> ExampleScene<R> for StanfordDragon<R, M> {
fn get_scene(&self) -> Box<dyn Scene<R> + Sync> {
let s = self.scene.get_or_init(|| {
let obj = ObjData::new("ray-tracing-scene/obj/stanford_dragon.obj").unwrap();
@ -35,9 +37,8 @@ impl<R: Rng + 'static> ExampleScene<R> for StanfordDragon<R> {
.map(|t| Triangle::new(t.v, 0))
.collect::<Vec<_>>();
let color = Color::new(0.2, 0.2, 0.9);
let materials = vec![
BVHMaterial::new_material(Microfacet::new(BeckmannDistribution::new(0.01), color)),
BVHMaterial::new_material(self.material.take().unwrap()),
BVHMaterial::new_material(OrenNayar::new(0.5, Color::new(0.8, 0.8, 0.8))),
BVHMaterial::new_material(OrenNayar::new(0.5, Color::new(0.9, 0.0, 0.0))),
BVHMaterial::new_material(OrenNayar::new(0.5, Color::new(0.0, 0.9, 0.0))),