Skip to content

Commit

Permalink
Add KHR ray tracing demo
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Mar 19, 2021
1 parent 0c3b5c4 commit b7e34e5
Show file tree
Hide file tree
Showing 5 changed files with 1,680 additions and 522 deletions.
12 changes: 12 additions & 0 deletions res/org/lwjgl/demo/vulkan/khrraytracing/closesthit.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
#version 460
#extension GL_EXT_ray_tracing : enable

layout(location = 0) rayPayloadInEXT bool payload;

void main(void) {
payload = true;
}
39 changes: 39 additions & 0 deletions res/org/lwjgl/demo/vulkan/khrraytracing/raygen.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
#version 460
#extension GL_EXT_ray_tracing : enable

layout(location = 0) rayPayloadEXT bool payload;
layout(binding = 0, set = 0) uniform accelerationStructureEXT acc;
layout(binding = 1, set = 0, rgba8) uniform image2D image;
layout(binding = 2, set = 0) uniform Camera {
mat4 projInverse;
mat4 viewInverse;
} cam;

void main(void) {
vec2 px = vec2(gl_LaunchIDEXT.xy) + vec2(0.5);
vec2 ndc = (px / vec2(gl_LaunchSizeEXT.xy)) * 2.0 - vec2(1.0);
vec3 origin = cam.viewInverse[3].xyz;
vec4 target = cam.projInverse * vec4(ndc, 0.0, 1.0);
vec4 direction = cam.viewInverse * vec4(normalize(target.xyz), 0.0);
uint rayFlags = gl_RayFlagsOpaqueEXT | gl_RayFlagsCullBackFacingTrianglesEXT;
float tMin = 0.1;
float tMax = 100.0;
traceRayEXT(
acc, // acceleration structure
rayFlags, // rayFlags
0xFF, // cullMask
0, // sbtRecordOffset
0, // sbtRecordStride
0, // missIndex
origin, // ray origin
tMin, // ray min range
direction.xyz, // ray direction
tMax, // ray max range
0 // payload (location = 0)
);
imageStore(image, ivec2(gl_LaunchIDEXT), payload ? vec4(1.0) : vec4(0.0));
}
12 changes: 12 additions & 0 deletions res/org/lwjgl/demo/vulkan/khrraytracing/raymiss.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
#version 460
#extension GL_EXT_ray_tracing : enable

layout(location = 0) rayPayloadInEXT bool payload;

void main(void) {
payload = false;
}
Loading

0 comments on commit b7e34e5

Please sign in to comment.