Added BxDF support, still somewhat broken. Starting work on image reading, writing. At the moment, this is completely broken. Fixed some issues with cameras, matrix operations, math

This commit is contained in:
pingupingou 2025-11-07 15:24:23 +00:00
parent cf58f0efc3
commit 7dc132dad7
3 changed files with 1253 additions and 0 deletions

69
README.md Normal file
View file

@ -0,0 +1,69 @@
# PBRust
## Description
A Rust implementation of the physically based renderer described in the tremendous book *Physically Based Rendering: From Theory to Implementation* by Matt Pharr, Wenzel Jakob, and Greg Humphreys. This project aims to explore modern Rust features, and create a performant and stable rendering engine.
This implementation is currently under development and serves as a learning exercise for both advanced rendering techniques and cutting-edge Rust programming.
## Getting Started
This project requires the Rust nightly toolchain
To install the nightly toolchain:
```sh
rustup toolchain install nightly
rustup default nightly
To get a local copy up and running, follow these simple steps.
1. **Clone the repository:**
```sh
git clone <your-repository-url>
cd pbrt
```
2. **Build the project:**
```sh
cargo build
```
3. **Run the executable:**
```sh
cargo run
```
4. **Run tests:**
```sh
cargo test
```
## Dependencies
This project relies on the following external crates:
* [**bitflags**](https://crates.io/crates/bitflags)
* [**bumpalo**](https://crates.io/crates/bumpalo)
* [**num**](https://crates.io/crates/num) & [**num-traits**](https://crates.io/crates/num-traits)
* [**once_cell**](https://crates.io/crates/once_cell)
* [**rand**](https://crates.io/crates/rand)
* [**thiserror**](https://crates.io/crates/thiserror)
## Help
Good luck.
```
command to run if program contains helper info
```
## Authors
## Version History
## License
This project is licensed under the [NAME HERE] License - see the LICENSE.md file for details
## Acknowledgments

84
src/utils/error.rs Normal file
View file

@ -0,0 +1,84 @@
use thiserror::Error;
use image::error;
use std::fmt;
use crate::utils::image::PixelFormat;
#[derive(Error, Debug)]
pub enum LlsError {
SingularMatrix,
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum InversionError {
SingularMatrix,
EmptyMatrix,
}
impl fmt::Display for LlsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
LlsError::SingularMatrix => write!(f, "Matrix is singular and cannot be inverted."),
}
}
}
impl fmt::Display for InversionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InversionError::SingularMatrix => {
write!(f, "Matrix is singular and cannot be inverted.")
}
InversionError::EmptyMatrix => write!(f, "Matrix is empty and cannot be inverted."),
}
}
}
#[derive(Error, Debug)]
pub enum ImageError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Image file error: {0}")]
Image(#[from] image::ImageError),
#[error("EXR file error: {0}")]
Exr(#[from] exr::error::Error),
#[error("QOI file error: {0}")]
Qoi(String),
#[error("Pixel format error: {0}")]
PixelFormat(#[from] PixelFormatError),
#[error("Unsupported operation: {0}")]
Unsupported(String),
#[error("Mismatched dimensions or channels: {0}")]
Mismatch(String),
#[error("Channel '{0}' not found in image")]
ChannelNotFound(String),
}
/// Describes an error related to an unexpected or unsupported pixel format.
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum PixelFormatError {
#[error("Unsupported operation '{operation}' for pixel format {actual:?}. Reason: {reason}")]
UnsupportedOperation {
operation: String,
actual: PixelFormat,
reason: String,
},
#[error("Invalid conversion from pixel format {from:?} to {to:?}.")]
InvalidConversion {
from: PixelFormat,
to: PixelFormat,
},
#[error("Internal invariant violated: image format is {expected:?} but pixel data is of a different type.")]
InternalFormatMismatch {
expected: PixelFormat,
},
}

1100
src/utils/image.rs Normal file

File diff suppressed because it is too large Load diff