Fix all warnings
This commit is contained in:
parent
2bc5ec93fe
commit
ae4dc2c21a
26 changed files with 249 additions and 185 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use std::fmt::Debug;
|
use std::{fmt::Debug, ops::Deref};
|
||||||
|
|
||||||
/// Trait to model bxdf.
|
/// Trait to model bxdf.
|
||||||
///
|
///
|
||||||
|
|
@ -55,6 +55,20 @@ impl<R: Rng, M: Material<R>> Material<R> for &M {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<R: Rng> Material<R> for std::sync::Arc<dyn Material<R>> {
|
||||||
|
fn eval(&self, w_in: Dir3, w_out: Dir3, rng: &mut R) -> Color {
|
||||||
|
self.deref().eval(w_in, w_out, rng)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sample(&self, w_in: Dir3, rng: &mut R) -> SampleResult {
|
||||||
|
self.deref().sample(w_in, rng)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pdf(&self, w_in: Dir3, w_out: Dir3) -> Float {
|
||||||
|
self.deref().pdf(w_in, w_out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SampleResult {
|
pub struct SampleResult {
|
||||||
w_out: Dir3,
|
w_out: Dir3,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use std::ops::{Add, Index, Mul, Sub};
|
use std::ops::{Add, Index, Sub};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Pos3 {
|
pub struct Pos3 {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,6 @@
|
||||||
use std::sync::{
|
|
||||||
mpsc::{Receiver, Sender},
|
|
||||||
Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use rand::{rngs::SmallRng, SeedableRng};
|
use rand::{rngs::SmallRng, SeedableRng};
|
||||||
use ray_tracing_core::{
|
use ray_tracing_core::{
|
||||||
camera::{BasicCamera, Camera},
|
camera::BasicCamera, prelude::*, renderer::ClassicalRenderer, scene::Scene,
|
||||||
prelude::*,
|
|
||||||
renderer::ClassicalRenderer,
|
|
||||||
scene::Scene,
|
|
||||||
};
|
};
|
||||||
use ray_tracing_renderer::{
|
use ray_tracing_renderer::{
|
||||||
depth_renderer::DepthRenderer, mis::MIS, next_event_estimation::NextEventEstimation,
|
depth_renderer::DepthRenderer, mis::MIS, next_event_estimation::NextEventEstimation,
|
||||||
|
|
@ -19,6 +11,10 @@ use rayon::{
|
||||||
iter::{IndexedParallelIterator, ParallelIterator},
|
iter::{IndexedParallelIterator, ParallelIterator},
|
||||||
slice::ParallelSliceMut,
|
slice::ParallelSliceMut,
|
||||||
};
|
};
|
||||||
|
use std::sync::{
|
||||||
|
mpsc::{Receiver, Sender},
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
|
buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer},
|
||||||
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
|
memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter},
|
||||||
|
|
@ -62,7 +58,7 @@ fn render_pass<
|
||||||
(x + y * settings.width) as u64
|
(x + y * settings.width) as u64
|
||||||
+ (settings.width as u64 * settings.height as u64 * samples as u64),
|
+ (settings.width as u64 * settings.height as u64 * samples as u64),
|
||||||
);
|
);
|
||||||
let r = renderer.render_pixel(&scene, &camera, x, y, &mut rng);
|
let r = renderer.render_pixel(scene, camera, x, y, &mut rng);
|
||||||
c[0] += r.r();
|
c[0] += r.r();
|
||||||
c[1] += r.g();
|
c[1] += r.g();
|
||||||
c[2] += r.b();
|
c[2] += r.b();
|
||||||
|
|
@ -159,6 +155,9 @@ pub fn render_thread(
|
||||||
examples::ExampleSceneEnum::TriangleBVH(s) => {
|
examples::ExampleSceneEnum::TriangleBVH(s) => {
|
||||||
render_pass_renderer(&settings, s, &camera, samples, &mut buffer)
|
render_pass_renderer(&settings, s, &camera, samples, &mut buffer)
|
||||||
}
|
}
|
||||||
|
examples::ExampleSceneEnum::BasicScene(s) => {
|
||||||
|
render_pass_renderer(&settings, s, &camera, samples, &mut buffer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
samples += 1;
|
samples += 1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,5 +66,8 @@ fn main() -> ImageResult<()> {
|
||||||
ray_tracing_scene::examples::ExampleSceneEnum::TriangleBVH(s) => {
|
ray_tracing_scene::examples::ExampleSceneEnum::TriangleBVH(s) => {
|
||||||
render_image(&r, s, &c, "test.exr", 1048)
|
render_image(&r, s, &c, "test.exr", 1048)
|
||||||
}
|
}
|
||||||
|
ray_tracing_scene::examples::ExampleSceneEnum::BasicScene(s) => {
|
||||||
|
render_image(&r, s, &c, "test.exr", 1048)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ impl Iridescent {
|
||||||
let phi = 2.0 * f32::consts::PI * self.n2 * self.d2 * theta2.cos() / l;
|
let phi = 2.0 * f32::consts::PI * self.n2 * self.d2 * theta2.cos() / l;
|
||||||
|
|
||||||
let num_real = r12 * (1.0 - f32::cos(-2.0 * phi));
|
let num_real = r12 * (1.0 - f32::cos(-2.0 * phi));
|
||||||
let num_imag = r12 * (-1.0 * f32::sin(-2.0 * phi));
|
let num_imag = r12 * -f32::sin(-2.0 * phi);
|
||||||
|
|
||||||
let denom_real = 1.0 - r12 * r12 * f32::cos(-2.0 * phi);
|
let denom_real = 1.0 - r12 * r12 * f32::cos(-2.0 * phi);
|
||||||
let denom_imag = 0.0 - r12 * r12 * f32::sin(-2.0 * phi);
|
let denom_imag = 0.0 - r12 * r12 * f32::sin(-2.0 * phi);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ struct Args {
|
||||||
fn main() -> Result<(), miette::Error> {
|
fn main() -> Result<(), miette::Error> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let t = parse_pbrt_v4(args.filename)?;
|
let _t = parse_pbrt_v4(args.filename)?;
|
||||||
|
|
||||||
// dbg!(t);
|
// dbg!(t);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ pub enum Either<A, B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A, B> Either<A, B> {
|
impl<A, B> Either<A, B> {
|
||||||
pub fn map_a<C>(self, f: impl FnOnce(A) -> C) -> Either<C, B> {
|
// pub fn map_a<C>(self, f: impl FnOnce(A) -> C) -> Either<C, B> {
|
||||||
match self {
|
// match self {
|
||||||
Either::A(a) => Either::A(f(a)),
|
// Either::A(a) => Either::A(f(a)),
|
||||||
Either::B(b) => Either::B(b),
|
// Either::B(b) => Either::B(b),
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
pub fn map_b<C>(self, f: impl FnOnce(B) -> C) -> Either<A, C> {
|
pub fn map_b<C>(self, f: impl FnOnce(B) -> C) -> Either<A, C> {
|
||||||
match self {
|
match self {
|
||||||
Either::A(a) => Either::A(a),
|
Either::A(a) => Either::A(a),
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
scene::PbrtScene,
|
scene::PbrtScene,
|
||||||
shape::{Shape, ShapeAlpha, ShapeType},
|
shape::{Shape, ShapeAlpha, ShapeType},
|
||||||
texture::Pbrt_2d_float_texture,
|
|
||||||
tokenizer::Tokenizer,
|
tokenizer::Tokenizer,
|
||||||
};
|
};
|
||||||
use error::SourceFile;
|
|
||||||
use material::PbrtMaterial;
|
use material::PbrtMaterial;
|
||||||
use miette::{Diagnostic, IntoDiagnostic, Result, SourceSpan, bail, miette};
|
use miette::{IntoDiagnostic, Result, bail, miette};
|
||||||
use ray_tracing_core::{
|
use ray_tracing_core::{
|
||||||
affine_transform::AffineTransform,
|
affine_transform::AffineTransform,
|
||||||
math::{Dir3, Pos3},
|
math::{Dir3, Pos3},
|
||||||
|
|
@ -18,7 +16,6 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use texture::PbrtTexture;
|
use texture::PbrtTexture;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod tokenizer;
|
mod tokenizer;
|
||||||
|
|
@ -43,6 +40,7 @@ impl Lexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
enum CameraType {
|
enum CameraType {
|
||||||
Orthographic {
|
Orthographic {
|
||||||
frame_aspect_ratio: Option<Float>,
|
frame_aspect_ratio: Option<Float>,
|
||||||
|
|
@ -60,6 +58,7 @@ enum CameraType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct PbrtCamera {
|
struct PbrtCamera {
|
||||||
camera_type: CameraType,
|
camera_type: CameraType,
|
||||||
shutter_open: Float,
|
shutter_open: Float,
|
||||||
|
|
@ -465,8 +464,8 @@ fn parse_transform(input: &mut Tokenizer) -> Result<AffineTransform> {
|
||||||
|
|
||||||
let mut v = [0.0; 16];
|
let mut v = [0.0; 16];
|
||||||
|
|
||||||
for i in 0..16 {
|
for i in &mut v {
|
||||||
v[i] = input
|
*i = input
|
||||||
.next()
|
.next()
|
||||||
.ok_or(miette!("value expected"))??
|
.ok_or(miette!("value expected"))??
|
||||||
.parse::<Float>()
|
.parse::<Float>()
|
||||||
|
|
@ -618,7 +617,8 @@ impl Pbrt {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct PbrtWorldSettings {
|
#[allow(dead_code)]
|
||||||
|
pub struct PbrtWorldSettings {
|
||||||
camera: PbrtCamera,
|
camera: PbrtCamera,
|
||||||
camera_ctm: AffineTransform,
|
camera_ctm: AffineTransform,
|
||||||
}
|
}
|
||||||
|
|
@ -747,7 +747,7 @@ fn inner_parse_pbrt(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Pbrt> {
|
||||||
match p {
|
match p {
|
||||||
Statement::AttributeBegin => context.push(),
|
Statement::AttributeBegin => context.push(),
|
||||||
Statement::AttributeEnd => {
|
Statement::AttributeEnd => {
|
||||||
context.pop();
|
context.pop()?;
|
||||||
}
|
}
|
||||||
Statement::Include(_) => unreachable!(),
|
Statement::Include(_) => unreachable!(),
|
||||||
Statement::ConcatTransform(affine_transform) => {
|
Statement::ConcatTransform(affine_transform) => {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use ray_tracing_core::color::Color;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
either::Either,
|
either::Either,
|
||||||
texture::{Pbrt_2d_float_texture, Pbrt_2d_spectrum_texture, parse_rgb},
|
texture::{Pbrt2dFloatTexture, Pbrt2dSpectrumTexture, parse_rgb},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -24,40 +24,45 @@ pub fn parse_make_named_material(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct PbrtCoatedDiffuseMaterial {
|
struct PbrtCoatedDiffuseMaterial {
|
||||||
albedo: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
|
albedo: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
|
||||||
g: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
g: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
maxdepth: usize,
|
maxdepth: usize,
|
||||||
nsamples: usize,
|
nsamples: usize,
|
||||||
thickness: Float,
|
thickness: Float,
|
||||||
roughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
roughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
uroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
uroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
vroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
vroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
reflectance: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
|
reflectance: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
eta: Either<
|
eta: Either<
|
||||||
Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
|
Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
|
||||||
>,
|
>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtMaterial for PbrtCoatedDiffuseMaterial {}
|
impl PbrtMaterial for PbrtCoatedDiffuseMaterial {}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct PbrtDielectricMaterial {
|
struct PbrtDielectricMaterial {
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
eta: Either<
|
eta: Either<
|
||||||
Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
|
Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
|
||||||
>,
|
>,
|
||||||
roughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
roughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
uroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
uroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
vroughness: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
vroughness: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtMaterial for PbrtDielectricMaterial {}
|
impl PbrtMaterial for PbrtDielectricMaterial {}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct PbrtDiffuseMaterial {
|
struct PbrtDiffuseMaterial {
|
||||||
reflectance: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
|
reflectance: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtMaterial for PbrtDiffuseMaterial {}
|
impl PbrtMaterial for PbrtDiffuseMaterial {}
|
||||||
|
|
@ -65,7 +70,7 @@ impl PbrtMaterial for PbrtDiffuseMaterial {}
|
||||||
fn parse_2d_float_texture(
|
fn parse_2d_float_texture(
|
||||||
input: &mut Tokenizer,
|
input: &mut Tokenizer,
|
||||||
context: &PbrtContext,
|
context: &PbrtContext,
|
||||||
) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
|
) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
|
||||||
let n = input.parse_parameter()?;
|
let n = input.parse_parameter()?;
|
||||||
|
|
||||||
context
|
context
|
||||||
|
|
@ -77,7 +82,7 @@ fn parse_2d_float_texture(
|
||||||
fn parse_2d_spectrum_texture(
|
fn parse_2d_spectrum_texture(
|
||||||
input: &mut Tokenizer,
|
input: &mut Tokenizer,
|
||||||
context: &PbrtContext,
|
context: &PbrtContext,
|
||||||
) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
|
) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
|
||||||
let n = input.parse_parameter()?;
|
let n = input.parse_parameter()?;
|
||||||
|
|
||||||
context
|
context
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ impl<R: Rng> Scene<R> for PbrtScene {
|
||||||
R: 'a;
|
R: 'a;
|
||||||
|
|
||||||
fn intersect(
|
fn intersect(
|
||||||
&self,
|
&'_ self,
|
||||||
ray: ray_tracing_core::prelude::Ray,
|
ray: ray_tracing_core::prelude::Ray,
|
||||||
min: ray_tracing_core::prelude::Float,
|
min: ray_tracing_core::prelude::Float,
|
||||||
max: ray_tracing_core::prelude::Float,
|
max: ray_tracing_core::prelude::Float,
|
||||||
) -> Option<ray_tracing_core::scene::Intersection<R, Self::Mat<'_>>> {
|
) -> Option<ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'_>>> {
|
||||||
let mut i = None;
|
let mut i = None;
|
||||||
for s in &self.shapes {
|
for s in &self.shapes {
|
||||||
if let Some(new_i) = s.intersect::<R>(ray, min, max)
|
if let Some(new_i) = s.intersect::<R>(ray, min, max)
|
||||||
|
|
@ -40,9 +40,9 @@ impl<R: Rng> Scene<R> for PbrtScene {
|
||||||
|
|
||||||
fn sample_light<'b>(
|
fn sample_light<'b>(
|
||||||
&self,
|
&self,
|
||||||
w_in: ray_tracing_core::prelude::Dir3,
|
_w_in: ray_tracing_core::prelude::Dir3,
|
||||||
intersection: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'b>>,
|
_intersection: &ray_tracing_core::scene::Intersection<'_, R, Self::Mat<'b>>,
|
||||||
rng: &mut R,
|
_rng: &mut R,
|
||||||
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
|
) -> Option<ray_tracing_core::scene::LightSample<'_, R>>
|
||||||
where
|
where
|
||||||
Self: 'b,
|
Self: 'b,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use ray_tracing_core::{affine_transform::AffineTransform, prelude::*, scene::Int
|
||||||
use crate::material::PbrtMaterial;
|
use crate::material::PbrtMaterial;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct Shape {
|
pub(crate) struct Shape {
|
||||||
pub(crate) ctm: AffineTransform,
|
pub(crate) ctm: AffineTransform,
|
||||||
pub(crate) material: Arc<dyn PbrtMaterial>,
|
pub(crate) material: Arc<dyn PbrtMaterial>,
|
||||||
|
|
@ -13,6 +14,7 @@ pub(crate) struct Shape {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) enum ShapeAlpha {
|
pub(crate) enum ShapeAlpha {
|
||||||
None,
|
None,
|
||||||
Value(Float),
|
Value(Float),
|
||||||
|
|
@ -20,6 +22,7 @@ pub(crate) enum ShapeAlpha {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) enum ShapeType {
|
pub(crate) enum ShapeType {
|
||||||
Sphere {
|
Sphere {
|
||||||
radius: Float,
|
radius: Float,
|
||||||
|
|
@ -115,7 +118,7 @@ fn bilinear_intersection(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter(|&u| {
|
.filter(|&u| {
|
||||||
if 0.0 <= u && u <= 1.0 {
|
if (0.0..=1.0).contains(&u) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
@ -146,7 +149,7 @@ fn bilinear_intersection(
|
||||||
- ud.x() * deltao.y() * perp.z()
|
- ud.x() * deltao.y() * perp.z()
|
||||||
- perp.x() * ud.y() * deltao.z();
|
- perp.x() * ud.y() * deltao.z();
|
||||||
|
|
||||||
if t1 > 0.0 && 0.0 < v1 && v1 <= p2 {
|
if t1 >= min && t1 <= max && 0.0 < v1 && v1 <= p2 {
|
||||||
Some((t1 / p2, u, v1 / p2))
|
Some((t1 / p2, u, v1 / p2))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -157,11 +160,11 @@ fn bilinear_intersection(
|
||||||
|
|
||||||
impl Shape {
|
impl Shape {
|
||||||
pub(crate) fn intersect<R: Rng>(
|
pub(crate) fn intersect<R: Rng>(
|
||||||
&self,
|
&'_ self,
|
||||||
ray: Ray,
|
ray: Ray,
|
||||||
min: Float,
|
min: Float,
|
||||||
max: Float,
|
max: Float,
|
||||||
) -> Option<Intersection<R, &'_ dyn Material<R>>> {
|
) -> Option<Intersection<'_, R, &'_ dyn Material<R>>> {
|
||||||
let ray = self.ctm.transform_ray(ray);
|
let ray = self.ctm.transform_ray(ray);
|
||||||
|
|
||||||
match &self.obj {
|
match &self.obj {
|
||||||
|
|
@ -220,14 +223,13 @@ impl Shape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShapeType::TriangleMesh {
|
ShapeType::TriangleMesh { .. } => (),
|
||||||
|
ShapeType::BilinearMesh {
|
||||||
indices,
|
indices,
|
||||||
p,
|
p,
|
||||||
n,
|
n: _,
|
||||||
s,
|
uv: _,
|
||||||
uv,
|
} => {
|
||||||
} => (),
|
|
||||||
ShapeType::BilinearMesh { indices, p, n, uv } => {
|
|
||||||
if indices.is_empty()
|
if indices.is_empty()
|
||||||
&& let Some((t, _u, _v)) =
|
&& let Some((t, _u, _v)) =
|
||||||
bilinear_intersection(ray, min, max, [p[0], p[1], p[2], p[3]])
|
bilinear_intersection(ray, min, max, [p[0], p[1], p[2], p[3]])
|
||||||
|
|
@ -235,18 +237,9 @@ impl Shape {
|
||||||
return Some(Intersection::new(t, Dir3::up(), None, None, 0.0));
|
return Some(Intersection::new(t, Dir3::up(), None, None, 0.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShapeType::LoopSubDiv { levels, indices, p } => todo!(),
|
ShapeType::LoopSubDiv { .. } => todo!(),
|
||||||
ShapeType::Disk {
|
ShapeType::Disk { .. } => (),
|
||||||
height,
|
ShapeType::PlyMesh { .. } => (),
|
||||||
radius,
|
|
||||||
innerradius,
|
|
||||||
phimax,
|
|
||||||
} => (),
|
|
||||||
ShapeType::PlyMesh {
|
|
||||||
filename,
|
|
||||||
displacement,
|
|
||||||
edgelength,
|
|
||||||
} => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
|
use crate::{PbrtContext, either::Either, tokenizer::Tokenizer};
|
||||||
use imagemap::{ImageMapEncoding, ImageMapWrap, SpectrumImageMapTexture};
|
use imagemap::{ImageMapEncoding, ImageMapWrap, SpectrumImageMapTexture};
|
||||||
use miette::{Result, miette};
|
use miette::{Result, miette};
|
||||||
use ray_tracing_core::{affine_transform::AffineTransform, color::Color, prelude::Float};
|
use ray_tracing_core::{color::Color, prelude::Float};
|
||||||
use scale::SpectrumScaleTexture2d;
|
use scale::SpectrumScaleTexture2d;
|
||||||
use std::{collections::HashMap, ops::Deref, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{PbrtContext, either::Either, tokenizer::Tokenizer};
|
|
||||||
|
|
||||||
mod checkerboard;
|
mod checkerboard;
|
||||||
mod imagemap;
|
mod imagemap;
|
||||||
|
|
@ -12,20 +11,20 @@ mod scale;
|
||||||
|
|
||||||
pub trait PbrtTexture: std::fmt::Debug + Send + Sync {
|
pub trait PbrtTexture: std::fmt::Debug + Send + Sync {
|
||||||
fn get_dimension(&self) -> TextureDimension;
|
fn get_dimension(&self) -> TextureDimension;
|
||||||
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>>;
|
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>>;
|
||||||
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>>;
|
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Pbrt_2d_float_texture: std::fmt::Debug + Sync + Send {
|
pub trait Pbrt2dFloatTexture: std::fmt::Debug + Sync + Send {
|
||||||
fn get(&self, u: Float, v: Float) -> Float;
|
fn get(&self, u: Float, v: Float) -> Float;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Pbrt_2d_spectrum_texture: std::fmt::Debug + Sync + Send {
|
pub trait Pbrt2dSpectrumTexture: std::fmt::Debug + Sync + Send {
|
||||||
fn get(&self, u: Float, v: Float) -> Color;
|
fn get(&self, u: Float, v: Float) -> Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum TextureDimension {
|
pub enum TextureDimension {
|
||||||
D2,
|
D2,
|
||||||
D3,
|
D3,
|
||||||
}
|
}
|
||||||
|
|
@ -57,6 +56,7 @@ impl TextureMapping {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_spectrum(input: &mut Tokenizer) -> Result<Color> {
|
pub fn parse_spectrum(input: &mut Tokenizer) -> Result<Color> {
|
||||||
|
let _ = input;
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +71,67 @@ fn parse_float_texture(
|
||||||
) -> Result<Arc<dyn PbrtTexture>> {
|
) -> Result<Arc<dyn PbrtTexture>> {
|
||||||
let texture_class: String = input.parse_next()?;
|
let texture_class: String = input.parse_next()?;
|
||||||
|
|
||||||
dbg!(texture_class);
|
match texture_class.as_str() {
|
||||||
todo!()
|
"\"checkerboard\"" => {
|
||||||
|
let t = parse_dict!(input =>
|
||||||
|
mapping, TextureMapping, TextureMapping::UV;
|
||||||
|
uscale, Float, 1.0;
|
||||||
|
vscale, Float, 1.0;
|
||||||
|
udelta, Float, 0.0;
|
||||||
|
vdelta, Float, 0.0;
|
||||||
|
dimension, TextureDimension, TextureDimension::D2;
|
||||||
|
tex1, Either<Float, String>, Either::A(1.0);
|
||||||
|
tex2, Either<Float, String>, Either::A(0.0)
|
||||||
|
=>
|
||||||
|
mapping, "\"string mapping\"", TextureMapping::new(input.parse_parameter()?)?;
|
||||||
|
uscale, "\"float uscale\"", input.parse_parameter()?;
|
||||||
|
vscale, "\"float vscale\"", input.parse_parameter()?;
|
||||||
|
udelta, "\"float udelta\"", input.parse_parameter()?;
|
||||||
|
vdelta, "\"float vdelta\"", input.parse_parameter()?;
|
||||||
|
dimension, "\"integer dimension\"", TextureDimension::new(input.parse_parameter()?)?;
|
||||||
|
tex1, "\"float tex1\"", Either::A(input.parse_parameter()?);
|
||||||
|
tex1, "\"texture tex1\"", Either::B(input.parse_parameter()?);
|
||||||
|
tex2, "\"float tex2\"", Either::A(input.parse_parameter()?);
|
||||||
|
tex2, "\"texture tex2\"", Either::B(input.parse_parameter()?)
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
let mapping = UVMapping::new(t.mapping, t.uscale, t.vscale, t.udelta, t.vdelta);
|
||||||
|
|
||||||
|
match t.dimension {
|
||||||
|
TextureDimension::D2 => Ok(Arc::new(checkerboard::FloatCheckerboardTexture2d {
|
||||||
|
mapping,
|
||||||
|
tex: [
|
||||||
|
t.tex1
|
||||||
|
.map_b(|name| {
|
||||||
|
Arc::clone(
|
||||||
|
context
|
||||||
|
.get_texture(&name)
|
||||||
|
.ok_or_else(|| miette!("unable to find texture"))?,
|
||||||
|
)
|
||||||
|
.get_2d_float_texture()
|
||||||
|
})
|
||||||
|
.transpose_b()?,
|
||||||
|
t.tex2
|
||||||
|
.map_b(|name| {
|
||||||
|
Arc::clone(
|
||||||
|
context
|
||||||
|
.get_texture(&name)
|
||||||
|
.ok_or_else(|| miette!("unable to find texture"))?,
|
||||||
|
)
|
||||||
|
.get_2d_float_texture()
|
||||||
|
})
|
||||||
|
.transpose_b()?,
|
||||||
|
],
|
||||||
|
})),
|
||||||
|
TextureDimension::D3 => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => Err(miette!("unknown error {texture_class}")),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_spectrum_texture(
|
fn parse_spectrum_texture(
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ use super::*;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct FloatCheckerboardTexture2d {
|
pub(super) struct FloatCheckerboardTexture2d {
|
||||||
pub(super) mapping: UVMapping,
|
pub(super) mapping: UVMapping,
|
||||||
pub(super) tex: [Either<Float, Arc<dyn Pbrt_2d_float_texture>>; 2],
|
pub(super) tex: [Either<Float, Arc<dyn Pbrt2dFloatTexture>>; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pbrt_2d_float_texture for FloatCheckerboardTexture2d {
|
impl Pbrt2dFloatTexture for FloatCheckerboardTexture2d {
|
||||||
fn get(&self, u: Float, v: Float) -> Float {
|
fn get(&self, u: Float, v: Float) -> Float {
|
||||||
let (u, v) = self.mapping.map(u, v);
|
let (u, v) = self.mapping.map(u, v);
|
||||||
|
|
||||||
|
|
@ -28,11 +28,11 @@ impl Pbrt_2d_float_texture for FloatCheckerboardTexture2d {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtTexture for FloatCheckerboardTexture2d {
|
impl PbrtTexture for FloatCheckerboardTexture2d {
|
||||||
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
|
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
|
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
|
||||||
Err(miette!("Unable to use this texture as a spectrum texture"))
|
Err(miette!("Unable to use this texture as a spectrum texture"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,10 +43,10 @@ impl PbrtTexture for FloatCheckerboardTexture2d {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct SpectrumCheckerboardTexture2d {
|
pub(super) struct SpectrumCheckerboardTexture2d {
|
||||||
pub(super) mapping: UVMapping,
|
pub(super) mapping: UVMapping,
|
||||||
pub(super) tex: [Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>; 2],
|
pub(super) tex: [Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pbrt_2d_spectrum_texture for SpectrumCheckerboardTexture2d {
|
impl Pbrt2dSpectrumTexture for SpectrumCheckerboardTexture2d {
|
||||||
fn get(&self, u: Float, v: Float) -> Color {
|
fn get(&self, u: Float, v: Float) -> Color {
|
||||||
let (u, v) = self.mapping.map(u, v);
|
let (u, v) = self.mapping.map(u, v);
|
||||||
|
|
||||||
|
|
@ -68,11 +68,11 @@ impl Pbrt_2d_spectrum_texture for SpectrumCheckerboardTexture2d {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtTexture for SpectrumCheckerboardTexture2d {
|
impl PbrtTexture for SpectrumCheckerboardTexture2d {
|
||||||
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
|
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
|
||||||
Err(miette!("Unable to use this texture as a float texture"))
|
Err(miette!("Unable to use this texture as a float texture"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
|
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ impl ImageMapWrap {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) enum ImageMapEncoding {
|
pub(super) enum ImageMapEncoding {
|
||||||
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
SRGB,
|
SRGB,
|
||||||
Linear,
|
Linear,
|
||||||
Gamma(Float),
|
Gamma(Float),
|
||||||
|
|
@ -118,22 +119,23 @@ impl SpectrumImageMapTexture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pbrt_2d_spectrum_texture for SpectrumImageMapTexture {
|
impl Pbrt2dSpectrumTexture for SpectrumImageMapTexture {
|
||||||
fn get(&self, u: Float, v: Float) -> Color {
|
fn get(&self, u: Float, v: Float) -> Color {
|
||||||
let (u, v) = self.mapping.map(u, v);
|
let (u, v) = self.mapping.map(u, v);
|
||||||
|
|
||||||
let (w, h) = self.image.dimensions();
|
let (w, h) = self.image.dimensions();
|
||||||
|
|
||||||
|
dbg!(u, v, w, h);
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtTexture for SpectrumImageMapTexture {
|
impl PbrtTexture for SpectrumImageMapTexture {
|
||||||
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
|
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
|
||||||
Err(miette!("Unable to use this texture as a float texture"))
|
Err(miette!("Unable to use this texture as a float texture"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
|
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use super::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct SpectrumScaleTexture2d {
|
pub(super) struct SpectrumScaleTexture2d {
|
||||||
pub(super) tex: Either<Color, Arc<dyn Pbrt_2d_spectrum_texture>>,
|
pub(super) tex: Either<Color, Arc<dyn Pbrt2dSpectrumTexture>>,
|
||||||
pub(super) scale: Either<Float, Arc<dyn Pbrt_2d_float_texture>>,
|
pub(super) scale: Either<Float, Arc<dyn Pbrt2dFloatTexture>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PbrtTexture for SpectrumScaleTexture2d {
|
impl PbrtTexture for SpectrumScaleTexture2d {
|
||||||
|
|
@ -11,16 +11,16 @@ impl PbrtTexture for SpectrumScaleTexture2d {
|
||||||
TextureDimension::D2
|
TextureDimension::D2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_float_texture>> {
|
fn get_2d_float_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dFloatTexture>> {
|
||||||
Err(miette!("Unable to convert to float texture"))
|
Err(miette!("Unable to convert to float texture"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt_2d_spectrum_texture>> {
|
fn get_2d_spectrum_texture(self: Arc<Self>) -> Result<Arc<dyn Pbrt2dSpectrumTexture>> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pbrt_2d_spectrum_texture for SpectrumScaleTexture2d {
|
impl Pbrt2dSpectrumTexture for SpectrumScaleTexture2d {
|
||||||
fn get(&self, u: Float, v: Float) -> Color {
|
fn get(&self, u: Float, v: Float) -> Color {
|
||||||
let x = match &self.tex {
|
let x = match &self.tex {
|
||||||
Either::A(x) => *x,
|
Either::A(x) => *x,
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
use crate::{
|
use crate::{BytesToChar, error::SourceFile};
|
||||||
BytesToChar, PbrtContext, either::Either, error::SourceFile, texture::Pbrt_2d_float_texture,
|
use miette::{Diagnostic, IntoDiagnostic, Report, Result, SourceSpan};
|
||||||
};
|
|
||||||
use const_format::concatcp;
|
|
||||||
use miette::{Diagnostic, Error, IntoDiagnostic, Report, Result, SourceSpan};
|
|
||||||
use ray_tracing_core::prelude::Float;
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufReader, Bytes, Read},
|
io::{BufReader, Bytes, Read},
|
||||||
iter::Peekable,
|
iter::Peekable,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -32,10 +27,6 @@ impl Tokenizer {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_path(&self) -> &Path {
|
|
||||||
&self.path
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_base_path(&self) -> &Path {
|
pub fn get_base_path(&self) -> &Path {
|
||||||
&self.base_path
|
&self.base_path
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
use std::cell::OnceCell;
|
use super::ExampleScene;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
examples::ExampleSceneEnum,
|
examples::ExampleSceneEnum,
|
||||||
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
||||||
};
|
};
|
||||||
|
use ray_tracing_core::{light::AreaLight, prelude::*};
|
||||||
use super::ExampleScene;
|
|
||||||
|
|
||||||
use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene};
|
|
||||||
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
||||||
|
use std::cell::OnceCell;
|
||||||
|
|
||||||
pub struct BasicCornell<R: Rng> {
|
pub struct BasicCornell<R: Rng> {
|
||||||
scene: OnceCell<TriangleBVH<R>>,
|
scene: OnceCell<TriangleBVH<R>>,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene};
|
use ray_tracing_core::{light::AreaLight, prelude::*};
|
||||||
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
||||||
use std::cell::OnceCell;
|
use std::cell::OnceCell;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
examples::ExampleSceneEnum,
|
examples::ExampleSceneEnum,
|
||||||
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
||||||
};
|
};
|
||||||
use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene};
|
use ray_tracing_core::{light::AreaLight, prelude::*};
|
||||||
use ray_tracing_material::{
|
use ray_tracing_material::{
|
||||||
microfacet::{BeckmannDistribution, Microfacet},
|
microfacet::{BeckmannDistribution, Microfacet},
|
||||||
mirror::Mirror,
|
mirror::Mirror,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
use ray_tracing_core::{prelude::*, scene::Scene};
|
use crate::acceleration_structure::{triangle_bvh::TriangleBVH, AccelerationStructureScene};
|
||||||
use ray_tracing_material::iridescent::Iridescent;
|
use ray_tracing_core::prelude::*;
|
||||||
use ray_tracing_material::microfacet::{BeckmannDistribution, Microfacet};
|
use ray_tracing_material::{
|
||||||
use ray_tracing_material::mirror::Mirror;
|
iridescent::Iridescent,
|
||||||
use std::collections::HashMap;
|
microfacet::{BeckmannDistribution, Microfacet},
|
||||||
use std::fmt::Debug;
|
mirror::Mirror,
|
||||||
|
};
|
||||||
use crate::acceleration_structure::triangle_bvh::TriangleBVH;
|
use std::{collections::HashMap, fmt::Debug, sync::Arc};
|
||||||
use crate::acceleration_structure::AccelerationStructureScene;
|
|
||||||
use crate::basic_scene::BasicScene;
|
|
||||||
|
|
||||||
pub enum ExampleSceneEnum<R: Rng> {
|
pub enum ExampleSceneEnum<R: Rng> {
|
||||||
AccelerationStructureScene(AccelerationStructureScene<TriangleBVH<u32>, R>),
|
AccelerationStructureScene(AccelerationStructureScene<TriangleBVH<u32>, R>),
|
||||||
TriangleBVH(crate::triangle_bvh::TriangleBVH<R>),
|
TriangleBVH(crate::triangle_bvh::TriangleBVH<R>),
|
||||||
|
BasicScene(crate::basic_scene::BasicScene<Arc<dyn Material<R>>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ExampleScene<R: Rng> {
|
pub trait ExampleScene<R: Rng> {
|
||||||
|
|
@ -59,8 +58,8 @@ pub fn example_scenes<R: Rng + Debug + 'static>() -> HashMap<&'static str, Box<d
|
||||||
map.insert("mis_test", Box::new(mis_test::MISTest::new()));
|
map.insert("mis_test", Box::new(mis_test::MISTest::new()));
|
||||||
|
|
||||||
// let material = Iridescent::new(250.0, 250.0, 1.0, 1.3, 20);
|
// let material = Iridescent::new(250.0, 250.0, 1.0, 1.3, 20);
|
||||||
// let material = Iridescent::new(0.9 * 988.0, 0.1 * 988.0, 1.0, 1.5, 20);
|
let material = Iridescent::new(0.9 * 988.0, 0.1 * 988.0, 1.0, 1.5, 20);
|
||||||
// map.insert("sphere", Box::new(sphere::SphereScene::new(material)));
|
map.insert("sphere", Box::new(sphere::SphereScene::new(material)));
|
||||||
|
|
||||||
map.insert(
|
map.insert(
|
||||||
"presentation",
|
"presentation",
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use ray_tracing_core::{
|
||||||
color::Color,
|
color::Color,
|
||||||
light::AreaLight,
|
light::AreaLight,
|
||||||
math::{Dir3, Pos3},
|
math::{Dir3, Pos3},
|
||||||
prelude::{Float, Material},
|
prelude::Float,
|
||||||
};
|
};
|
||||||
use ray_tracing_material::{iridescent::Iridescent, oren_nayar::OrenNayar};
|
use ray_tracing_material::{iridescent::Iridescent, oren_nayar::OrenNayar};
|
||||||
use std::cell::OnceCell;
|
use std::cell::OnceCell;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
use super::ExampleScene;
|
use super::ExampleScene;
|
||||||
use crate::{basic_scene::BasicScene, examples::ExampleSceneEnum};
|
use crate::{basic_scene::BasicScene, examples::ExampleSceneEnum};
|
||||||
use ray_tracing_core::prelude::*;
|
use ray_tracing_core::prelude::*;
|
||||||
use std::cell::{Cell, OnceCell};
|
use std::{
|
||||||
|
cell::{Cell, OnceCell},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct SphereScene<M> {
|
pub struct SphereScene<R: Rng, M> {
|
||||||
scene: OnceCell<BasicScene<M>>,
|
scene: OnceCell<BasicScene<Arc<dyn Material<R>>>>,
|
||||||
material: Cell<Option<M>>,
|
material: Cell<Option<M>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M> SphereScene<M> {
|
impl<R: Rng, M> SphereScene<R, M> {
|
||||||
pub fn new(material: M) -> Self {
|
pub fn new(material: M) -> Self {
|
||||||
Self {
|
Self {
|
||||||
scene: OnceCell::new(),
|
scene: OnceCell::new(),
|
||||||
|
|
@ -17,33 +20,33 @@ impl<M> SphereScene<M> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<R, M> ExampleScene<R> for SphereScene<M>
|
impl<R, M> ExampleScene<R> for SphereScene<R, M>
|
||||||
// where
|
where
|
||||||
// R: Rng + 'static,
|
R: Rng + 'static,
|
||||||
// M: Material<R> + Clone + 'static,
|
M: Material<R> + Clone + 'static,
|
||||||
// M: Send + Sync,
|
M: Send + Sync,
|
||||||
// {
|
{
|
||||||
// fn get_scene(&self) -> ExampleSceneEnum<R> {
|
fn get_scene(&self) -> ExampleSceneEnum<R> {
|
||||||
// let s = self
|
let s = self
|
||||||
// .scene
|
.scene
|
||||||
// .get_or_init(|| BasicScene::new(self.material.take().unwrap()));
|
.get_or_init(|| BasicScene::new(Arc::new(self.material.take().unwrap())));
|
||||||
|
|
||||||
// ExampleSceneEnum::BasicScene(s.clone())
|
ExampleSceneEnum::BasicScene(s.clone())
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn get_camera_pos(&self) -> Pos3 {
|
fn get_camera_pos(&self) -> Pos3 {
|
||||||
// Pos3::new(5.0, 1.0, 0.0)
|
Pos3::new(5.0, 1.0, 0.0)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn get_camera_look_at(&self) -> Pos3 {
|
fn get_camera_look_at(&self) -> Pos3 {
|
||||||
// Pos3::new(0.0, 0.0, 0.0)
|
Pos3::new(0.0, 0.0, 0.0)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn get_camera_up(&self) -> Dir3 {
|
fn get_camera_up(&self) -> Dir3 {
|
||||||
// Dir3::up()
|
Dir3::up()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn get_horizontal_fov(&self) -> Float {
|
fn get_horizontal_fov(&self) -> Float {
|
||||||
// Float::to_radians(90.0)
|
Float::to_radians(90.0)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
|
use super::ExampleScene;
|
||||||
use crate::{
|
use crate::{
|
||||||
examples::ExampleSceneEnum,
|
examples::ExampleSceneEnum,
|
||||||
parse_obj::ObjData,
|
parse_obj::ObjData,
|
||||||
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene};
|
use ray_tracing_core::{light::AreaLight, prelude::*};
|
||||||
use ray_tracing_material::oren_nayar::OrenNayar;
|
use ray_tracing_material::oren_nayar::OrenNayar;
|
||||||
use std::cell::{Cell, OnceCell};
|
use std::cell::{Cell, OnceCell};
|
||||||
|
|
||||||
use super::ExampleScene;
|
|
||||||
|
|
||||||
pub struct StanfordDragon<R: Rng, M: Material<R>> {
|
pub struct StanfordDragon<R: Rng, M: Material<R>> {
|
||||||
scene: OnceCell<TriangleBVH<R>>,
|
scene: OnceCell<TriangleBVH<R>>,
|
||||||
material: Cell<Option<M>>,
|
material: Cell<Option<M>>,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
use rand::Rng;
|
use super::ExampleScene;
|
||||||
use ray_tracing_core::{light::AreaLight, prelude::*, scene::Scene};
|
|
||||||
use ray_tracing_material::{
|
|
||||||
microfacet::{BeckmannDistribution, Microfacet},
|
|
||||||
oren_nayar::OrenNayar,
|
|
||||||
};
|
|
||||||
use std::cell::OnceCell;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
acceleration_structure::{
|
acceleration_structure::{
|
||||||
triangle_bvh::{Triangle, TriangleBVH},
|
triangle_bvh::{Triangle, TriangleBVH},
|
||||||
|
|
@ -14,8 +7,13 @@ use crate::{
|
||||||
examples::ExampleSceneEnum,
|
examples::ExampleSceneEnum,
|
||||||
parse_obj::ObjData,
|
parse_obj::ObjData,
|
||||||
};
|
};
|
||||||
|
use rand::Rng;
|
||||||
use super::ExampleScene;
|
use ray_tracing_core::{light::AreaLight, prelude::*};
|
||||||
|
use ray_tracing_material::{
|
||||||
|
microfacet::{BeckmannDistribution, Microfacet},
|
||||||
|
oren_nayar::OrenNayar,
|
||||||
|
};
|
||||||
|
use std::cell::OnceCell;
|
||||||
|
|
||||||
pub struct StanfordDragon<R: Rng> {
|
pub struct StanfordDragon<R: Rng> {
|
||||||
scene: OnceCell<AccelerationStructureScene<TriangleBVH<u32>, R>>,
|
scene: OnceCell<AccelerationStructureScene<TriangleBVH<u32>, R>>,
|
||||||
|
|
|
||||||
|
|
@ -69,19 +69,19 @@ fn parse_float(i: &str) -> IResult<&str, Float> {
|
||||||
double(i).map(|(i, f)| (i, f as Float))
|
double(i).map(|(i, f)| (i, f as Float))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_vertex(i: &str) -> IResult<&str, Line> {
|
fn parse_vertex(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
let mut v = [0.0; 3];
|
let mut v = [0.0; 3];
|
||||||
let (i, _) = fill(parse_float, &mut v)(i)?;
|
let (i, _) = fill(parse_float, &mut v)(i)?;
|
||||||
Ok((i, Line::Vertex(Pos3::new(v[0], v[1], v[2]))))
|
Ok((i, Line::Vertex(Pos3::new(v[0], v[1], v[2]))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_normal(i: &str) -> IResult<&str, Line> {
|
fn parse_normal(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
let mut v = [0.0; 3];
|
let mut v = [0.0; 3];
|
||||||
let (i, _) = fill(parse_float, &mut v)(i)?;
|
let (i, _) = fill(parse_float, &mut v)(i)?;
|
||||||
Ok((i, Line::Normal(Dir3::new(v[0], v[1], v[2]))))
|
Ok((i, Line::Normal(Dir3::new(v[0], v[1], v[2]))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_texcoord(i: &str) -> IResult<&str, Line> {
|
fn parse_texcoord(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
let mut v = [0.0; 2];
|
let mut v = [0.0; 2];
|
||||||
let (i, _) = fill(parse_float, &mut v)(i)?;
|
let (i, _) = fill(parse_float, &mut v)(i)?;
|
||||||
Ok((i, Line::Texcoord(v)))
|
Ok((i, Line::Texcoord(v)))
|
||||||
|
|
@ -125,7 +125,7 @@ fn face_vertex_normal_tex(i: &str) -> IResult<&str, (i32, i32, i32)> {
|
||||||
Ok((i, (v, t, n)))
|
Ok((i, (v, t, n)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_face(i: &str) -> IResult<&str, Line> {
|
fn parse_face(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
if let Ok((i, s)) = many1(face_vertex_normal_tex)(i) {
|
if let Ok((i, s)) = many1(face_vertex_normal_tex)(i) {
|
||||||
if s.len() >= 3 {
|
if s.len() >= 3 {
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -198,17 +198,17 @@ fn parse_face(i: &str) -> IResult<&str, Line> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_mtllib(i: &str) -> IResult<&str, Line> {
|
fn parse_mtllib(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
let (i, s) = take_till(|c| c == ' ')(i)?;
|
let (i, s) = take_till(|c| c == ' ')(i)?;
|
||||||
Ok((i, Line::Mtllib(s)))
|
Ok((i, Line::Mtllib(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_mtl(i: &str) -> IResult<&str, Line> {
|
fn parse_mtl(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
let (i, s) = take_till(|c| c == ' ')(i)?;
|
let (i, s) = take_till(|c| c == ' ')(i)?;
|
||||||
Ok((i, Line::Material(s)))
|
Ok((i, Line::Material(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_line(i: &str) -> IResult<&str, Line> {
|
fn parse_line(i: &'_ str) -> IResult<&'_ str, Line<'_>> {
|
||||||
let (i, ident) = parse_identifier(i)?;
|
let (i, ident) = parse_identifier(i)?;
|
||||||
let (i, _) = remove_whitespace(i)?;
|
let (i, _) = remove_whitespace(i)?;
|
||||||
match ident {
|
match ident {
|
||||||
|
|
@ -250,12 +250,12 @@ enum MaterialsLine<'a> {
|
||||||
Empty,
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_new_material(i: &str) -> IResult<&str, MaterialsLine> {
|
fn parse_new_material(i: &'_ str) -> IResult<&'_ str, MaterialsLine<'_>> {
|
||||||
let (i, ident) = take_till1(|c| c == ' ')(i)?;
|
let (i, ident) = take_till1(|c| c == ' ')(i)?;
|
||||||
Ok((i, MaterialsLine::Material(ident)))
|
Ok((i, MaterialsLine::Material(ident)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_line_material(i: &str) -> IResult<&str, MaterialsLine> {
|
fn parse_line_material(i: &'_ str) -> IResult<&'_ str, MaterialsLine<'_>> {
|
||||||
let (i, ident) = parse_identifier(i)?;
|
let (i, ident) = parse_identifier(i)?;
|
||||||
let (i, _) = remove_whitespace(i)?;
|
let (i, _) = remove_whitespace(i)?;
|
||||||
match ident {
|
match ident {
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,13 @@ struct Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_image<
|
fn render_image<
|
||||||
'sc,
|
|
||||||
R: ClassicalRenderer<SmallRng, S, C> + Sync,
|
R: ClassicalRenderer<SmallRng, S, C> + Sync,
|
||||||
S: Scene<SmallRng> + Sync,
|
S: Scene<SmallRng> + Sync,
|
||||||
C: Camera<SmallRng> + Sync,
|
C: Camera<SmallRng> + Sync,
|
||||||
>(
|
>(
|
||||||
name: impl AsRef<str>,
|
name: impl AsRef<str>,
|
||||||
renderer: &R,
|
renderer: &R,
|
||||||
scene: &'sc S,
|
scene: &S,
|
||||||
camera: &C,
|
camera: &C,
|
||||||
samples_per_pixel: usize,
|
samples_per_pixel: usize,
|
||||||
tev: &mut TevClient,
|
tev: &mut TevClient,
|
||||||
|
|
@ -109,7 +108,7 @@ fn render_image<
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn choose_renderer<'sc, S, C>(args: &Args, scene: &str, s: &'sc S, c: &C, tev: &mut TevClient)
|
fn choose_renderer<S, C>(args: &Args, scene: &str, s: &S, c: &C, tev: &mut TevClient)
|
||||||
where
|
where
|
||||||
S: Scene<SmallRng> + Sync,
|
S: Scene<SmallRng> + Sync,
|
||||||
C: Camera<SmallRng> + Sync,
|
C: Camera<SmallRng> + Sync,
|
||||||
|
|
@ -216,6 +215,9 @@ fn main() {
|
||||||
ray_tracing_scene::examples::ExampleSceneEnum::TriangleBVH(s) => {
|
ray_tracing_scene::examples::ExampleSceneEnum::TriangleBVH(s) => {
|
||||||
choose_renderer(&args, scene, s, &c, &mut client);
|
choose_renderer(&args, scene, s, &c, &mut client);
|
||||||
}
|
}
|
||||||
|
ray_tracing_scene::examples::ExampleSceneEnum::BasicScene(s) => {
|
||||||
|
choose_renderer(&args, scene, s, &c, &mut client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue