Use camera settings from pbrt file
This commit is contained in:
parent
6403aabc11
commit
0a9748a1b7
4 changed files with 51 additions and 15 deletions
|
|
@ -40,6 +40,10 @@ impl AffineTransform {
|
|||
Some(Self { mat, inv })
|
||||
}
|
||||
|
||||
pub fn get(&self, i: usize, j: usize) -> Float {
|
||||
self.mat[j][i]
|
||||
}
|
||||
|
||||
pub fn identity() -> Self {
|
||||
Self {
|
||||
mat: [
|
||||
|
|
@ -127,7 +131,7 @@ impl AffineTransform {
|
|||
pub fn look_at(pos: Pos3, look: Pos3, up: Dir3) -> Option<Self> {
|
||||
let dir = (look - pos).normalize();
|
||||
let right = Dir3::cross(up.normalize(), dir).normalize();
|
||||
let new_up = Dir3::cross(dir, right);
|
||||
let new_up = Dir3::cross(right, dir);
|
||||
|
||||
let mat = [
|
||||
[right.x(), new_up.x(), dir.x(), pos.x()],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::*;
|
||||
use crate::{affine_transform::AffineTransform, prelude::*};
|
||||
|
||||
pub trait Camera<R: Rng> {
|
||||
fn forward(&self, x: u32, y: u32, rng: &mut R) -> Ray;
|
||||
|
|
@ -41,6 +41,25 @@ impl BasicCamera {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_affine_transform(
|
||||
width: u32,
|
||||
height: u32,
|
||||
tm: AffineTransform,
|
||||
horizontal_fov: Float,
|
||||
) -> Self {
|
||||
assert!(horizontal_fov < FloatConsts::PI);
|
||||
|
||||
let l = Float::sin(0.5 * horizontal_fov);
|
||||
|
||||
Self {
|
||||
width,
|
||||
height,
|
||||
pos: Pos3::new(tm.get(3, 0), tm.get(3, 1), tm.get(3, 2)),
|
||||
dir: Dir3::new(tm.get(2, 0), tm.get(2, 1), tm.get(2, 2)),
|
||||
h: l * Dir3::new(tm.get(0, 0), tm.get(0, 1), tm.get(0, 2)),
|
||||
v: l * Dir3::new(tm.get(1, 0), tm.get(1, 1), tm.get(1, 2)),
|
||||
}
|
||||
}
|
||||
pub fn from_look_at(
|
||||
width: u32,
|
||||
height: u32,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl Lexer {
|
|||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
enum CameraType {
|
||||
pub enum CameraType {
|
||||
Orthographic {
|
||||
frame_aspect_ratio: Option<Float>,
|
||||
screen_window: Option<Float>,
|
||||
|
|
@ -64,8 +64,8 @@ enum CameraType {
|
|||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
struct PbrtCamera {
|
||||
camera_type: CameraType,
|
||||
pub struct PbrtCamera {
|
||||
pub camera_type: CameraType,
|
||||
shutter_open: Float,
|
||||
shutter_close: Float,
|
||||
}
|
||||
|
|
@ -640,10 +640,9 @@ impl<R: Rng> Pbrt<R> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
pub struct PbrtWorldSettings {
|
||||
camera: PbrtCamera,
|
||||
camera_ctm: AffineTransform,
|
||||
pub camera: PbrtCamera,
|
||||
pub camera_ctm: AffineTransform,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -790,7 +789,7 @@ fn inner_parse_pbrt<R: Rng + std::fmt::Debug>(
|
|||
*context.ctm.last_mut().unwrap() = affine_transform
|
||||
}
|
||||
Statement::Shape(shape_type, shape_alpha) => {
|
||||
dbg!(&context);
|
||||
// dbg!(&context);
|
||||
if context.area_light.is_empty() {
|
||||
pbrt.scene.shapes.push(Shape {
|
||||
ctm: context.get_ctm(),
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use ray_tracing_core::{
|
|||
renderer::ClassicalRenderer,
|
||||
scene::Scene,
|
||||
};
|
||||
use ray_tracing_pbrt_scene::parse_pbrt_v4;
|
||||
use ray_tracing_pbrt_scene::{parse_pbrt_v4, CameraType};
|
||||
use ray_tracing_renderer::{
|
||||
depth_renderer::DepthRenderer, mis::MIS, next_event_estimation::NextEventEstimation,
|
||||
path_tracer::PathTracer, path_tracer_importance::PathTracerImportance,
|
||||
|
|
@ -230,15 +230,29 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
let c = BasicCamera::from_look_at(
|
||||
let fov = match pbrt.settings.camera.camera_type {
|
||||
CameraType::Perspective { fov, .. } => 2.0 * fov,
|
||||
_ => todo!(),
|
||||
};
|
||||
|
||||
let c = BasicCamera::from_affine_transform(
|
||||
args.width,
|
||||
args.height,
|
||||
Pos3::new(3.0, 4.0, 1.5),
|
||||
Pos3::new(0.5, 0.5, 0.0),
|
||||
Dir3::new(0.0, 0.0, 1.0),
|
||||
Float::to_radians(90.0),
|
||||
pbrt.settings.camera_ctm,
|
||||
Float::to_radians(fov),
|
||||
);
|
||||
|
||||
// let c = BasicCamera::from_look_at(
|
||||
// args.width,
|
||||
// args.height,
|
||||
// Pos3::new(-0.3, 0.5, -0.5),
|
||||
// Pos3::new(0.0, 0.75, 0.0),
|
||||
// Dir3::new(0.0, 1.0, 0.0),
|
||||
// Float::to_radians(2.0 * 37.0),
|
||||
// );
|
||||
|
||||
// dbg!(c);
|
||||
|
||||
let s = &pbrt.scene;
|
||||
|
||||
choose_renderer(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue