Compare commits
17 Commits
d4281d3538
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
5c5c81325d
|
|||
|
d1211b7157
|
|||
|
99bf883eeb
|
|||
|
078ad2c401
|
|||
|
3a49460fe6
|
|||
|
684cc19302
|
|||
|
0e919c339c
|
|||
|
5605ad0901
|
|||
|
3e5f23a3bf
|
|||
|
5aeaf72af1
|
|||
|
6e6a3e8a27
|
|||
|
aa0ba6ed7a
|
|||
|
5ffc390d2c
|
|||
|
48d4039c31
|
|||
|
3cb3e4a8fa
|
|||
|
fc40e0b798
|
|||
|
d0840759b3
|
32
Cargo.lock
generated
32
Cargo.lock
generated
@@ -894,6 +894,7 @@ dependencies = [
|
|||||||
"lispers-core",
|
"lispers-core",
|
||||||
"lispers-macro",
|
"lispers-macro",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
|
"ndarray",
|
||||||
"nix",
|
"nix",
|
||||||
"rayon",
|
"rayon",
|
||||||
"video-rs",
|
"video-rs",
|
||||||
@@ -1033,6 +1034,21 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ndarray"
|
||||||
|
version = "0.17.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d"
|
||||||
|
dependencies = [
|
||||||
|
"matrixmultiply",
|
||||||
|
"num-complex",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"portable-atomic",
|
||||||
|
"portable-atomic-util",
|
||||||
|
"rawpointer",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "new_debug_unreachable"
|
name = "new_debug_unreachable"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
@@ -1194,6 +1210,21 @@ dependencies = [
|
|||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic-util"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3"
|
||||||
|
dependencies = [
|
||||||
|
"portable-atomic",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "potential_utf"
|
name = "potential_utf"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
@@ -1669,6 +1700,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2633ec4c2a8aeb7c0e970f75ba99122a75841e9f7b34d5225366d0e61a870a8c"
|
checksum = "2633ec4c2a8aeb7c0e970f75ba99122a75841e9f7b34d5225366d0e61a870a8c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ffmpeg-next",
|
"ffmpeg-next",
|
||||||
|
"ndarray",
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ nix = "0.31.2"
|
|||||||
rayon = "1.11.0"
|
rayon = "1.11.0"
|
||||||
lispers-core = {workspace = true}
|
lispers-core = {workspace = true}
|
||||||
lispers-macro = {workspace = true}
|
lispers-macro = {workspace = true}
|
||||||
video-rs = "0.11.0"
|
video-rs = { version = "0.11.0", features = ["ndarray"] }
|
||||||
|
ndarray = "0.17.2"
|
||||||
|
|||||||
39
build.rs
Normal file
39
build.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn copy_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> {
|
||||||
|
std::fs::create_dir_all(&dst)?;
|
||||||
|
for entry in std::fs::read_dir(src)? {
|
||||||
|
let entry = entry?;
|
||||||
|
if entry.file_type()?.is_dir() {
|
||||||
|
copy_dir(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||||
|
} else {
|
||||||
|
std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let use_local_scenes = std::env::var("LISPERS_USE_LOCAL_SCENES").unwrap_or_default() == "1";
|
||||||
|
let no_copy = std::env::var("LISPERS_DONT_COPY_SCENES").unwrap_or_default() == "1";
|
||||||
|
|
||||||
|
let out_dir = match std::env::var("LISPERS_OUT_DIR") {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => std::env::var("OUT_DIR").unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut scenes_dir = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap()
|
||||||
|
.join("scenes");
|
||||||
|
|
||||||
|
if !use_local_scenes {
|
||||||
|
let tgt_scenes_dir = Path::new(&out_dir).join("scenes");
|
||||||
|
if !no_copy {
|
||||||
|
copy_dir(&scenes_dir, &tgt_scenes_dir).expect("Failed to copy scenes directory");
|
||||||
|
}
|
||||||
|
scenes_dir = tgt_scenes_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("cargo:rustc-env=SCENES_DIR={}", scenes_dir.display());
|
||||||
|
}
|
||||||
18
flake.nix
18
flake.nix
@@ -79,7 +79,15 @@
|
|||||||
overlays = [rust-overlay.overlays.default];
|
overlays = [rust-overlay.overlays.default];
|
||||||
};
|
};
|
||||||
|
|
||||||
packages.lispers = cargoNix.workspaceMembers.lispers.build;
|
packages.lispers = cargoNix.workspaceMembers.lispers.build.overrideAttrs (attrs: {
|
||||||
|
preConfigure = ''
|
||||||
|
export LISPERS_OUT_DIR="$out"
|
||||||
|
export LISPERS_DONT_COPY_SCENES=1
|
||||||
|
'';
|
||||||
|
postInstall = ''
|
||||||
|
cp -r $src/scenes $out/scenes
|
||||||
|
'';
|
||||||
|
});
|
||||||
packages.default = self'.packages.lispers;
|
packages.default = self'.packages.lispers;
|
||||||
apps = {
|
apps = {
|
||||||
lisp_demo = {
|
lisp_demo = {
|
||||||
@@ -94,7 +102,7 @@
|
|||||||
type = "app";
|
type = "app";
|
||||||
program = "${self'.packages.lispers}/bin/rt_demo";
|
program = "${self'.packages.lispers}/bin/rt_demo";
|
||||||
};
|
};
|
||||||
rt_demo_lisp = {
|
rt_lisp_demo = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${self'.packages.lispers}/bin/rt_lisp_demo";
|
program = "${self'.packages.lispers}/bin/rt_lisp_demo";
|
||||||
};
|
};
|
||||||
@@ -102,11 +110,13 @@
|
|||||||
type = "app";
|
type = "app";
|
||||||
program = "${self'.packages.lispers}/bin/rt_interp";
|
program = "${self'.packages.lispers}/bin/rt_interp";
|
||||||
};
|
};
|
||||||
default = self'.apps.rt_demo_lisp;
|
default = self'.apps.rt_lisp_demo;
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
inputsFrom = [self'.packages.lispers];
|
shellHook = ''
|
||||||
|
export LISPERS_USE_LOCAL_SCENES=1
|
||||||
|
'';
|
||||||
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
||||||
nativeBuildInputs = [rust-toolchain pkgs.pkg-config pkgs.ffmpeg_4];
|
nativeBuildInputs = [rust-toolchain pkgs.pkg-config pkgs.ffmpeg_4];
|
||||||
BINDGEN_EXTRA_CLANG_ARGS = [
|
BINDGEN_EXTRA_CLANG_ARGS = [
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ impl<'a> Environment<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a new `Environment` with `self` as the outer `Environment`.
|
/// Construct a new `Environment` with `self` as the outer `Environment`.
|
||||||
pub fn mk_inner(&self) -> Environment {
|
pub fn mk_inner(&'a self) -> Environment<'a> {
|
||||||
Environment {
|
Environment {
|
||||||
layer: EnvironmentLayer::new(),
|
layer: EnvironmentLayer::new(),
|
||||||
outer: Some(self),
|
outer: Some(self),
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use crate::parser::ParserError;
|
||||||
|
|
||||||
use super::environment::Environment;
|
use super::environment::Environment;
|
||||||
use super::environment::EnvironmentLayer;
|
use super::environment::EnvironmentLayer;
|
||||||
use super::expression::Expression;
|
use super::expression::Expression;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
/// All possible evaluation errors
|
/// All possible evaluation errors
|
||||||
pub enum EvalError {
|
pub enum EvalError {
|
||||||
SymbolNotBound(String),
|
SymbolNotBound(String),
|
||||||
@@ -14,6 +16,13 @@ pub enum EvalError {
|
|||||||
TypeError(String),
|
TypeError(String),
|
||||||
NotASymbol(Expression),
|
NotASymbol(Expression),
|
||||||
RuntimeError(String),
|
RuntimeError(String),
|
||||||
|
ParserError(ParserError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParserError> for EvalError {
|
||||||
|
fn from(value: ParserError) -> Self {
|
||||||
|
EvalError::ParserError(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for EvalError {
|
impl Display for EvalError {
|
||||||
@@ -26,6 +35,7 @@ impl Display for EvalError {
|
|||||||
EvalError::TypeError(s) => write!(f, "Type error: {}", s),
|
EvalError::TypeError(s) => write!(f, "Type error: {}", s),
|
||||||
EvalError::NotASymbol(e) => write!(f, "Expression {} is not a symbol", e),
|
EvalError::NotASymbol(e) => write!(f, "Expression {} is not a symbol", e),
|
||||||
EvalError::RuntimeError(s) => write!(f, "Runtime error: {}", s),
|
EvalError::RuntimeError(s) => write!(f, "Runtime error: {}", s),
|
||||||
|
EvalError::ParserError(s) => write!(f, "Parser error: {}", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ impl Display for ForeignDataStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, PartialOrd)]
|
#[derive(Clone, Debug)]
|
||||||
/// A sum type of all possible lisp expressions.
|
/// A sum type of all possible lisp expressions.
|
||||||
pub enum Expression {
|
pub enum Expression {
|
||||||
/// The classic lisp cons cell aka (a . b) used to construct expressions.
|
/// The classic lisp cons cell aka (a . b) used to construct expressions.
|
||||||
@@ -151,6 +151,60 @@ pub enum Expression {
|
|||||||
Nil,
|
Nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Expression {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
use Expression::*;
|
||||||
|
match (self, other) {
|
||||||
|
(Cell(a1, b1), Cell(a2, b2)) => PartialEq::eq(a1, a2) && PartialEq::eq(b1, b2),
|
||||||
|
(
|
||||||
|
AnonymousFunction {
|
||||||
|
argument_symbols: args1,
|
||||||
|
body: body1,
|
||||||
|
},
|
||||||
|
AnonymousFunction {
|
||||||
|
argument_symbols: args2,
|
||||||
|
body: body2,
|
||||||
|
},
|
||||||
|
) => PartialEq::eq(args1, args2) && PartialEq::eq(body1, body2),
|
||||||
|
(ForeignExpression(f1), ForeignExpression(f2)) => PartialEq::eq(f1, f2),
|
||||||
|
(Quote(e1), Quote(e2)) => PartialEq::eq(e1, e2),
|
||||||
|
(Symbol(s1), Symbol(s2)) => PartialEq::eq(s1, s2),
|
||||||
|
(Float(f1), Float(f2)) => PartialEq::eq(f1, f2),
|
||||||
|
(Nil, Nil) => true,
|
||||||
|
(True, True) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Expression {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
use Expression::*;
|
||||||
|
match (self, other) {
|
||||||
|
(Cell(a1, b1), Cell(a2, b2)) => a1.partial_cmp(a2).or_else(|| b1.partial_cmp(b2)),
|
||||||
|
(
|
||||||
|
AnonymousFunction {
|
||||||
|
argument_symbols: args1,
|
||||||
|
body: body1,
|
||||||
|
},
|
||||||
|
AnonymousFunction {
|
||||||
|
argument_symbols: args2,
|
||||||
|
body: body2,
|
||||||
|
},
|
||||||
|
) => args1
|
||||||
|
.partial_cmp(args2)
|
||||||
|
.or_else(|| body1.partial_cmp(body2)),
|
||||||
|
(ForeignExpression(f1), ForeignExpression(f2)) => f1.partial_cmp(f2),
|
||||||
|
(Quote(e1), Quote(e2)) => e1.partial_cmp(e2),
|
||||||
|
(Symbol(s1), Symbol(s2)) => s1.partial_cmp(s2),
|
||||||
|
(Float(f1), Float(f2)) => f1.partial_cmp(f2),
|
||||||
|
(Nil, Nil) => Some(std::cmp::Ordering::Equal),
|
||||||
|
(True, True) => Some(std::cmp::Ordering::Equal),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: ForeignData> From<ForeignDataWrapper<T>> for Expression {
|
impl<T: ForeignData> From<ForeignDataWrapper<T>> for Expression {
|
||||||
fn from(value: ForeignDataWrapper<T>) -> Expression {
|
fn from(value: ForeignDataWrapper<T>) -> Expression {
|
||||||
Expression::ForeignExpression(ForeignDataStore::new(value.0))
|
Expression::ForeignExpression(ForeignDataStore::new(value.0))
|
||||||
@@ -361,7 +415,7 @@ impl Display for Expression {
|
|||||||
Expression::Symbol(s) => write!(f, "{}", s),
|
Expression::Symbol(s) => write!(f, "{}", s),
|
||||||
Expression::Integer(i) => write!(f, "{}", i),
|
Expression::Integer(i) => write!(f, "{}", i),
|
||||||
Expression::Float(fl) => write!(f, "{}", fl),
|
Expression::Float(fl) => write!(f, "{}", fl),
|
||||||
Expression::String(s) => write!(f, "{}", s),
|
Expression::String(s) => write!(f, "\"{}\"", s),
|
||||||
Expression::True => write!(f, "true"),
|
Expression::True => write!(f, "true"),
|
||||||
Expression::Nil => write!(f, "nil"),
|
Expression::Nil => write!(f, "nil"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
use crate::parser::ExpressionStream;
|
||||||
|
use crate::parser::ParserError;
|
||||||
|
|
||||||
use super::environment::Environment;
|
use super::environment::Environment;
|
||||||
use super::environment::EnvironmentLayer;
|
use super::environment::EnvironmentLayer;
|
||||||
use super::eval::eval;
|
use super::eval::eval;
|
||||||
@@ -5,6 +8,7 @@ use super::eval::CellIterator;
|
|||||||
use super::eval::EvalError;
|
use super::eval::EvalError;
|
||||||
use super::expression::Expression;
|
use super::expression::Expression;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn prelude_add(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
pub fn prelude_add(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
||||||
let [a, b] = expr.try_into()?;
|
let [a, b] = expr.try_into()?;
|
||||||
@@ -325,6 +329,54 @@ pub fn prelude_to_string(env: &Environment, expr: Expression) -> Result<Expressi
|
|||||||
Ok(Expression::String(format!("{}", eval(env, e)?)))
|
Ok(Expression::String(format!("{}", eval(env, e)?)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prelude_load(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
||||||
|
let [expr] = expr.try_into()?;
|
||||||
|
let lisp_string: String = eval(env, expr)?.try_into()?;
|
||||||
|
|
||||||
|
let mut last_result = Expression::Nil;
|
||||||
|
|
||||||
|
for expr in ExpressionStream::from_char_stream(lisp_string.chars())
|
||||||
|
.collect::<Result<Vec<Expression>, ParserError>>()?
|
||||||
|
{
|
||||||
|
last_result = eval(env, expr)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(last_result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prelude_include(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
||||||
|
let [expr] = expr.try_into()?;
|
||||||
|
let lisp_file: String = eval(env, expr)?.try_into()?;
|
||||||
|
|
||||||
|
// Try to resolve as relative to FILE
|
||||||
|
let resolved_lisp_file: PathBuf = PathBuf::from(
|
||||||
|
env.get("FILE")
|
||||||
|
.map(|x| x.try_into())
|
||||||
|
.unwrap_or(Ok(String::new()))?,
|
||||||
|
)
|
||||||
|
.parent()
|
||||||
|
.ok_or(EvalError::RuntimeError(
|
||||||
|
"Could not get parent of current file.".to_string(),
|
||||||
|
))?
|
||||||
|
.join(&lisp_file);
|
||||||
|
|
||||||
|
let lisp_string = std::fs::read_to_string(&resolved_lisp_file)
|
||||||
|
.map_err(|e| EvalError::RuntimeError(e.to_string()))?;
|
||||||
|
|
||||||
|
// Use enviroment for resolved file or fallback to the lisp_file argument
|
||||||
|
let mut env = env.mk_inner();
|
||||||
|
env.set(
|
||||||
|
"FILE".to_string(),
|
||||||
|
resolved_lisp_file
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or(&lisp_file)
|
||||||
|
.to_string()
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
|
||||||
|
prelude_load(&env, [lisp_string.into()].into())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mk_prelude(layer: &mut EnvironmentLayer) {
|
pub fn mk_prelude(layer: &mut EnvironmentLayer) {
|
||||||
layer.set("+".to_string(), Expression::Function(prelude_add));
|
layer.set("+".to_string(), Expression::Function(prelude_add));
|
||||||
layer.set("-".to_string(), Expression::Function(prelude_sub));
|
layer.set("-".to_string(), Expression::Function(prelude_sub));
|
||||||
@@ -355,4 +407,6 @@ pub fn mk_prelude(layer: &mut EnvironmentLayer) {
|
|||||||
"to-string".to_string(),
|
"to-string".to_string(),
|
||||||
Expression::Function(prelude_to_string),
|
Expression::Function(prelude_to_string),
|
||||||
);
|
);
|
||||||
|
layer.set("load".to_string(), Expression::Function(prelude_load));
|
||||||
|
layer.set("include".to_string(), Expression::Function(prelude_include));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use super::tokenizer::tokenize;
|
|||||||
use super::tokenizer::TokenStream;
|
use super::tokenizer::TokenStream;
|
||||||
use super::tokenizer::TokenizerError;
|
use super::tokenizer::TokenizerError;
|
||||||
use crate::lisp::Expression;
|
use crate::lisp::Expression;
|
||||||
|
use std::fmt::Display;
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -18,6 +19,16 @@ impl From<TokenizerError> for ParserError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for ParserError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
ParserError::TokenizerError(t) => write!(f, "Tokenizer Error: {}", t),
|
||||||
|
ParserError::UnexpectedToken(t) => write!(f, "Unexpecte Token: {}", t),
|
||||||
|
ParserError::UnexpectedEndOfInput => write!(f, "Unexpected end of input."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_list<I>(stream: &mut Peekable<TokenStream<I>>) -> Result<Expression, ParserError>
|
fn parse_list<I>(stream: &mut Peekable<TokenStream<I>>) -> Result<Expression, ParserError>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = char>,
|
I: Iterator<Item = char>,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
/// Sum type of different tokens
|
/// Sum type of different tokens
|
||||||
pub enum Token {
|
pub enum Token {
|
||||||
@@ -12,3 +14,20 @@ pub enum Token {
|
|||||||
Symbol(String),
|
Symbol(String),
|
||||||
True,
|
True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Token {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Token::FloatLiteral(x) => write!(f, "{}", x),
|
||||||
|
Token::IntLiteral(x) => write!(f, "{}", x),
|
||||||
|
Token::Dot => write!(f, "."),
|
||||||
|
Token::Nil => write!(f, "nil"),
|
||||||
|
Token::ParClose => write!(f, ")"),
|
||||||
|
Token::ParOpen => write!(f, "("),
|
||||||
|
Token::Quote => write!(f, "'"),
|
||||||
|
Token::StringLiteral(x) => write!(f, "\"{}\"", x),
|
||||||
|
Token::Symbol(x) => write!(f, "{}", x),
|
||||||
|
Token::True => write!(f, "true"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use super::token::Token;
|
use super::token::Token;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -7,6 +9,14 @@ pub enum TokenizerError {
|
|||||||
UnmatchedSequence(String),
|
UnmatchedSequence(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for TokenizerError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
TokenizerError::UnmatchedSequence(s) => write!(f, "Unmatched sequence: {}", s),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A reader used to wrap the `TokenStream`.
|
/// A reader used to wrap the `TokenStream`.
|
||||||
/// When reading, it starts with the staging buffer of the stream, once
|
/// When reading, it starts with the staging buffer of the stream, once
|
||||||
/// it's end is reached, the input stream is copied character wise to
|
/// it's end is reached, the input stream is copied character wise to
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ pub fn native_lisp_function_proxy(item: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
#(#try_apply_statements)*
|
#(#try_apply_statements)*
|
||||||
|
|
||||||
Err(EvalError::TypeError(format!("No applicable method found for {}", #fname_str).to_string()))
|
Err(EvalError::TypeError(format!("Could not call {} with arguments {} ", #fname_str, expr).to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
|
|||||||
@@ -1,33 +1,4 @@
|
|||||||
(set 'red
|
(include "./materials.lisp")
|
||||||
(material
|
|
||||||
(color 1 0 0)
|
|
||||||
(color 1 0 0)
|
|
||||||
(color 0.5 0 0)
|
|
||||||
50 0.25))
|
|
||||||
(set 'blue
|
|
||||||
(material
|
|
||||||
(color 0 0 1)
|
|
||||||
(color 0 0 1)
|
|
||||||
(color 0 0 0.6)
|
|
||||||
50 0.25))
|
|
||||||
(set 'green
|
|
||||||
(material
|
|
||||||
(color 0 1 0)
|
|
||||||
(color 0 1 0)
|
|
||||||
(color 0 0.6 0)
|
|
||||||
50 0.25))
|
|
||||||
(set 'white
|
|
||||||
(material
|
|
||||||
(color 1 1 1)
|
|
||||||
(color 1 1 1)
|
|
||||||
(color 0.6 0.6 0.6)
|
|
||||||
100 0.5))
|
|
||||||
(set 'black
|
|
||||||
(material
|
|
||||||
(color 0 0 0)
|
|
||||||
(color 0 0 0)
|
|
||||||
(color 0.6 0.6 0.6)
|
|
||||||
100 0.5))
|
|
||||||
|
|
||||||
(set 's1
|
(set 's1
|
||||||
(sphere
|
(sphere
|
||||||
@@ -36,22 +7,26 @@
|
|||||||
(sphere
|
(sphere
|
||||||
(point 2 0.5 2) 0.5 green))
|
(point 2 0.5 2) 0.5 green))
|
||||||
|
|
||||||
(defun spiral-sphere (i n)
|
(set 'mirror-dome
|
||||||
|
(sphere
|
||||||
|
(point 0 -17 0)
|
||||||
|
30 dark-mirror))
|
||||||
|
|
||||||
|
(defun spiral-sphere (i n t)
|
||||||
(sphere
|
(sphere
|
||||||
(progn
|
(progn
|
||||||
(print "Spiral Sphere at: ")
|
(point
|
||||||
(println (point
|
(* 2 (cos (/ (* i 6.2) n)))
|
||||||
(* 2 (cos (/ (* i 6.2) n)))
|
(+ 0.5 (* 0.3 (cos (+ (/ (* i 6.2) n) (/ t 5.0)))))
|
||||||
0.5
|
(* 2 (sin (/ (* i 6.2) n))))
|
||||||
(* 2 (sin (/ (* i 6.2) n)))))
|
|
||||||
)
|
)
|
||||||
0.5 red))
|
0.2 red))
|
||||||
|
|
||||||
(defun spiral (scn i n)
|
(defun spiral (scn i n t)
|
||||||
(if (< i n)
|
(if (< i n)
|
||||||
(scene-add
|
(scene-add
|
||||||
(spiral scn (+ i 1) n)
|
(spiral scn (+ i 1) n t)
|
||||||
(spiral-sphere i n))
|
(spiral-sphere i n t))
|
||||||
scn))
|
scn))
|
||||||
|
|
||||||
(set 'p1
|
(set 'p1
|
||||||
@@ -67,28 +42,26 @@
|
|||||||
|
|
||||||
(set 'scn-base (scene
|
(set 'scn-base (scene
|
||||||
(color 0.1 0.1 0.1)
|
(color 0.1 0.1 0.1)
|
||||||
'(s1 s2 p1)
|
'(s1 s2 p1 mirror-dome)
|
||||||
'(l1 l2)))
|
'(l1 l2)))
|
||||||
|
|
||||||
(set 'scn (spiral scn-base 0 10))
|
|
||||||
|
|
||||||
(set 'cam (camera (point 0 3 6) (point 0 0 0) (vector 0 1 0) 40 1920 1080))
|
(set 'cam (camera (point 0 3 6) (point 0 0 0) (vector 0 1 0) 40 1920 1080))
|
||||||
|
|
||||||
(defun scene-fn (t)
|
(defun scene-fn (t)
|
||||||
scn)
|
(spiral scn-base 0 30 t))
|
||||||
|
|
||||||
(defun cam-fn (t c)
|
(defun cam-fn (t c)
|
||||||
(let '((pos . (point 0 4 8))
|
(let '((pos . (point -3 0.5 8))
|
||||||
(cnt . (point 0 0 0))
|
(cnt . (point 0 0 0))
|
||||||
(to . (point -3 3 -8))
|
(to . (point -3 0.5 -8))
|
||||||
(up . (vector 0 1 0))
|
(up . (vector 0 1 0))
|
||||||
(fovy . 40)
|
(fovy . 80)
|
||||||
(pct . (/ t 300.0)))
|
(pct . (/ t 300.0)))
|
||||||
(let '((tpos . (vadd pos (vmul (vsub to pos) pct)))
|
(let '((tpos . (+ pos (* (- to pos) pct)))
|
||||||
(tfovy . (+ fovy (* 40 pct)))
|
(tfovy . (+ fovy (* 40 pct)))
|
||||||
)
|
)
|
||||||
(camera-reposition c tpos cnt up fovy)
|
(camera-reposition c tpos cnt up tfovy)
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
(render-animation cam scene-fn cam-fn 300 1 4 2)
|
(render-animation cam "demo-animation.mp4" scene-fn cam-fn 400 30 7 2)
|
||||||
|
|||||||
69
scenes/demo-3.lisp
Normal file
69
scenes/demo-3.lisp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
(set 'red
|
||||||
|
(material
|
||||||
|
(color 1 0 0)
|
||||||
|
(color 1 0 0)
|
||||||
|
(color 0.5 0 0)
|
||||||
|
50 0.25))
|
||||||
|
(set 'blue
|
||||||
|
(material
|
||||||
|
(color 0 0 1)
|
||||||
|
(color 0 0 1)
|
||||||
|
(color 0 0 0.6)
|
||||||
|
50 0.25))
|
||||||
|
(set 'green
|
||||||
|
(material
|
||||||
|
(color 0 1 0)
|
||||||
|
(color 0 1 0)
|
||||||
|
(color 0 0.6 0)
|
||||||
|
50 0.25))
|
||||||
|
|
||||||
|
(set 'mandelbrot-red
|
||||||
|
(mandelbrot-texture
|
||||||
|
1800.0
|
||||||
|
(point2 -0.7489967346191402 -0.06952285766601607)
|
||||||
|
1000
|
||||||
|
(color 0.3 0 0)
|
||||||
|
(color 0.3 0 0)
|
||||||
|
(color 0.3 0 0)
|
||||||
|
))
|
||||||
|
|
||||||
|
(set 'mandelbrot-blue
|
||||||
|
(mandelbrot-texture
|
||||||
|
1800.0
|
||||||
|
(point2 -0.7489967346191402 -0.06952285766601607)
|
||||||
|
1000
|
||||||
|
(color 0 0 0.3)
|
||||||
|
(color 0 0 0.3)
|
||||||
|
(color 0 0 0.3)
|
||||||
|
))
|
||||||
|
|
||||||
|
(set 's1
|
||||||
|
(sphere
|
||||||
|
(point 0 1 0) 1 blue))
|
||||||
|
(set 's2
|
||||||
|
(sphere
|
||||||
|
(point 2 0.5 2) 0.5 green))
|
||||||
|
|
||||||
|
|
||||||
|
(set 'p1
|
||||||
|
(texture-plane
|
||||||
|
mandelbrot-red
|
||||||
|
(point 0 0 0)
|
||||||
|
(vector 0 1 0)
|
||||||
|
1.0
|
||||||
|
(vector 1 0 0)))
|
||||||
|
|
||||||
|
(set 'l1 (light (point 3 10 5) (color 1 1 1)))
|
||||||
|
(set 'l2 (light (point 2 10 5) (color 1 1 1)))
|
||||||
|
|
||||||
|
|
||||||
|
(set 'scn (scene
|
||||||
|
(color 0.1 0.1 0.1)
|
||||||
|
'(s1 s2 p1)
|
||||||
|
'(l1 l2)))
|
||||||
|
|
||||||
|
(println (cons "Final Scene:" scn))
|
||||||
|
|
||||||
|
(set 'cam (camera (point 0 3 6) (point 0 0 0) (vector 0 1 0) 40 1920 1080))
|
||||||
|
|
||||||
|
(render cam scn 5 4 "demo-3.png")
|
||||||
37
scenes/materials.lisp
Normal file
37
scenes/materials.lisp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
(set 'red
|
||||||
|
(material
|
||||||
|
(color 1 0 0)
|
||||||
|
(color 1 0 0)
|
||||||
|
(color 0.5 0 0)
|
||||||
|
50 0.25))
|
||||||
|
(set 'blue
|
||||||
|
(material
|
||||||
|
(color 0 0 1)
|
||||||
|
(color 0 0 1)
|
||||||
|
(color 0 0 0.6)
|
||||||
|
50 0.25))
|
||||||
|
(set 'green
|
||||||
|
(material
|
||||||
|
(color 0 1 0)
|
||||||
|
(color 0 1 0)
|
||||||
|
(color 0 0.6 0)
|
||||||
|
50 0.25))
|
||||||
|
(set 'white
|
||||||
|
(material
|
||||||
|
(color 1 1 1)
|
||||||
|
(color 1 1 1)
|
||||||
|
(color 0.6 0.6 0.6)
|
||||||
|
100 0.4))
|
||||||
|
(set 'black
|
||||||
|
(material
|
||||||
|
(color 0 0 0)
|
||||||
|
(color 0 0 0)
|
||||||
|
(color 0.6 0.6 0.6)
|
||||||
|
100 0.4))
|
||||||
|
|
||||||
|
(set 'dark-mirror
|
||||||
|
(material
|
||||||
|
(color 0.01 0.05 0.15)
|
||||||
|
(color 0.01 0.05 0.15)
|
||||||
|
(color 0.01 0.05 0.15)
|
||||||
|
20 0.7))
|
||||||
@@ -15,6 +15,8 @@ fn main() {
|
|||||||
"(defun do-n-times (f n) (if (= n 0) '() (cons (f) (do-n-times f (- n 1)))))",
|
"(defun do-n-times (f n) (if (= n 0) '() (cons (f) (do-n-times f (- n 1)))))",
|
||||||
"(do-n-times (lambda () (print 'hello)) 5)",
|
"(do-n-times (lambda () (print 'hello)) 5)",
|
||||||
"(progn (print 'hello) (print 'world))",
|
"(progn (print 'hello) (print 'world))",
|
||||||
|
"(load \"(defun loaded-foo (x) (+ x 1))\")",
|
||||||
|
"(loaded-foo 1)",
|
||||||
];
|
];
|
||||||
|
|
||||||
let environment = Environment::default();
|
let environment = Environment::default();
|
||||||
|
|||||||
@@ -17,20 +17,27 @@ fn main() {
|
|||||||
mk_prelude(&mut layer);
|
mk_prelude(&mut layer);
|
||||||
mk_raytrace(&mut layer);
|
mk_raytrace(&mut layer);
|
||||||
|
|
||||||
let environment = Environment::from_layer(layer);
|
let mut environment = Environment::from_layer(layer);
|
||||||
|
|
||||||
for (i, r) in
|
for (program, path) in programs.iter().zip(program_paths) {
|
||||||
ExpressionStream::from_char_stream(programs.iter().map(|p| p.chars()).flatten()).enumerate()
|
environment.set("FILE".to_string(), path.clone().into());
|
||||||
{
|
|
||||||
match r {
|
for (i, r) in ExpressionStream::from_char_stream(program.chars()).enumerate() {
|
||||||
Err(err) => {
|
match r {
|
||||||
println!("ParserError in Expression {}: {:?}", i + 1, err);
|
Err(err) => {
|
||||||
break;
|
println!(
|
||||||
|
"ParserError in File {} Expression {}: {:?}",
|
||||||
|
path,
|
||||||
|
i + 1,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Ok(expr) => match eval(&environment, expr) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => println!("Error evaluating Expression {}: {}", i + 1, e),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
Ok(expr) => match eval(&environment, expr) {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(e) => println!("Error evaluating Expression {}: {}", i + 1, e),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,51 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use lispers::raytracer::lisp::mk_raytrace;
|
use lispers::raytracer::lisp::mk_raytrace;
|
||||||
use lispers_core::lisp::environment::EnvironmentLayer;
|
use lispers_core::lisp::environment::EnvironmentLayer;
|
||||||
use lispers_core::lisp::prelude::mk_prelude;
|
use lispers_core::lisp::prelude::mk_prelude;
|
||||||
use lispers_core::lisp::{eval, Environment};
|
use lispers_core::lisp::{eval, Environment};
|
||||||
use lispers_core::parser::ExpressionStream;
|
use lispers_core::parser::ExpressionStream;
|
||||||
|
|
||||||
|
const SCENES_DIR: &str = env!("SCENES_DIR");
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let programs = [
|
println!("Loading scenes from directory: {}", SCENES_DIR);
|
||||||
"(set 'red (material (color 1 0 0) (color 1 0 0) (color 0.5 0 0) 50 0.25))",
|
|
||||||
"(set 'blue (material (color 0 0 1) (color 0 0 1) (color 0 0 0.6) 50 0.25))",
|
let mut scenes = HashMap::new();
|
||||||
"(set 'green (material (color 0 1 0) (color 0 1 0) (color 0 0.6 0) 50 0.25))",
|
for e in std::fs::read_dir(Path::new(SCENES_DIR)).expect("Failed to read scenes directory") {
|
||||||
"(set 'white (material (color 1 1 1) (color 1 1 1) (color 0.6 0.6 0.6) 100 0.5))",
|
let e = e.expect("Failed to read scene file");
|
||||||
"(set 'black (material (color 0 0 0) (color 0 0 0) (color 0.6 0.6 0.6) 100 0.5))",
|
let t = e.file_type().expect("Failed to read scene file type");
|
||||||
"(set 's1 (sphere (point 0 1 0) 1 blue))",
|
let n = e
|
||||||
"(set 's2 (sphere (point 2 0.5 2) 0.5 green))",
|
.file_name()
|
||||||
"(defun spiral-sphere (i n) (sphere (print (point (* 2 (cos (/ (* i 6.2) n))) 0.5 (* 2 (sin (/ (* i 6.2) n))))) 0.5 red))",
|
.into_string()
|
||||||
"(defun spiral (scn i n) (if (< i n) (scene-add (spiral scn (+ i 1) n) (spiral-sphere i n)) scn))",
|
.expect("Failed to read scene file name");
|
||||||
"(set 'p1 (checkerboard (point 0 0 0) (vector 0 1 0) black white 0.5 (vector 0.5 0 1)))",
|
if t.is_file() && n.starts_with("demo-") && n.ends_with(".lisp") {
|
||||||
"(set 'l1 (light (point 3 10 5) (color 1 1 1)))",
|
scenes.insert(n, e);
|
||||||
"(set 'l2 (light (point 2 10 5) (color 1 1 1)))",
|
}
|
||||||
"(set 'scn (scene (color 0.1 0.1 0.1) '(s1 s2 p1) '(l1 l2)))",
|
}
|
||||||
"(set 'scn (spiral scn 0.0 10.0))",
|
|
||||||
"(print scn)",
|
|
||||||
"(set 'cam (camera (point 0 3 6) (point 0 0 0) (vector 0 1 0) 40 1920 1080))",
|
|
||||||
"(render cam scn 5 4 \"rt-lisp-demo.png\")",
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut layer = EnvironmentLayer::new();
|
let mut layer = EnvironmentLayer::new();
|
||||||
mk_prelude(&mut layer);
|
mk_prelude(&mut layer);
|
||||||
mk_raytrace(&mut layer);
|
mk_raytrace(&mut layer);
|
||||||
|
|
||||||
let environment = Environment::from_layer(layer);
|
let environment = Environment::from_layer(layer);
|
||||||
|
|
||||||
for r in ExpressionStream::from_char_stream(programs.iter().map(|p| p.chars()).flatten()) {
|
let args: Vec<_> = std::env::args().collect();
|
||||||
|
|
||||||
|
if args.len() != 2 {
|
||||||
|
println!("Usage: {} <scene-file.lisp>", args[0]);
|
||||||
|
println!("Available scene files:");
|
||||||
|
for name in scenes.keys() {
|
||||||
|
println!(" {}", name);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for r in ExpressionStream::from_char_stream(
|
||||||
|
std::fs::read_to_string(scenes.get(&args[1]).expect("Scene file not found").path())
|
||||||
|
.expect("Failed to read scene file")
|
||||||
|
.chars(),
|
||||||
|
) {
|
||||||
match r {
|
match r {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("ParserError: {:?}", err);
|
println!("ParserError: {:?}", err);
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
use std::fmt::Display;
|
use std::{fmt::Display, path::Path};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
scene::Scene,
|
scene::Scene,
|
||||||
types::{Color, Point3, Ray, Scalar, Vector3},
|
types::{Color, Point3, Ray, Scalar, Vector3},
|
||||||
|
RTError,
|
||||||
};
|
};
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
|
use lispers_core::lisp::eval::EvalError;
|
||||||
|
use ndarray::Array3;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use video_rs::{encode::Settings, Encoder, Time};
|
||||||
|
|
||||||
/// A camera that can render a scene.
|
/// A camera that can render a scene.
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
@@ -119,26 +123,47 @@ impl Camera {
|
|||||||
Camera::new(position, center, up, fovy, self.width, self.height)
|
Camera::new(position, center, up, fovy, self.width, self.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_animation<SFn: Fn(u32) -> Scene, CFn: Fn(u32, &Camera) -> Camera>(
|
pub fn render_animation<
|
||||||
|
SFn: Fn(u32) -> Result<Scene, EvalError>,
|
||||||
|
CFn: Fn(u32, &Camera) -> Result<Camera, EvalError>,
|
||||||
|
>(
|
||||||
&self,
|
&self,
|
||||||
|
path: &Path,
|
||||||
scene_fn: SFn,
|
scene_fn: SFn,
|
||||||
update_cam: CFn,
|
update_cam: CFn,
|
||||||
frames: u32,
|
frames: u32,
|
||||||
fps: u32,
|
fps: u32,
|
||||||
depth: u32,
|
depth: u32,
|
||||||
subp: u32,
|
subp: u32,
|
||||||
) {
|
) -> Result<(), RTError> {
|
||||||
|
let mut encoder = Encoder::new(
|
||||||
|
path,
|
||||||
|
Settings::preset_h264_yuv420p(self.width, self.height, false),
|
||||||
|
)?;
|
||||||
|
let frame_duration = Time::from_nth_of_a_second(fps as usize);
|
||||||
|
let mut timestamp = Time::zero();
|
||||||
|
|
||||||
let mut cam = self.to_owned();
|
let mut cam = self.to_owned();
|
||||||
for t in 0..frames {
|
for t in 0..frames {
|
||||||
println!("Rendering frame {}/{}", t + 1, frames);
|
println!(
|
||||||
cam = update_cam(t, &cam);
|
"Rendering frame {}/{} for {}",
|
||||||
let img = cam.render(&scene_fn(t), depth, subp);
|
t + 1,
|
||||||
|
frames,
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
cam = update_cam(t, &cam)?;
|
||||||
|
let img = cam.render(&scene_fn(t)?, depth, subp);
|
||||||
|
|
||||||
match img.save(format!("frame_{:04}.png", t)) {
|
let frame = Array3::from_shape_fn((self.height, self.width, 3), |(y, x, c)| {
|
||||||
Ok(_) => {}
|
img.get_pixel(x as u32, y as u32)[c]
|
||||||
Err(e) => print!("Could not render frame: {}", e),
|
});
|
||||||
}
|
|
||||||
|
encoder.encode(&frame, timestamp)?;
|
||||||
|
timestamp = timestamp.aligned_with(frame_duration).add();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
encoder.finish()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
use crate::raytracer::{scene::Scene, types::Light};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::raytracer::{
|
||||||
|
scene::Scene,
|
||||||
|
sphere::TextureSphere,
|
||||||
|
texture::TextureWrapper,
|
||||||
|
types::{Light, Point2},
|
||||||
|
};
|
||||||
|
|
||||||
use lispers_macro::{native_lisp_function, native_lisp_function_proxy};
|
use lispers_macro::{native_lisp_function, native_lisp_function_proxy};
|
||||||
|
|
||||||
@@ -11,9 +18,11 @@ use lispers_core::lisp::{
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
plane::{Checkerboard, Plane},
|
plane::{Checkerboard, Plane, TexturePlane},
|
||||||
sphere::Sphere,
|
sphere::Sphere,
|
||||||
|
texture::MandelbrotTexture,
|
||||||
types::{Color, Material, Point3, RTObjectWrapper, Vector3},
|
types::{Color, Material, Point3, RTObjectWrapper, Vector3},
|
||||||
|
RTError,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[native_lisp_function(eval)]
|
#[native_lisp_function(eval)]
|
||||||
@@ -21,6 +30,11 @@ pub fn point(x: f64, y: f64, z: f64) -> Result<ForeignDataWrapper<Point3>, EvalE
|
|||||||
Ok(ForeignDataWrapper::new(Point3::new(x, y, z)))
|
Ok(ForeignDataWrapper::new(Point3::new(x, y, z)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn point2(x: f64, y: f64) -> Result<ForeignDataWrapper<Point2>, EvalError> {
|
||||||
|
Ok(ForeignDataWrapper::new(Point2::new(x, y)))
|
||||||
|
}
|
||||||
|
|
||||||
#[native_lisp_function(eval)]
|
#[native_lisp_function(eval)]
|
||||||
pub fn vector(x: f64, y: f64, z: f64) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
pub fn vector(x: f64, y: f64, z: f64) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
Ok(ForeignDataWrapper::new(Vector3::new(x, y, z)))
|
Ok(ForeignDataWrapper::new(Vector3::new(x, y, z)))
|
||||||
@@ -61,6 +75,22 @@ pub fn sphere(
|
|||||||
Ok(ForeignDataWrapper::new(RTObjectWrapper::from(Sphere::new(*pos, rad, *mat))).into())
|
Ok(ForeignDataWrapper::new(RTObjectWrapper::from(Sphere::new(*pos, rad, *mat))).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn texture_sphere(
|
||||||
|
pos: ForeignDataWrapper<Point3>,
|
||||||
|
rad: f64,
|
||||||
|
tex: ForeignDataWrapper<TextureWrapper>,
|
||||||
|
) -> Result<ForeignDataWrapper<RTObjectWrapper>, EvalError> {
|
||||||
|
Ok(
|
||||||
|
ForeignDataWrapper::new(RTObjectWrapper::from(TextureSphere::new(
|
||||||
|
*pos,
|
||||||
|
rad,
|
||||||
|
tex.clone(),
|
||||||
|
)))
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[native_lisp_function(eval)]
|
#[native_lisp_function(eval)]
|
||||||
pub fn plane(
|
pub fn plane(
|
||||||
pos: ForeignDataWrapper<Point3>,
|
pos: ForeignDataWrapper<Point3>,
|
||||||
@@ -87,6 +117,47 @@ pub fn checkerboard(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn texture_plane(
|
||||||
|
texture: ForeignDataWrapper<TextureWrapper>,
|
||||||
|
pos: ForeignDataWrapper<Point3>,
|
||||||
|
norm: ForeignDataWrapper<Vector3>,
|
||||||
|
sca: f64,
|
||||||
|
up: ForeignDataWrapper<Vector3>,
|
||||||
|
) -> Result<ForeignDataWrapper<RTObjectWrapper>, EvalError> {
|
||||||
|
Ok(
|
||||||
|
ForeignDataWrapper::new(RTObjectWrapper::from(TexturePlane::new(
|
||||||
|
*pos,
|
||||||
|
*norm,
|
||||||
|
texture.clone(),
|
||||||
|
sca,
|
||||||
|
*up,
|
||||||
|
)))
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn mandelbrot_texture(
|
||||||
|
scale: f64,
|
||||||
|
at: ForeignDataWrapper<Point2>,
|
||||||
|
max_iter: i64,
|
||||||
|
ambient_color: ForeignDataWrapper<Color>,
|
||||||
|
diffuse_color: ForeignDataWrapper<Color>,
|
||||||
|
specular_color: ForeignDataWrapper<Color>,
|
||||||
|
) -> Result<ForeignDataWrapper<TextureWrapper>, EvalError> {
|
||||||
|
Ok(ForeignDataWrapper::new(TextureWrapper::new(
|
||||||
|
MandelbrotTexture::new(
|
||||||
|
scale,
|
||||||
|
*at,
|
||||||
|
max_iter as u32,
|
||||||
|
*ambient_color,
|
||||||
|
*diffuse_color,
|
||||||
|
*specular_color,
|
||||||
|
),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn scene(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
pub fn scene(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
||||||
let [amb, objs, lgts]: [Expression; 3] = expr.try_into()?;
|
let [amb, objs, lgts]: [Expression; 3] = expr.try_into()?;
|
||||||
|
|
||||||
@@ -179,38 +250,44 @@ pub fn render(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_animation(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
pub fn render_animation(env: &Environment, expr: Expression) -> Result<Expression, EvalError> {
|
||||||
let [cam, scene_fn, update_cam, frames, fps, depth, subp]: [Expression; 7] = expr.try_into()?;
|
let [cam, path, scene_fn, update_cam, frames, fps, depth, subp]: [Expression; 8] =
|
||||||
|
expr.try_into()?;
|
||||||
|
|
||||||
let cam: ForeignDataWrapper<Camera> = eval(env, cam)?.try_into()?;
|
let cam: ForeignDataWrapper<Camera> = eval(env, cam)?.try_into()?;
|
||||||
|
let path: String = eval(env, path)?.try_into()?;
|
||||||
let frames: i64 = eval(env, frames)?.try_into()?;
|
let frames: i64 = eval(env, frames)?.try_into()?;
|
||||||
let fps: i64 = eval(env, fps)?.try_into()?;
|
let fps: i64 = eval(env, fps)?.try_into()?;
|
||||||
let depth: i64 = eval(env, depth)?.try_into()?;
|
let depth: i64 = eval(env, depth)?.try_into()?;
|
||||||
let subp: i64 = eval(env, subp)?.try_into()?;
|
let subp: i64 = eval(env, subp)?.try_into()?;
|
||||||
|
|
||||||
let sfn = |t: u32| -> Scene {
|
let sfn = |t: u32| -> Result<Scene, EvalError> {
|
||||||
let scene_fn_call: Expression = [scene_fn.clone(), (t as i64).into()].into();
|
let scene_fn_call: Expression = [scene_fn.clone(), (t as i64).into()].into();
|
||||||
let scn: ForeignDataWrapper<Scene> = eval(env, scene_fn_call).unwrap().try_into().unwrap();
|
let scn: ForeignDataWrapper<Scene> = eval(env, scene_fn_call)?.try_into()?;
|
||||||
scn.to_owned()
|
Ok(scn.to_owned())
|
||||||
};
|
};
|
||||||
|
|
||||||
let ucm = |t: u32, c: &Camera| -> Camera {
|
let ucm = |t: u32, c: &Camera| -> Result<Camera, EvalError> {
|
||||||
let c = ForeignDataWrapper::new(c.to_owned());
|
let c = ForeignDataWrapper::new(c.to_owned());
|
||||||
let update_cam_call: Expression = [update_cam.clone(), (t as i64).into(), c.into()].into();
|
let update_cam_call: Expression = [update_cam.clone(), (t as i64).into(), c.into()].into();
|
||||||
let new_c: ForeignDataWrapper<Camera> =
|
let new_c: ForeignDataWrapper<Camera> = eval(env, update_cam_call)?.try_into()?;
|
||||||
eval(env, update_cam_call).unwrap().try_into().unwrap();
|
Ok(new_c.to_owned())
|
||||||
new_c.to_owned()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cam.render_animation(
|
let path: PathBuf = path.into();
|
||||||
|
|
||||||
|
match cam.render_animation(
|
||||||
|
&path,
|
||||||
sfn,
|
sfn,
|
||||||
ucm,
|
ucm,
|
||||||
frames as u32,
|
frames as u32,
|
||||||
fps as u32,
|
fps as u32,
|
||||||
depth as u32,
|
depth as u32,
|
||||||
subp as u32,
|
subp as u32,
|
||||||
);
|
) {
|
||||||
|
Ok(()) => Ok(Expression::Nil),
|
||||||
Ok(Expression::Nil)
|
Err(RTError::EvalError(e)) => Err(e),
|
||||||
|
Err(RTError::FFMpegError(e)) => Err(EvalError::RuntimeError(e.to_string())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function(eval)]
|
#[native_lisp_function(eval)]
|
||||||
@@ -223,6 +300,16 @@ pub fn cos(x: f64) -> Result<f64, EvalError> {
|
|||||||
Ok(x.cos())
|
Ok(x.cos())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn add_i(x: i64, y: i64) -> Result<i64, EvalError> {
|
||||||
|
Ok(x + y)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn add_f(x: f64, y: f64) -> Result<f64, EvalError> {
|
||||||
|
Ok(x + y)
|
||||||
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vadd_vv(
|
pub fn vadd_vv(
|
||||||
a: ForeignDataWrapper<Vector3>,
|
a: ForeignDataWrapper<Vector3>,
|
||||||
@@ -248,15 +335,27 @@ pub fn vadd_pv(
|
|||||||
}
|
}
|
||||||
|
|
||||||
native_lisp_function_proxy!(
|
native_lisp_function_proxy!(
|
||||||
fname = vadd,
|
fname = add,
|
||||||
eval,
|
eval,
|
||||||
|
dispatch = add_i,
|
||||||
|
dispatch = add_f,
|
||||||
dispatch = vadd_vv,
|
dispatch = vadd_vv,
|
||||||
dispatch = vadd_vp,
|
dispatch = vadd_vp,
|
||||||
dispatch = vadd_pv
|
dispatch = vadd_pv
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn sub_i(x: i64, y: i64) -> Result<i64, EvalError> {
|
||||||
|
Ok(x - y)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn sub_f(x: f64, y: f64) -> Result<f64, EvalError> {
|
||||||
|
Ok(x - y)
|
||||||
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vsub_vv(
|
pub fn sub_vv(
|
||||||
a: ForeignDataWrapper<Vector3>,
|
a: ForeignDataWrapper<Vector3>,
|
||||||
b: ForeignDataWrapper<Vector3>,
|
b: ForeignDataWrapper<Vector3>,
|
||||||
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
@@ -264,7 +363,7 @@ pub fn vsub_vv(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vsub_vp(
|
pub fn sub_vp(
|
||||||
a: ForeignDataWrapper<Vector3>,
|
a: ForeignDataWrapper<Vector3>,
|
||||||
b: ForeignDataWrapper<Point3>,
|
b: ForeignDataWrapper<Point3>,
|
||||||
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
||||||
@@ -272,7 +371,7 @@ pub fn vsub_vp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vsub_pv(
|
pub fn sub_pv(
|
||||||
a: ForeignDataWrapper<Point3>,
|
a: ForeignDataWrapper<Point3>,
|
||||||
b: ForeignDataWrapper<Vector3>,
|
b: ForeignDataWrapper<Vector3>,
|
||||||
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
||||||
@@ -280,7 +379,7 @@ pub fn vsub_pv(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vsub_pp(
|
pub fn sub_pp(
|
||||||
a: ForeignDataWrapper<Point3>,
|
a: ForeignDataWrapper<Point3>,
|
||||||
b: ForeignDataWrapper<Point3>,
|
b: ForeignDataWrapper<Point3>,
|
||||||
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
@@ -288,16 +387,28 @@ pub fn vsub_pp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
native_lisp_function_proxy!(
|
native_lisp_function_proxy!(
|
||||||
fname = vsub,
|
fname = sub,
|
||||||
eval,
|
eval,
|
||||||
dispatch = vsub_vv,
|
dispatch = sub_i,
|
||||||
dispatch = vsub_vp,
|
dispatch = sub_f,
|
||||||
dispatch = vsub_pv,
|
dispatch = sub_vv,
|
||||||
dispatch = vsub_pp
|
dispatch = sub_vp,
|
||||||
|
dispatch = sub_pv,
|
||||||
|
dispatch = sub_pp
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn mul_i(x: i64, y: i64) -> Result<i64, EvalError> {
|
||||||
|
Ok(x * y)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn mul_f(x: f64, y: f64) -> Result<f64, EvalError> {
|
||||||
|
Ok(x * y)
|
||||||
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vmul_vs(
|
pub fn mul_vs(
|
||||||
a: ForeignDataWrapper<Vector3>,
|
a: ForeignDataWrapper<Vector3>,
|
||||||
b: f64,
|
b: f64,
|
||||||
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
@@ -305,7 +416,7 @@ pub fn vmul_vs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vmul_sv(
|
pub fn mul_sv(
|
||||||
a: f64,
|
a: f64,
|
||||||
b: ForeignDataWrapper<Vector3>,
|
b: ForeignDataWrapper<Vector3>,
|
||||||
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
@@ -313,7 +424,7 @@ pub fn vmul_sv(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vmul_ps(
|
pub fn mul_ps(
|
||||||
a: ForeignDataWrapper<Point3>,
|
a: ForeignDataWrapper<Point3>,
|
||||||
b: f64,
|
b: f64,
|
||||||
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
||||||
@@ -321,7 +432,7 @@ pub fn vmul_ps(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[native_lisp_function]
|
#[native_lisp_function]
|
||||||
pub fn vmul_sp(
|
pub fn mul_sp(
|
||||||
a: f64,
|
a: f64,
|
||||||
b: ForeignDataWrapper<Point3>,
|
b: ForeignDataWrapper<Point3>,
|
||||||
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
||||||
@@ -329,17 +440,104 @@ pub fn vmul_sp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
native_lisp_function_proxy!(
|
native_lisp_function_proxy!(
|
||||||
fname = vmul,
|
fname = mul,
|
||||||
eval,
|
eval,
|
||||||
dispatch = vmul_vs,
|
dispatch = mul_i,
|
||||||
dispatch = vmul_sv,
|
dispatch = mul_f,
|
||||||
dispatch = vmul_ps,
|
dispatch = mul_vs,
|
||||||
dispatch = vmul_sp
|
dispatch = mul_sv,
|
||||||
|
dispatch = mul_ps,
|
||||||
|
dispatch = mul_sp
|
||||||
|
);
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn div_i(x: i64, y: i64) -> Result<f64, EvalError> {
|
||||||
|
Ok(x as f64 / y as f64)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn div_f(x: f64, y: f64) -> Result<f64, EvalError> {
|
||||||
|
Ok(x / y)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn div_vs(
|
||||||
|
a: ForeignDataWrapper<Vector3>,
|
||||||
|
b: f64,
|
||||||
|
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
|
Ok(ForeignDataWrapper::new(*a / b))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn div_sv(
|
||||||
|
a: f64,
|
||||||
|
b: ForeignDataWrapper<Vector3>,
|
||||||
|
) -> Result<ForeignDataWrapper<Vector3>, EvalError> {
|
||||||
|
Ok(ForeignDataWrapper::new(*b / a))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn div_ps(
|
||||||
|
a: ForeignDataWrapper<Point3>,
|
||||||
|
b: f64,
|
||||||
|
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
||||||
|
Ok(ForeignDataWrapper::new(*a / b))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn div_sp(
|
||||||
|
a: f64,
|
||||||
|
b: ForeignDataWrapper<Point3>,
|
||||||
|
) -> Result<ForeignDataWrapper<Point3>, EvalError> {
|
||||||
|
Ok(ForeignDataWrapper::new(*b / a))
|
||||||
|
}
|
||||||
|
|
||||||
|
native_lisp_function_proxy!(
|
||||||
|
fname = div,
|
||||||
|
eval,
|
||||||
|
dispatch = div_i,
|
||||||
|
dispatch = div_f,
|
||||||
|
dispatch = div_vs,
|
||||||
|
dispatch = div_sv,
|
||||||
|
dispatch = div_ps,
|
||||||
|
dispatch = div_sp
|
||||||
|
);
|
||||||
|
|
||||||
|
#[native_lisp_function(eval)]
|
||||||
|
pub fn dot(
|
||||||
|
a: ForeignDataWrapper<Vector3>,
|
||||||
|
b: ForeignDataWrapper<Vector3>,
|
||||||
|
) -> Result<f64, EvalError> {
|
||||||
|
Ok(a.dot(&b))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn abs_i(a: i64) -> Result<i64, EvalError> {
|
||||||
|
Ok(a.abs())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn abs_f(a: f64) -> Result<f64, EvalError> {
|
||||||
|
Ok(a.abs())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[native_lisp_function]
|
||||||
|
pub fn abs_v(a: ForeignDataWrapper<Vector3>) -> Result<f64, EvalError> {
|
||||||
|
Ok(a.dot(&a).sqrt())
|
||||||
|
}
|
||||||
|
|
||||||
|
native_lisp_function_proxy!(
|
||||||
|
fname = abs,
|
||||||
|
eval,
|
||||||
|
dispatch = abs_i,
|
||||||
|
dispatch = abs_f,
|
||||||
|
dispatch = abs_v
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Adds the raytracing functions to the given environment layer.
|
/// Adds the raytracing functions to the given environment layer.
|
||||||
pub fn mk_raytrace(layer: &mut EnvironmentLayer) {
|
pub fn mk_raytrace(layer: &mut EnvironmentLayer) {
|
||||||
layer.set("point".to_string(), Expression::Function(point));
|
layer.set("point".to_string(), Expression::Function(point));
|
||||||
|
layer.set("point2".to_string(), Expression::Function(point2));
|
||||||
layer.set("vector".to_string(), Expression::Function(vector));
|
layer.set("vector".to_string(), Expression::Function(vector));
|
||||||
layer.set("color".to_string(), Expression::Function(color));
|
layer.set("color".to_string(), Expression::Function(color));
|
||||||
layer.set("light".to_string(), Expression::Function(light));
|
layer.set("light".to_string(), Expression::Function(light));
|
||||||
@@ -349,7 +547,19 @@ pub fn mk_raytrace(layer: &mut EnvironmentLayer) {
|
|||||||
"checkerboard".to_string(),
|
"checkerboard".to_string(),
|
||||||
Expression::Function(checkerboard),
|
Expression::Function(checkerboard),
|
||||||
);
|
);
|
||||||
|
layer.set(
|
||||||
|
"texture-plane".to_string(),
|
||||||
|
Expression::Function(texture_plane),
|
||||||
|
);
|
||||||
|
layer.set(
|
||||||
|
"mandelbrot-texture".to_string(),
|
||||||
|
Expression::Function(mandelbrot_texture),
|
||||||
|
);
|
||||||
layer.set("sphere".to_string(), Expression::Function(sphere));
|
layer.set("sphere".to_string(), Expression::Function(sphere));
|
||||||
|
layer.set(
|
||||||
|
"texture-sphere".to_string(),
|
||||||
|
Expression::Function(texture_sphere),
|
||||||
|
);
|
||||||
layer.set("scene".to_string(), Expression::Function(scene));
|
layer.set("scene".to_string(), Expression::Function(scene));
|
||||||
layer.set("scene-add".to_string(), Expression::Function(scene_add));
|
layer.set("scene-add".to_string(), Expression::Function(scene_add));
|
||||||
layer.set("camera".to_string(), Expression::Function(camera));
|
layer.set("camera".to_string(), Expression::Function(camera));
|
||||||
@@ -364,7 +574,10 @@ pub fn mk_raytrace(layer: &mut EnvironmentLayer) {
|
|||||||
);
|
);
|
||||||
layer.set("sin".to_string(), Expression::Function(sin));
|
layer.set("sin".to_string(), Expression::Function(sin));
|
||||||
layer.set("cos".to_string(), Expression::Function(cos));
|
layer.set("cos".to_string(), Expression::Function(cos));
|
||||||
layer.set("vadd".to_string(), Expression::Function(vadd));
|
layer.set("+".to_string(), Expression::Function(add));
|
||||||
layer.set("vsub".to_string(), Expression::Function(vsub));
|
layer.set("-".to_string(), Expression::Function(sub));
|
||||||
layer.set("vmul".to_string(), Expression::Function(vmul));
|
layer.set("*".to_string(), Expression::Function(mul));
|
||||||
|
layer.set("/".to_string(), Expression::Function(div));
|
||||||
|
layer.set("dot".to_string(), Expression::Function(dot));
|
||||||
|
layer.set("abs".to_string(), Expression::Function(abs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,24 @@ pub mod lisp;
|
|||||||
pub mod plane;
|
pub mod plane;
|
||||||
pub mod scene;
|
pub mod scene;
|
||||||
pub mod sphere;
|
pub mod sphere;
|
||||||
|
mod texture;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
mod vec;
|
mod vec;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum RTError {
|
||||||
|
EvalError(lispers_core::lisp::eval::EvalError),
|
||||||
|
FFMpegError(video_rs::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<lispers_core::lisp::eval::EvalError> for RTError {
|
||||||
|
fn from(value: lispers_core::lisp::eval::EvalError) -> Self {
|
||||||
|
RTError::EvalError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<video_rs::Error> for RTError {
|
||||||
|
fn from(value: video_rs::Error) -> Self {
|
||||||
|
RTError::FFMpegError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use super::types::{Intersect, Material, Point3, Scalar, Vector3};
|
use super::{
|
||||||
|
texture::TextureWrapper,
|
||||||
|
types::{Intersect, Material, Point3, Scalar, Vector3},
|
||||||
|
};
|
||||||
|
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
@@ -26,6 +29,21 @@ pub struct Checkerboard {
|
|||||||
projection_matrix: na::Matrix2x3<Scalar>,
|
projection_matrix: na::Matrix2x3<Scalar>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Define a plane using a 2D texture function
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct TexturePlane {
|
||||||
|
/// The position of the plane.
|
||||||
|
position: Point3,
|
||||||
|
/// The normal of the plane.
|
||||||
|
normal: Vector3,
|
||||||
|
/// The scale of the plane (factor for x,y passed to material function)
|
||||||
|
scale: f64,
|
||||||
|
/// A projection matrix to map 3D points to the 2D plane space.
|
||||||
|
projection_matrix: na::Matrix2x3<Scalar>,
|
||||||
|
/// The texture to use.
|
||||||
|
texture: TextureWrapper,
|
||||||
|
}
|
||||||
|
|
||||||
impl Plane {
|
impl Plane {
|
||||||
/// Create a new plane.
|
/// Create a new plane.
|
||||||
/// - `position` is the position of the plane.
|
/// - `position` is the position of the plane.
|
||||||
@@ -66,6 +84,49 @@ impl Checkerboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TexturePlane {
|
||||||
|
/// Create a new Function Plane.
|
||||||
|
/// - `position` is the position of the plane.
|
||||||
|
/// - `normal` is the normal of the plane.
|
||||||
|
/// - `texture` the texture to use
|
||||||
|
/// - `scale` is the side-length of each square.
|
||||||
|
/// - `up` is "y" direction on the plane in 3D-Space.
|
||||||
|
pub fn new(
|
||||||
|
position: Point3,
|
||||||
|
normal: Vector3,
|
||||||
|
texture: TextureWrapper,
|
||||||
|
scale: f64,
|
||||||
|
up: Vector3,
|
||||||
|
) -> TexturePlane {
|
||||||
|
let right = up.cross(&normal).normalize();
|
||||||
|
TexturePlane {
|
||||||
|
position,
|
||||||
|
normal,
|
||||||
|
scale,
|
||||||
|
projection_matrix: na::Matrix3x2::from_columns(&[right, up]).transpose(),
|
||||||
|
texture,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn plane_intersect(
|
||||||
|
position: Point3,
|
||||||
|
normal: Vector3,
|
||||||
|
ray: &super::types::Ray,
|
||||||
|
) -> Option<(Point3, Vector3, super::types::Scalar)> {
|
||||||
|
let denom = normal.dot(&ray.direction);
|
||||||
|
if denom != 0.0 {
|
||||||
|
let d = normal.dot(&position.coords);
|
||||||
|
let t = (d - normal.dot(&ray.origin.coords)) / denom;
|
||||||
|
|
||||||
|
if t > 1e-5 {
|
||||||
|
let point = ray.origin + ray.direction * t;
|
||||||
|
return Some((point, normal, t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
impl Intersect for Plane {
|
impl Intersect for Plane {
|
||||||
fn intersect(
|
fn intersect(
|
||||||
&self,
|
&self,
|
||||||
@@ -76,17 +137,11 @@ impl Intersect for Plane {
|
|||||||
super::types::Scalar,
|
super::types::Scalar,
|
||||||
super::types::Material,
|
super::types::Material,
|
||||||
)> {
|
)> {
|
||||||
let denom = self.normal.dot(&ray.direction);
|
if let Some((point, normal, t)) = plane_intersect(self.position, self.normal, ray) {
|
||||||
if denom != 0.0 {
|
Some((point, normal, t, self.material.clone()))
|
||||||
let d = self.normal.dot(&self.position.coords);
|
} else {
|
||||||
let t = (d - self.normal.dot(&ray.origin.coords)) / denom;
|
None
|
||||||
|
|
||||||
if t > 1e-5 {
|
|
||||||
let point = ray.origin + ray.direction * t;
|
|
||||||
return Some((point, self.normal, t, self.material.clone()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +172,29 @@ impl Intersect for Checkerboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Intersect for TexturePlane {
|
||||||
|
fn intersect(
|
||||||
|
&self,
|
||||||
|
ray: &super::types::Ray,
|
||||||
|
) -> Option<(
|
||||||
|
Point3,
|
||||||
|
Vector3,
|
||||||
|
super::types::Scalar,
|
||||||
|
super::types::Material,
|
||||||
|
)> {
|
||||||
|
if let Some((point, normal, t)) = plane_intersect(self.position, self.normal, ray) {
|
||||||
|
let v3 = point - self.position;
|
||||||
|
let v2 = self.projection_matrix * v3;
|
||||||
|
let material = self
|
||||||
|
.texture
|
||||||
|
.material_at(na::Point2::new(v2.x / self.scale, v2.y / self.scale));
|
||||||
|
Some((point, normal, t, material))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Plane {
|
impl std::fmt::Display for Plane {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
@@ -137,6 +215,26 @@ impl std::fmt::Display for Checkerboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for TexturePlane {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"(function-plane position: {:?}, normal: {:?}, scale: {:?})",
|
||||||
|
self.position, self.normal, self.scale,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for TexturePlane {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"(function-plane position: {}, normal: {}, scale: {})",
|
||||||
|
self.position, self.normal, self.scale,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialOrd for Plane {
|
impl PartialOrd for Plane {
|
||||||
fn partial_cmp(&self, _other: &Self) -> Option<std::cmp::Ordering> {
|
fn partial_cmp(&self, _other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
None
|
None
|
||||||
@@ -148,3 +246,18 @@ impl PartialOrd for Checkerboard {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for TexturePlane {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.normal == other.normal
|
||||||
|
&& self.position == other.position
|
||||||
|
&& self.projection_matrix == other.projection_matrix
|
||||||
|
&& self.scale == other.scale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for TexturePlane {
|
||||||
|
fn partial_cmp(&self, _other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use super::types::{Intersect, Material, Point3, Ray, Scalar, Vector3};
|
use super::{
|
||||||
|
texture::TextureWrapper,
|
||||||
|
types::{Intersect, Material, Point2, Point3, Ray, Scalar, Vector3},
|
||||||
|
};
|
||||||
|
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
@@ -13,6 +16,17 @@ pub struct Sphere {
|
|||||||
material: Material,
|
material: Material,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A sphere in 3D space
|
||||||
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
|
pub struct TextureSphere {
|
||||||
|
/// Center of the sphere
|
||||||
|
center: Point3,
|
||||||
|
/// Radius of the sphere
|
||||||
|
radius: Scalar,
|
||||||
|
/// texture of the sphere
|
||||||
|
texture: TextureWrapper,
|
||||||
|
}
|
||||||
|
|
||||||
impl Sphere {
|
impl Sphere {
|
||||||
/// Create a new sphere at `center` with `radius` and `material`.
|
/// Create a new sphere at `center` with `radius` and `material`.
|
||||||
pub fn new(center: Point3, radius: Scalar, material: Material) -> Sphere {
|
pub fn new(center: Point3, radius: Scalar, material: Material) -> Sphere {
|
||||||
@@ -27,41 +41,47 @@ impl Sphere {
|
|||||||
/// Numerical error tolerance
|
/// Numerical error tolerance
|
||||||
const EPSILON: Scalar = 1e-5;
|
const EPSILON: Scalar = 1e-5;
|
||||||
|
|
||||||
impl Intersect for Sphere {
|
fn intersect(ray: &Ray, center: &Point3, radius: Scalar) -> Option<(Point3, Vector3, Scalar)> {
|
||||||
fn intersect(&self, ray: &Ray) -> Option<(Point3, Vector3, Scalar, Material)> {
|
let co = ray.origin - center;
|
||||||
let co = ray.origin - self.center;
|
|
||||||
|
|
||||||
let a = ray.direction.dot(&ray.direction);
|
let a = ray.direction.dot(&ray.direction);
|
||||||
let b = 2.0 * ray.direction.dot(&co);
|
let b = 2.0 * ray.direction.dot(&co);
|
||||||
let c = co.dot(&co) - (self.radius * self.radius);
|
let c = co.dot(&co) - (radius * radius);
|
||||||
let d = b * b - 4.0 * a * c;
|
let d = b * b - 4.0 * a * c;
|
||||||
|
|
||||||
if d >= 0.0 {
|
if d >= 0.0 {
|
||||||
let e = d.sqrt();
|
let e = d.sqrt();
|
||||||
let t1 = (-b - e) / (2.0 * a);
|
let t1 = (-b - e) / (2.0 * a);
|
||||||
let t2 = (-b + e) / (2.0 * a);
|
let t2 = (-b + e) / (2.0 * a);
|
||||||
let mut t = Scalar::MAX;
|
let mut t = Scalar::MAX;
|
||||||
|
|
||||||
if t1 > EPSILON && t1 < t {
|
if t1 > EPSILON && t1 < t {
|
||||||
t = t1;
|
t = t1;
|
||||||
}
|
}
|
||||||
if t2 > EPSILON && t2 < t {
|
if t2 > EPSILON && t2 < t {
|
||||||
t = t2;
|
t = t2;
|
||||||
}
|
|
||||||
|
|
||||||
if t < Scalar::MAX {
|
|
||||||
let isect_pt: Point3 = ray.origin + ray.direction * t;
|
|
||||||
|
|
||||||
return Some((
|
|
||||||
isect_pt,
|
|
||||||
(isect_pt - self.center) / self.radius,
|
|
||||||
t,
|
|
||||||
self.material.clone(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
if t < Scalar::MAX {
|
||||||
|
let isect_pt: Point3 = ray.origin + ray.direction * t;
|
||||||
|
|
||||||
|
if c >= 0.0 {
|
||||||
|
return Some((isect_pt, (isect_pt - center) / radius, t));
|
||||||
|
} else {
|
||||||
|
return Some((isect_pt, -(isect_pt - center) / radius, t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Intersect for Sphere {
|
||||||
|
fn intersect(&self, ray: &Ray) -> Option<(Point3, Vector3, Scalar, Material)> {
|
||||||
|
match intersect(ray, &self.center, self.radius) {
|
||||||
|
Some((isect_pt, normal, t)) => Some((isect_pt, normal, t, self.material.clone())),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,3 +100,46 @@ impl PartialOrd for Sphere {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TextureSphere {
|
||||||
|
/// Create a new sphere at `center` with `radius` and `texture`.
|
||||||
|
pub fn new(center: Point3, radius: Scalar, texture: TextureWrapper) -> TextureSphere {
|
||||||
|
TextureSphere {
|
||||||
|
center,
|
||||||
|
radius,
|
||||||
|
texture,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Intersect for TextureSphere {
|
||||||
|
fn intersect(&self, ray: &Ray) -> Option<(Point3, Vector3, Scalar, Material)> {
|
||||||
|
match intersect(ray, &self.center, self.radius) {
|
||||||
|
Some((isect_pt, normal, t)) => {
|
||||||
|
let n_isect_pt = (isect_pt - self.center) / self.radius;
|
||||||
|
let uv: Point2 = Point2::new(
|
||||||
|
0.5 + (n_isect_pt.z.atan2(n_isect_pt.x) / (2.0 * std::f64::consts::PI)),
|
||||||
|
0.5 - (n_isect_pt.y).asin() / std::f64::consts::PI,
|
||||||
|
);
|
||||||
|
Some((isect_pt, normal, t, self.texture.material_at(uv)))
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for TextureSphere {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"(sphere center: {}, radius: {}, texture: {})",
|
||||||
|
self.center, self.radius, self.texture
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for TextureSphere {
|
||||||
|
fn partial_cmp(&self, _other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
127
src/raytracer/texture.rs
Normal file
127
src/raytracer/texture.rs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
use std::fmt::Debug;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use as_any::AsAny;
|
||||||
|
use nalgebra as na;
|
||||||
|
|
||||||
|
use super::types::Color;
|
||||||
|
use super::types::Material;
|
||||||
|
use super::types::Point2;
|
||||||
|
use super::types::Scalar;
|
||||||
|
|
||||||
|
pub trait Texture: Display + Debug + AsAny + Sync + Send {
|
||||||
|
fn material_at(&self, pt: Point2) -> Material;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct TextureWrapper(Arc<dyn Texture>);
|
||||||
|
|
||||||
|
impl TextureWrapper {
|
||||||
|
pub fn new<T: Texture>(texture: T) -> Self {
|
||||||
|
Self(Arc::new(texture))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for TextureWrapper {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug for TextureWrapper {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
Debug::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextureWrapper {
|
||||||
|
pub fn material_at(&self, pt: Point2) -> Material {
|
||||||
|
self.0.material_at(pt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for TextureWrapper {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
Arc::ptr_eq(&self.0, &other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for TextureWrapper {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
|
PartialOrd::partial_cmp(&Arc::as_ptr(&self.0).addr(), &Arc::as_ptr(&other.0).addr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MandelbrotTexture {
|
||||||
|
scale: Scalar,
|
||||||
|
at: Point2,
|
||||||
|
max_iter: u32,
|
||||||
|
ambient_color: Color,
|
||||||
|
diffuse_color: Color,
|
||||||
|
specular_color: Color,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MandelbrotTexture {
|
||||||
|
pub fn new(
|
||||||
|
scale: Scalar,
|
||||||
|
at: Point2,
|
||||||
|
max_iter: u32,
|
||||||
|
ambient_color: Color,
|
||||||
|
diffuse_color: Color,
|
||||||
|
specular_color: Color,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
scale,
|
||||||
|
at,
|
||||||
|
max_iter,
|
||||||
|
ambient_color,
|
||||||
|
diffuse_color,
|
||||||
|
specular_color,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Texture for MandelbrotTexture {
|
||||||
|
fn material_at(&self, pt: Point2) -> Material {
|
||||||
|
let x = (pt.x / self.scale) + self.at.x;
|
||||||
|
let y = (pt.y / self.scale) + self.at.y;
|
||||||
|
let mut z = na::Vector2::new(0.0, 0.0);
|
||||||
|
let mut n = 0;
|
||||||
|
while z.norm() < 2.0 && n < self.max_iter {
|
||||||
|
let xtemp = z.x * z.x - z.y * z.y + x;
|
||||||
|
z.y = 2.0 * z.x * z.y + y;
|
||||||
|
z.x = xtemp;
|
||||||
|
n += 1;
|
||||||
|
}
|
||||||
|
let c = n as f64 / self.max_iter as f64;
|
||||||
|
|
||||||
|
Material {
|
||||||
|
ambient_color: self.ambient_color * c,
|
||||||
|
diffuse_color: self.diffuse_color * c,
|
||||||
|
specular_color: self.specular_color * c,
|
||||||
|
shininess: (1.0 - c) * 10.0,
|
||||||
|
mirror: 1.0 - c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for MandelbrotTexture {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"MandelbrotTexture{{at={}, max_iter={}}}",
|
||||||
|
self.at, self.max_iter
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug for MandelbrotTexture {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"MandelbrotTexture{{at={:?}, max_iter={:?}}}",
|
||||||
|
self.at, self.max_iter
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ pub type Scalar = f64;
|
|||||||
pub type Vector3 = na::Vector3<Scalar>;
|
pub type Vector3 = na::Vector3<Scalar>;
|
||||||
/// The Point3 type to use for raytracing
|
/// The Point3 type to use for raytracing
|
||||||
pub type Point3 = na::Point3<Scalar>;
|
pub type Point3 = na::Point3<Scalar>;
|
||||||
|
/// The Point2 type to use for texture lookups
|
||||||
|
pub type Point2 = na::Point2<Scalar>;
|
||||||
/// The Color type to use for raytracing
|
/// The Color type to use for raytracing
|
||||||
pub type Color = Vector3;
|
pub type Color = Vector3;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user