Skip to content

Commit 1f622c9

Browse files
committed
WIP ray-tracing-pipeline example
1 parent 2b1fdf0 commit 1f622c9

10 files changed

+1305
-0
lines changed

examples/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ path = "mesh-shading/main.rs"
3434
name = "bench"
3535
path = "bench/main.rs"
3636

37+
[[bin]]
38+
name = "ray-tracing"
39+
path = "ray-tracing/main.rs"
40+
3741
[dependencies]
3842
image = "0.23.12"
3943
log = "0.4"
4044
hal = { path = "../src/hal", version = "0.8", package = "gfx-hal" }
4145
auxil = { path = "../src/auxil/auxil", version = "0.9", package = "gfx-auxil" }
4246
gfx-backend-empty = { path = "../src/backend/empty", version = "0.8" }
4347
winit = { version = "0.24", features = ["web-sys"] }
48+
cgmath = "0.18.0"
4449

4550
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4651
env_logger = "0.8"

examples/ray-tracing/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ray Tracing
2+
3+
TODO
4+
5+
- Screenshot
6+
- Explain which backends this supports
7+
- Explain what hardware this supports
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$shaders = @(
2+
"$PSScriptRoot\data\simple.rchit"
3+
"$PSScriptRoot\data\simple.rgen"
4+
"$PSScriptRoot\data\simple.rmiss"
5+
)
6+
7+
Remove-Item $PSScriptRoot\data\*.spv
8+
9+
foreach ($shader in $shaders) {
10+
& glslangValidator --target-env vulkan1.2 --entry-point main $shader -o "$shader.spv"
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#version 460
2+
#extension GL_EXT_ray_tracing : enable
3+
4+
layout(location = 0) rayPayloadInEXT vec3 out_color;
5+
hitAttributeEXT vec3 attribs;
6+
7+
void main() {
8+
out_color = vec3(1.0, 0.0, 0.0);
9+
}
436 Bytes
Binary file not shown.

examples/ray-tracing/data/simple.rgen

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#version 460
2+
#extension GL_EXT_ray_tracing : enable
3+
4+
layout(binding = 0, set = 0) uniform accelerationStructureEXT accel_struct;
5+
layout(binding = 1, set = 0, rgba8) uniform image2D storage_image;
6+
layout(binding = 2, set = 0) uniform CameraProperties {
7+
mat4 view_inverse;
8+
mat4 proj_inverse;
9+
}
10+
cam;
11+
12+
layout(location = 0) rayPayloadEXT vec3 out_color;
13+
14+
void main() {
15+
const vec2 pixel_center = vec2(gl_LaunchIDEXT.xy) + vec2(0.5);
16+
const vec2 in_uv = pixel_center / vec2(gl_LaunchSizeEXT.xy);
17+
vec2 d = in_uv * 2.0 - 1.0;
18+
19+
vec4 origin = cam.view_inverse * vec4(0, 0, 0, 1);
20+
vec4 target = cam.proj_inverse * vec4(d.x, d.y, 1, 1);
21+
vec4 direction = cam.view_inverse * vec4(normalize(target.xyz), 0);
22+
23+
out_color = vec3(0.0);
24+
25+
origin.xyz = vec3(0, 0, 1);
26+
direction.xyz = vec3(0, 0, -1);
27+
28+
float tmin = 0.001;
29+
float tmax = 10000.0;
30+
traceRayEXT(accel_struct, gl_RayFlagsOpaqueEXT, 0xff, 0, 0, 0, origin.xyz,
31+
tmin, direction.xyz, tmax, 0);
32+
33+
imageStore(storage_image, ivec2(gl_LaunchIDEXT.xy), vec4(out_color, 1.0));
34+
}
2.99 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#version 460
2+
#extension GL_EXT_ray_tracing : enable
3+
4+
layout(location = 0) rayPayloadInEXT vec3 out_color;
5+
6+
void main() { out_color = vec3(0.8, 0.8, 0.8); }
368 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)