Skip to content

Commit

Permalink
work on things add a render workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
float3 committed Mar 31, 2024
1 parent 5c71a28 commit 7f64b36
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
push:
branches:
- master
- dev
workflow_dispatch:

permissions:
contents: write
pages: write
id-token: write

concurrency:
group: "render"

jobs:
deploy:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive

- name: rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh
sh rustup.sh --default-toolchain nightly --profile minimal -y
rustup component add rustfmt clippy --toolchain nightly
source "$HOME/.cargo/env"
rustup update
- name: render
run: |
cargo run --release -- --multiplier=2 --all
- name: commit
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add -A
git commit -m "render"
git push || echo "No changes to commit"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
rustup.sh
lint.sh
Binary file modified output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 24 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,42 @@ use pathtracer::scene::FloatSize;
use png::text_metadata::ITXtChunk;
use toml::Value;

const MULTIPLIER: usize = 2;
const WIDTH: usize = 640 * MULTIPLIER;
const HEIGHT: usize = 360 * MULTIPLIER;
const SAMPLE_COUNT: usize = 256 * MULTIPLIER;

use std::env;
use std::fs;

fn main() {
let args: Vec<String> = env::args().collect();
let pathtracer = PathTracer::new(WIDTH, HEIGHT, SAMPLE_COUNT);

match args.len() {
1 => {
let (multiplier, args_offset) = if args.len() > 1 && args[1].starts_with("--multiplier=") {
let multiplier_str = &args[1]["--multiplier=".len()..];
let multiplier: usize = multiplier_str
.parse()
.expect("Multiplier must be a positive integer");
(multiplier, 2)
} else {
(1, 1)
};

let width = 1280 * multiplier;
let height = 720 * multiplier;
let sample_count = 512 * multiplier;

let pathtracer = PathTracer::new(width, height, sample_count);

match args.len() - args_offset {
0 => {
trace_scene_file("scene.toml", "output.png", &pathtracer);
}
2 if args[1] == "--all" => {
1 if args[args_offset] == "--all" => {
trace_all_scenes(&pathtracer);
}
2 => {
let scene_file = &args[1];
1 => {
let scene_file = &args[args_offset];
let output_file = format!("{}.png", scene_file.trim_end_matches(".toml"));
trace_scene_file(scene_file, &output_file, &pathtracer);
}
_ => {
println!("Usage: pathtracer [scene_file.toml] or --all");
println!("Usage: pathtracer [--multiplier=N] [scene_file.toml] or --all");
}
}
}
Expand All @@ -44,8 +54,8 @@ fn trace_scene_file(scene_file: &str, output_file: &str, pathtracer: &PathTracer

let mut encoder = png::Encoder::new(
std::fs::File::create(output_file).unwrap(),
WIDTH as u32,
HEIGHT as u32,
pathtracer.width as u32,
pathtracer.height as u32,
);
encoder.set_color(png::ColorType::Rgb);
encoder.set_depth(png::BitDepth::Eight);
Expand Down
4 changes: 2 additions & 2 deletions src/pathtracer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::utils::vector::Vec3;
use rayon::prelude::*;

pub struct PathTracer {
width: usize,
height: usize,
pub width: usize,
pub height: usize,
samples: usize,
}

Expand Down

0 comments on commit 7f64b36

Please sign in to comment.