Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP acceleration structure API proposal #3544

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/Cargo.toml
Expand Up @@ -34,13 +34,18 @@ path = "mesh-shading/main.rs"
name = "bench"
path = "bench/main.rs"

[[bin]]
name = "ray-tracing"
path = "ray-tracing/main.rs"

[dependencies]
image = "0.23.12"
log = "0.4"
hal = { path = "../src/hal", version = "0.8", package = "gfx-hal" }
auxil = { path = "../src/auxil/auxil", version = "0.9", package = "gfx-auxil" }
gfx-backend-empty = { path = "../src/backend/empty", version = "0.8" }
winit = { version = "0.24", features = ["web-sys"] }
cgmath = "0.18.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.8"
Expand Down
7 changes: 7 additions & 0 deletions examples/ray-tracing/README.md
@@ -0,0 +1,7 @@
# Ray Tracing

TODO

- Screenshot
- Explain which backends this supports
- Explain what hardware this supports
11 changes: 11 additions & 0 deletions examples/ray-tracing/build-shaders.ps1
@@ -0,0 +1,11 @@
$shaders = @(
"$PSScriptRoot\data\simple.rchit"
"$PSScriptRoot\data\simple.rgen"
"$PSScriptRoot\data\simple.rmiss"
)

Remove-Item $PSScriptRoot\data\*.spv

foreach ($shader in $shaders) {
& glslangValidator --target-env vulkan1.2 --entry-point main $shader -o "$shader.spv"
}
9 changes: 9 additions & 0 deletions examples/ray-tracing/data/simple.rchit
@@ -0,0 +1,9 @@
#version 460
#extension GL_EXT_ray_tracing : enable

layout(location = 0) rayPayloadInEXT vec3 out_color;
hitAttributeEXT vec3 attribs;

void main() {
out_color = vec3(1.0, 0.0, 0.0);
}
Binary file added examples/ray-tracing/data/simple.rchit.spv
Binary file not shown.
34 changes: 34 additions & 0 deletions examples/ray-tracing/data/simple.rgen
@@ -0,0 +1,34 @@
#version 460
#extension GL_EXT_ray_tracing : enable

layout(binding = 0, set = 0) uniform accelerationStructureEXT accel_struct;
layout(binding = 1, set = 0, rgba8) uniform image2D storage_image;
layout(binding = 2, set = 0) uniform CameraProperties {
mat4 view_inverse;
mat4 proj_inverse;
}
cam;

layout(location = 0) rayPayloadEXT vec3 out_color;

void main() {
const vec2 pixel_center = vec2(gl_LaunchIDEXT.xy) + vec2(0.5);
const vec2 in_uv = pixel_center / vec2(gl_LaunchSizeEXT.xy);
vec2 d = in_uv * 2.0 - 1.0;

vec4 origin = cam.view_inverse * vec4(0, 0, 0, 1);
vec4 target = cam.proj_inverse * vec4(d.x, d.y, 1, 1);
vec4 direction = cam.view_inverse * vec4(normalize(target.xyz), 0);

out_color = vec3(0.0);

origin.xyz = vec3(0, 0, 1);
direction.xyz = vec3(0, 0, -1);

float tmin = 0.001;
float tmax = 10000.0;
traceRayEXT(accel_struct, gl_RayFlagsOpaqueEXT, 0xff, 0, 0, 0, origin.xyz,
tmin, direction.xyz, tmax, 0);

imageStore(storage_image, ivec2(gl_LaunchIDEXT.xy), vec4(out_color, 1.0));
}
Binary file added examples/ray-tracing/data/simple.rgen.spv
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/ray-tracing/data/simple.rmiss
@@ -0,0 +1,6 @@
#version 460
#extension GL_EXT_ray_tracing : enable

layout(location = 0) rayPayloadInEXT vec3 out_color;

void main() { out_color = vec3(0.8, 0.8, 0.8); }
Binary file added examples/ray-tracing/data/simple.rmiss.spv
Binary file not shown.