Skip to content

Commit

Permalink
fix spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Nov 17, 2023
1 parent eb0c2f6 commit 1365c1d
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 67 deletions.
1 change: 1 addition & 0 deletions luisa_compute/examples/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
21 changes: 13 additions & 8 deletions luisa_compute/examples/path_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use luisa::lang::types::vector::alias::*;
use luisa::lang::types::vector::*;
use luisa::prelude::*;
use luisa::rtx::{
offset_ray_origin, Accel, AccelBuildRequest, AccelOption, AccelVar, Index, Ray, RayComps,
offset_ray_origin, Accel, AccelBuildRequest, AccelOption, AccelVar, Index, Ray, RayComps, AccelTraceOptions,
};
use luisa_compute as luisa;

Expand Down Expand Up @@ -354,20 +354,25 @@ fn main() {

let depth = Var::<u32>::zeroed();
while depth < 10u32 {
let hit = accel.trace_closest(**ray);
let trace_options = AccelTraceOptions {
mask:0xff.expr(),
..Default::default()
};
let hit = accel.intersect(ray, trace_options);

if !hit.valid() {
break;
}

let vertex_buffer = vertex_heap.buffer::<[f32; 3]>(hit.inst_id);
let triangle = index_heap.buffer::<Index>(hit.inst_id).read(hit.prim_id);
let vertex_buffer = vertex_heap.buffer::<[f32; 3]>(hit.inst);
let triangle = index_heap.buffer::<Index>(hit.inst).read(hit.prim);

let p0: Expr<Float3> = vertex_buffer.read(triangle[0]).into();
let p1: Expr<Float3> = vertex_buffer.read(triangle[1]).into();
let p2: Expr<Float3> = vertex_buffer.read(triangle[2]).into();

let p = p0 * (1.0f32 - hit.u - hit.v) + p1 * hit.u + p2 * hit.v;
let bary = hit.triangle_barycentric_coord();
let p = p0 * (1.0f32 - bary.x - bary.y) + p1 * bary.x + p2 * bary.y;
let n = (p1 - p0).cross(p2 - p0).normalize();

let origin: Expr<Float3> = (**ray.orig).into();
Expand All @@ -377,9 +382,9 @@ fn main() {
break;
}
let pp = offset_ray_origin(p, n);
let albedo = cbox_materials.read(hit.inst_id);
let albedo = cbox_materials.read(hit.inst);
// hit light
if hit.inst_id == 7u32 {
if hit.inst == 7u32 {
if depth == 0u32 {
radiance.store(radiance + light_emission);
} else {
Expand All @@ -399,7 +404,7 @@ fn main() {
let wi_light = (pp_light - pp).normalize();
let shadow_ray =
make_ray(offset_ray_origin(pp, n), wi_light, 0.0f32.expr(), d_light);
let occluded = accel.trace_any(shadow_ray);
let occluded = accel.intersect_any(shadow_ray, trace_options);
let cos_wi_light = wi_light.dot(n);
let cos_light = -light_normal.dot(wi_light);

Expand Down
59 changes: 26 additions & 33 deletions luisa_compute/examples/path_tracer_cutout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use image::Rgb;
use luisa::lang::types::vector::alias::*;
use luisa::lang::types::vector::Mat4;
use luisa::rtx::AccelTraceOptions;
use luisa_compute_api_types::StreamTag;
use rand::Rng;
use std::env::current_exe;
Expand Down Expand Up @@ -372,35 +373,31 @@ fn main() {

let depth = Var::<u32>::zeroed();
while depth < 10 {
// let hit = accel.trace_closest(ray);
let hit = accel.query_all(
ray,
255,
RayQuery {
on_triangle_hit: |c: SurfaceCandidate| {
if filter(&c) {
c.commit();
}
},
on_procedural_hit: |_c| {},
},
);
let trace_options = AccelTraceOptions {
mask: 0xff.expr(),
..Default::default()
};
let hit = accel
.traverse(ray, trace_options)
.on_surface_hit(|c: SurfaceCandidate| {
if filter(&c) {
c.commit();
}
})
.trace();

if hit.miss() {
break;
}

let vertex_buffer = vertex_heap.var().buffer::<[f32; 3]>(hit.inst_id);
let triangle = index_heap
.var()
.buffer::<Index>(hit.inst_id)
.read(hit.prim_id);
let vertex_buffer = vertex_heap.var().buffer::<[f32; 3]>(hit.inst);
let triangle = index_heap.var().buffer::<Index>(hit.inst).read(hit.prim);

let p0: Expr<Float3> = vertex_buffer.read(triangle[0]).into();
let p1: Expr<Float3> = vertex_buffer.read(triangle[1]).into();
let p2: Expr<Float3> = vertex_buffer.read(triangle[2]).into();

let m = accel.instance_transform(hit.inst_id);
let m = accel.instance_transform(hit.inst);
let p =
p0 * (1.0f32 - hit.bary.x - hit.bary.y) + p1 * hit.bary.x + p2 * hit.bary.y;
let p = (m * Float4::expr(p.x, p.y, p.z, 1.0f32)).xyz();
Expand All @@ -414,9 +411,9 @@ fn main() {
break;
}
let pp = offset_ray_origin(p, n);
let albedo = cbox_materials.read(hit.inst_id);
let albedo = cbox_materials.read(hit.inst);
// hit light
if hit.inst_id == 7u32 {
if hit.inst == 7u32 {
if depth == 0u32 {
radiance.store(radiance + light_emission);
} else {
Expand All @@ -436,18 +433,14 @@ fn main() {
let wi_light = (pp_light - pp).normalize();
let shadow_ray =
make_ray(offset_ray_origin(pp, n), wi_light, 0.0f32.expr(), d_light);
let occluded = accel.query_any(
shadow_ray,
255,
RayQuery {
on_triangle_hit: |c: SurfaceCandidate| {
if_!(filter(&c), {
c.commit();
});
},
on_procedural_hit: |_c| {},
},
);
let occluded = accel
.traverse_any(shadow_ray, trace_options)
.on_surface_hit(|c: SurfaceCandidate| {
if filter(&c) {
c.commit();
}
})
.trace();
let occluded = !occluded.miss();
let cos_wi_light = wi_light.dot(n);
let cos_light = -light_normal.dot(wi_light);
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute/examples/ray_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn main() {
uvw
} else {
if hit.procedural_hit() {
let prim = hit.prim_id;
let prim = hit.prim;
let sphere = spheres.var().read(prim);
let normal = (Expr::<Float3>::from(ray.orig)
+ Expr::<Float3>::from(ray.dir) * hit.committed_ray_t
Expand Down
12 changes: 9 additions & 3 deletions luisa_compute/examples/raytracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use luisa::lang::types::vector::*;
use luisa::lang::types::*;

use luisa::prelude::*;
use luisa::rtx::{AccelBuildRequest, AccelOption, Ray};
use luisa::rtx::{AccelBuildRequest, AccelOption, AccelTraceOptions, Ray};
use luisa_compute as luisa;
use winit::event::{Event as WinitEvent, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
Expand Down Expand Up @@ -54,11 +54,17 @@ fn main() {
Expr::<[f32; 3]>::from(d),
1e9,
);
let hit = accel.trace_closest(ray);
let hit = accel.intersect(
ray,
AccelTraceOptions {
mask: 0xff.expr(),
..Default::default()
},
);
let img = img.view(0).var();
let color = select(
hit.valid(),
Float3::expr(hit.u, hit.v, 1.0),
hit.triangle_barycentric_coord().extend(1.0),
Float3::expr(0.0, 0.0, 0.0),
);
img.write(px, Float4::expr(color.x, color.y, color.z, 1.0));
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute/src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ pub(crate) struct FnRecorder {
pub(crate) type FnRecorderPtr = Rc<RefCell<FnRecorder>>;
impl FnRecorder {
pub(crate) fn add_required_curve_basis(&mut self, basis: CurveBasisSet) {
self.curve_bases.merge(basis);
self.curve_bases.insert(basis);
}
pub(crate) fn make_index_const(&mut self, idx: i32) -> NodeRef {
if let Some(node) = self.index_const_pool.get(&idx) {
Expand Down
Loading

0 comments on commit 1365c1d

Please sign in to comment.