-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4e2b81
commit 48d98a0
Showing
9 changed files
with
234 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
use std::env; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
let out = cmake::Config::new("ext/assimp") | ||
.no_build_target(true) | ||
.build(); | ||
dbg!(out.display()); | ||
println!("cargo:rustc-link-search=native={}/build/bin", out.display()); | ||
println!("cargo:rustc-link-lib=dylib=assimpd"); | ||
match env::var("PROFILE") { | ||
Ok(x) => { | ||
if x == "release" { | ||
println!("cargo:rustc-link-lib=dylib=assimp"); | ||
} else if x == "debug" { | ||
println!("cargo:rustc-link-lib=dylib=assimpd"); | ||
} | ||
} | ||
_ => unreachable!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"method":{ | ||
"type":"pt", | ||
"use_nee":false | ||
}, | ||
"out":"output/vanilla.exr" | ||
}, | ||
{ | ||
"method":{ | ||
"type":"pt", | ||
"use_nee":true | ||
}, | ||
"out":"output/nee.exr" | ||
}, | ||
{ | ||
"method":{ | ||
"type":"mcmc" | ||
}, | ||
"out":"output/mcmc.exr" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,46 @@ | ||
use akari_render::{ | ||
film::{Film, FilmColorRepr}, | ||
integrator::{ | ||
mcmc::{self, MCMC}, | ||
mcmc::{self, Mcmc}, | ||
normal::NormalVis, | ||
pt::PathTracer, | ||
Integrator, | ||
render, Integrator, RenderTask, | ||
}, | ||
}; | ||
use clap::{arg, Arg, Command}; | ||
use luisa_compute as luisa; | ||
use std::{env::current_exe, process::exit}; | ||
use std::{env::current_exe, fs::File, process::exit}; | ||
fn main() { | ||
luisa::init_logger(); | ||
let mut cmd = Command::new("akari_cli") | ||
.allow_missing_positional(false) | ||
.arg(Arg::new("scene").help("Scene file to render")) | ||
.arg(arg!(-s --scene <SCENE> "Scene file to render")) | ||
.arg(arg!(-m --method <METHOD> "Render method config file")) | ||
.arg( | ||
arg!(-d --device <DEVICE> "Compute device. One of: cpu, cuda, dx, metal. Default: cpu"), | ||
) | ||
.arg(arg!(-o --output <FILE> "Output file name. Default: out.png")) | ||
.arg(arg!(--spp <SPP> "Set samples per pixel, override existing value")); | ||
); | ||
let help = cmd.render_help(); | ||
let matches = cmd.get_matches(); | ||
let scene = matches.get_one::<String>("scene"); | ||
let output = matches | ||
.get_one::<String>("output") | ||
.cloned() | ||
.unwrap_or("out.png".to_string()); | ||
let spp = matches | ||
.get_one::<String>("spp") | ||
.map(|s| s.parse::<u32>().unwrap()); | ||
let method = matches.get_one::<String>("method"); | ||
if scene.is_none() { | ||
println!("{}", help); | ||
exit(1); | ||
} | ||
if method.is_none() { | ||
println!("{}", help); | ||
exit(1); | ||
} | ||
let device = matches | ||
.get_one::<String>("device") | ||
.cloned() | ||
.unwrap_or("cpu".to_string()); | ||
let ctx = luisa::Context::new(current_exe().unwrap()); | ||
let device = ctx.create_device(&device); | ||
let method = method.unwrap(); | ||
let task: RenderTask = { | ||
let file = File::open(method).unwrap(); | ||
serde_json::from_reader(file).unwrap() | ||
}; | ||
let scene = akari_render::scene::Scene::load(device.clone(), &scene.unwrap()); | ||
let mut film = Film::new( | ||
device.clone(), | ||
scene.camera.resolution(), | ||
FilmColorRepr::SRgb, | ||
); | ||
let output_image: luisa::Tex2d<luisa::Float4> = device.create_tex2d( | ||
luisa::PixelStorage::Float4, | ||
scene.camera.resolution().x, | ||
scene.camera.resolution().y, | ||
1, | ||
); | ||
// { | ||
// let normal_vis = NormalVis::new(device.clone(), 1); | ||
// normal_vis.render(&scene, &mut film).unwrap_or_else(|e| { | ||
// println!("Render failed: {:?}", e); | ||
// exit(1); | ||
// }); | ||
// } | ||
let tic = std::time::Instant::now(); | ||
// { | ||
// let pt = PathTracer::new(device.clone(), spp.unwrap_or(1), 64, 5, true); | ||
// pt.render(&scene, &mut film); | ||
// } | ||
{ | ||
let mcmc = MCMC::new( | ||
device.clone(), | ||
spp.unwrap_or(1), | ||
1, | ||
5, | ||
true, | ||
mcmc::Method::Kelemen { | ||
small_sigma: 0.01, | ||
large_step_prob: 0.1, | ||
}, | ||
100, | ||
100000, | ||
); | ||
mcmc.render(&scene, &mut film); | ||
} | ||
film.copy_to_rgba_image(&output_image); | ||
let toc = std::time::Instant::now(); | ||
log::info!("Rendered in {:.1}ms", (toc - tic).as_secs_f64() * 1e3); | ||
|
||
akari_render::util::write_image(&output_image, &output); | ||
render(device, &scene, &task); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,70 @@ | ||
use crate::{*, camera::*, film::*, scene::*}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{film::*, scene::*, *}; | ||
|
||
pub trait Integrator { | ||
fn render(&self, scene: &Scene, film: &mut Film); | ||
} | ||
|
||
pub mod pt; | ||
pub mod gpt; | ||
pub mod mcmc; | ||
pub mod normal; | ||
pub mod mcmc; | ||
pub mod pt; | ||
|
||
#[derive(Clone, Serialize, Deserialize)] | ||
#[serde(tag = "type")] | ||
pub enum Method { | ||
#[serde(rename = "pt")] | ||
PathTracer(pt::Config), | ||
#[serde(rename = "mcmc")] | ||
Mcmc(mcmc::Config), | ||
} | ||
#[derive(Clone, Serialize, Deserialize)] | ||
pub struct RenderConfig { | ||
pub method: Method, | ||
pub out: String, | ||
} | ||
#[derive(Clone, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum RenderTask { | ||
Single(RenderConfig), | ||
Multi(Vec<RenderConfig>), | ||
} | ||
|
||
pub fn render(device: Device, scene: &Scene, task: &RenderTask) { | ||
fn render_single(device: Device, scene: &Scene, config: &RenderConfig) { | ||
let mut film = Film::new( | ||
device.clone(), | ||
scene.camera.resolution(), | ||
FilmColorRepr::SRgb, | ||
); | ||
let output_image: luisa::Tex2d<luisa::Float4> = device.create_tex2d( | ||
luisa::PixelStorage::Float4, | ||
scene.camera.resolution().x, | ||
scene.camera.resolution().y, | ||
1, | ||
); | ||
let tic = std::time::Instant::now(); | ||
match &config.method { | ||
Method::PathTracer(config) => pt::render(device.clone(), scene, &mut film, &config), | ||
Method::Mcmc(config) => mcmc::render(device.clone(), scene, &mut film, &config), | ||
} | ||
let toc = std::time::Instant::now(); | ||
log::info!("Rendered in {:.1}ms", (toc - tic).as_secs_f64() * 1e3); | ||
film.copy_to_rgba_image(&output_image); | ||
util::write_image(&output_image, &config.out); | ||
} | ||
match task { | ||
RenderTask::Single(config) => render_single(device, scene, config), | ||
RenderTask::Multi(configs) => { | ||
let tic = std::time::Instant::now(); | ||
log::info!("Rendering with {} methods", configs.len()); | ||
for (i, config) in configs.iter().enumerate() { | ||
log::info!("Rendering {}/{}", i + 1, configs.len()); | ||
render_single(device.clone(), scene, config) | ||
} | ||
let toc = std::time::Instant::now(); | ||
log::info!("Rendered in {:.3}s", (toc - tic).as_secs_f64()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,4 @@ impl Integrator for NormalVis { | |
}); | ||
} | ||
} | ||
|
Oops, something went wrong.