Update ray tracing samples to use VK_KHR_ray_tracing (#753)

* Started updating ray tracing samples to KHR extension

* Updated GLSL shaders to use GL_EXT_ray_tracing

* Code cleanup, naming

* Fix include directories to use Vulkan headers from repository instead of NDK for the Android build

* Added new Android function pointers

* Renamed basic ray tracing sample

Added android build files

* Remove unused batch file

* Replaced remaining NV identifiers

* Updating ray tracing shadow sample to KHR extension

* Updated shaders to use KHR instead of NV extension

Fixed shader bindings

* Updating ray tracing reflections sample to KHR extension

* Renamed ray tracing reflections sample

* Renamed ray tracing shadows sample

Added android build files

* Removed no-longer used batch files for shader generation

* Proper alignment for the shader binding table

* Updated readme

* Reworked shader group setup

* Cleanup

* Reworked shader group setup

* Reworked shader group setup

* Code cleanup
This commit is contained in:
Sascha Willems 2020-08-15 17:59:02 +02:00 committed by GitHub
parent e6956acfbd
commit ee946e2abf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
98 changed files with 3291 additions and 2457 deletions

View file

@ -0,0 +1,75 @@
#version 460
#extension GL_EXT_ray_tracing : require
#extension GL_EXT_nonuniform_qualifier : enable
layout(location = 0) rayPayloadInEXT vec3 hitValue;
layout(location = 2) rayPayloadEXT bool shadowed;
hitAttributeEXT vec3 attribs;
layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
layout(binding = 2, set = 0) uniform UBO
{
mat4 viewInverse;
mat4 projInverse;
vec4 lightPos;
int vertexSize;
} ubo;
layout(binding = 3, set = 0) buffer Vertices { vec4 v[]; } vertices;
layout(binding = 4, set = 0) buffer Indices { uint i[]; } indices;
struct Vertex
{
vec3 pos;
vec3 normal;
vec2 uv;
vec4 color;
vec4 _pad0;
vec4 _pad1;
};
Vertex unpack(uint index)
{
// Unpack the vertices from the SSBO using the glTF vertex structure
// The multiplier is the size of the vertex divided by four float components (=16 bytes)
const int m = ubo.vertexSize / 16;
vec4 d0 = vertices.v[m * index + 0];
vec4 d1 = vertices.v[m * index + 1];
vec4 d2 = vertices.v[m * index + 2];
Vertex v;
v.pos = d0.xyz;
v.normal = vec3(d0.w, d1.x, d1.y);
v.color = vec4(d2.x, d2.y, d2.z, 1.0);
return v;
}
void main()
{
ivec3 index = ivec3(indices.i[3 * gl_PrimitiveID], indices.i[3 * gl_PrimitiveID + 1], indices.i[3 * gl_PrimitiveID + 2]);
Vertex v0 = unpack(index.x);
Vertex v1 = unpack(index.y);
Vertex v2 = unpack(index.z);
// Interpolate normal
const vec3 barycentricCoords = vec3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
vec3 normal = normalize(v0.normal * barycentricCoords.x + v1.normal * barycentricCoords.y + v2.normal * barycentricCoords.z);
// Basic lighting
vec3 lightVector = normalize(ubo.lightPos.xyz);
float dot_product = max(dot(lightVector, normal), 0.2);
hitValue = v0.color.rgb * dot_product;
// Shadow casting
float tmin = 0.001;
float tmax = 10000.0;
vec3 origin = gl_WorldRayOriginEXT + gl_WorldRayDirectionEXT * gl_HitTEXT;
shadowed = true;
// Trace shadow ray and offset indices to match shadow hit/miss shader group indices
traceRayEXT(topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT | gl_RayFlagsOpaqueEXT | gl_RayFlagsSkipClosestHitShaderEXT, 0xFF, 1, 0, 1, origin, tmin, lightVector, tmax, 2);
if (shadowed) {
hitValue *= 0.3;
}
}

View file

@ -0,0 +1,9 @@
#version 460
#extension GL_EXT_ray_tracing : require
layout(location = 0) rayPayloadInEXT vec3 hitValue;
void main()
{
hitValue = vec3(0.0, 0.0, 0.2);
}

Binary file not shown.

View file

@ -0,0 +1,33 @@
#version 460
#extension GL_EXT_ray_tracing : require
layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
layout(binding = 1, set = 0, rgba8) uniform image2D image;
layout(binding = 2, set = 0) uniform CameraProperties
{
mat4 viewInverse;
mat4 projInverse;
vec4 lightPos;
} cam;
layout(location = 0) rayPayloadEXT vec3 hitValue;
void main()
{
const vec2 pixelCenter = vec2(gl_LaunchIDEXT.xy) + vec2(0.5);
const vec2 inUV = pixelCenter/vec2(gl_LaunchSizeEXT.xy);
vec2 d = inUV * 2.0 - 1.0;
vec4 origin = cam.viewInverse * vec4(0,0,0,1);
vec4 target = cam.projInverse * vec4(d.x, d.y, 1, 1) ;
vec4 direction = cam.viewInverse*vec4(normalize(target.xyz / target.w), 0) ;
uint rayFlags = gl_RayFlagsOpaqueEXT;
uint cullMask = 0xff;
float tmin = 0.001;
float tmax = 10000.0;
traceRayEXT(topLevelAS, rayFlags, cullMask, 0, 0, 0, origin.xyz, tmin, direction.xyz, tmax, 0);
imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(hitValue, 0.0));
}

Binary file not shown.

View file

@ -0,0 +1,9 @@
#version 460
#extension GL_EXT_ray_tracing : require
layout(location = 2) rayPayloadInEXT bool shadowed;
void main()
{
shadowed = false;
}

Binary file not shown.