Skip to content

Commit

Permalink
Merge pull request brson#3 from 23Skidoo/master
Browse files Browse the repository at this point in the history
Misc small fixes to make rustray compile with rustc 0.3
  • Loading branch information
brson committed Jul 13, 2012
2 parents 75113fb + 6bb73f9 commit e87488d
Show file tree
Hide file tree
Showing 7 changed files with 976 additions and 981 deletions.
5 changes: 3 additions & 2 deletions README.txt
Expand Up @@ -3,6 +3,9 @@ January 2012

A raytracing proof-of-concept in Rust

COMPILING:
$ rustc -W no-old-vecs rustray.rc

DEMO:
$ wget http://groups.csail.mit.edu/graphics/classes/6.837/F03/models/cow-nonormals.obj
$ ./rustray cow-nonormals.obj
Expand All @@ -15,5 +18,3 @@ DEMO:
Tracing rays... Done!
Writing "./oput.ppm"...Done!
$ gimp oput.ppm


10 changes: 10 additions & 0 deletions consts.rs
@@ -0,0 +1,10 @@
// TODO: These things should all be overridable by the command line
const WIDTH : uint = 256u;
const HEIGHT : uint = 256u;
const FOV : f32 = 3.14159f32 / 3f32 ;
const SAMPLE_GRID_SIZE : uint = 1u;
const NUM_GI_SAMPLES_SQRT: uint = 8u;
const NUM_LIGHT_SAMPLES : uint = 32u;
const MAX_TRACE_DEPTH : uint = 3u;
const USE_SMOOTH_NORMALS_FOR_GI : bool = true;
const USE_SMOOTH_NORMALS_FOR_DIRECT_LIGHTING : bool = true;
64 changes: 27 additions & 37 deletions main.rs
@@ -1,26 +1,16 @@
import io::writer_util;
import io::writer;
import consts::*;
import raytracer::*;

// TODO: These things should all be overridable by the command line
const WIDTH : uint = 256u;
const HEIGHT : uint = 256u;
const FOV : f32 = 3.14159f32 / 3f32 ;
const SAMPLE_GRID_SIZE : uint = 1u;
const NUM_GI_SAMPLES_SQRT: uint = 8u;
const NUM_LIGHT_SAMPLES : uint = 32u;
const MAX_TRACE_DEPTH : uint = 3u;
const USE_SMOOTH_NORMALS_FOR_GI : bool = true;
const USE_SMOOTH_NORMALS_FOR_DIRECT_LIGHTING : bool = true;

fn write_ppm( fname: str, width: uint, height: uint, pixels: [color] ){

let writer = result::get( io::file_writer( fname, [io::create, io::truncate] ) );
let writer = result::get( io::file_writer( fname, [io::create, io::truncate] ) );

writer.write_str(#fmt("P6\n%u %u\n255\n", width, height));
for pixels.each |pixel| {
writer.write([pixel.r, pixel.g, pixel.b]);
};
writer.write_str(#fmt("P6\n%u %u\n255\n", width, height));
for pixels.each |pixel| {
writer.write([pixel.r, pixel.g, pixel.b]);
};
}

fn main( args: [str] )
Expand All @@ -35,29 +25,29 @@ fn main( args: [str] )
io::println("");
fail;
}

let start = std::time::precise_time_s();


let start = std::time::precise_time_s();


io::println("Reading \"" + args[1] + "\"...");
let model = model::read_mesh( args[1] );
let {depth,count} = model::count_kd_tree_nodes( model.kd_tree );

io::println(#fmt("Done.\nLoaded model.\n\tVerts: %u, Tris: %u\n\tKD-tree depth: %u, #nodes: %u",
vec::len(model.polys.vertices),
vec::len(model.polys.indices)/3u,
depth, count));

io::print("Tracing rays... ");
let start_tracing = std::time::precise_time_s();
let pixels = raytracer::generate_raytraced_image(model, FOV, WIDTH, HEIGHT, SAMPLE_GRID_SIZE);
io::println("Done!");
let model = model::read_mesh( args[1] );
let {depth,count} = model::count_kd_tree_nodes( model.kd_tree );

io::println(#fmt("Done.\nLoaded model.\n\tVerts: %u, Tris: %u\n\tKD-tree depth: %u, #nodes: %u",
vec::len(model.polys.vertices),
vec::len(model.polys.indices)/3u,
depth, count));

io::print("Tracing rays... ");
let start_tracing = std::time::precise_time_s();
let pixels = raytracer::generate_raytraced_image(model, FOV, WIDTH, HEIGHT, SAMPLE_GRID_SIZE);
io::println("Done!");

let outputfile = "./oput.ppm";
io::print("Writing \"" + outputfile + "\"...");
write_ppm( outputfile, WIDTH, HEIGHT, pixels );
io::println("Done!");
let end = std::time::precise_time_s();
io::print("Writing \"" + outputfile + "\"...");
write_ppm( outputfile, WIDTH, HEIGHT, pixels );
io::println("Done!");

let end = std::time::precise_time_s();
io::print(#fmt("Total time: %3.3fs, of which tracing: %3.3f\n", end - start, end - start_tracing) );
}

0 comments on commit e87488d

Please sign in to comment.