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:
parent
e6956acfbd
commit
ee946e2abf
98 changed files with 3291 additions and 2457 deletions
85
data/shaders/hlsl/raytracingshadows/closesthit.rchit
Normal file
85
data/shaders/hlsl/raytracingshadows/closesthit.rchit
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
struct InPayload
|
||||
{
|
||||
[[vk::location(0)]] float3 hitValue;
|
||||
};
|
||||
|
||||
struct InOutPayload
|
||||
{
|
||||
[[vk::location(2)]] bool shadowed;
|
||||
};
|
||||
|
||||
RaytracingAccelerationStructure topLevelAS : register(t0);
|
||||
struct UBO
|
||||
{
|
||||
float4x4 viewInverse;
|
||||
float4x4 projInverse;
|
||||
float4 lightPos;
|
||||
int vertexSize;
|
||||
};
|
||||
cbuffer ubo : register(b2) { UBO ubo; };
|
||||
|
||||
StructuredBuffer<float4> vertices : register(t3);
|
||||
StructuredBuffer<uint> indices : register(t4);
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
float3 pos;
|
||||
float3 normal;
|
||||
float2 uv;
|
||||
float4 color;
|
||||
float4 _pad0;
|
||||
float4 _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;
|
||||
|
||||
float4 d0 = vertices[m * index + 0];
|
||||
float4 d1 = vertices[m * index + 1];
|
||||
float4 d2 = vertices[m * index + 2];
|
||||
|
||||
Vertex v;
|
||||
v.pos = d0.xyz;
|
||||
v.normal = float3(d0.w, d1.x, d1.y);
|
||||
v.color = float4(d2.x, d2.y, d2.z, 1.0);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
[shader("closesthit")]
|
||||
void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float3 attribs)
|
||||
{
|
||||
uint PrimitiveID = PrimitiveIndex();
|
||||
int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
|
||||
|
||||
Vertex v0 = unpack(index.x);
|
||||
Vertex v1 = unpack(index.y);
|
||||
Vertex v2 = unpack(index.z);
|
||||
|
||||
// Interpolate normal
|
||||
const float3 barycentricCoords = float3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
|
||||
float3 normal = normalize(v0.normal * barycentricCoords.x + v1.normal * barycentricCoords.y + v2.normal * barycentricCoords.z);
|
||||
|
||||
// Basic lighting
|
||||
float3 lightVector = normalize(ubo.lightPos.xyz);
|
||||
float dot_product = max(dot(lightVector, normal), 0.2);
|
||||
inPayload.hitValue = v0.color.rgb * dot_product;
|
||||
|
||||
RayDesc rayDesc;
|
||||
rayDesc.Origin = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();
|
||||
rayDesc.Direction = lightVector;
|
||||
rayDesc.TMin = 0.001;
|
||||
rayDesc.TMax = 100.0;
|
||||
|
||||
inOutPayload.shadowed = true;
|
||||
// Offset indices to match shadow hit/miss index
|
||||
TraceRay(topLevelAS, RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_FORCE_OPAQUE | RAY_FLAG_SKIP_CLOSEST_HIT_SHADER, 0xff, 1, 0, 1, rayDesc, inOutPayload);
|
||||
if (inOutPayload.shadowed) {
|
||||
inPayload.hitValue *= 0.3;
|
||||
}
|
||||
}
|
||||
BIN
data/shaders/hlsl/raytracingshadows/closesthit.rchit.spv
Normal file
BIN
data/shaders/hlsl/raytracingshadows/closesthit.rchit.spv
Normal file
Binary file not shown.
7
data/shaders/hlsl/raytracingshadows/miss.rmiss
Normal file
7
data/shaders/hlsl/raytracingshadows/miss.rmiss
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
[shader("miss")]
|
||||
void main([[vk::location(0)]] in float3 hitValue)
|
||||
{
|
||||
hitValue = float3(0.0, 0.0, 0.2);
|
||||
}
|
||||
BIN
data/shaders/hlsl/raytracingshadows/miss.rmiss.spv
Normal file
BIN
data/shaders/hlsl/raytracingshadows/miss.rmiss.spv
Normal file
Binary file not shown.
40
data/shaders/hlsl/raytracingshadows/raygen.rgen
Normal file
40
data/shaders/hlsl/raytracingshadows/raygen.rgen
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
RaytracingAccelerationStructure rs : register(t0);
|
||||
RWTexture2D<float4> image : register(u1);
|
||||
|
||||
struct CameraProperties
|
||||
{
|
||||
float4x4 viewInverse;
|
||||
float4x4 projInverse;
|
||||
float4 lightPos;
|
||||
};
|
||||
cbuffer cam : register(b2) { CameraProperties cam; };
|
||||
|
||||
struct Payload
|
||||
{
|
||||
[[vk::location(0)]] float3 hitValue;
|
||||
};
|
||||
|
||||
[shader("raygeneration")]
|
||||
void main()
|
||||
{
|
||||
uint3 LaunchID = DispatchRaysIndex();
|
||||
uint3 LaunchSize = DispatchRaysDimensions();
|
||||
|
||||
const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5, 0.5);
|
||||
const float2 inUV = pixelCenter/float2(LaunchSize.xy);
|
||||
float2 d = inUV * 2.0 - 1.0;
|
||||
float4 target = mul(cam.projInverse, float4(d.x, d.y, 1, 1));
|
||||
|
||||
RayDesc rayDesc;
|
||||
rayDesc.Origin = mul(cam.viewInverse, float4(0,0,0,1)).xyz;
|
||||
rayDesc.Direction = mul(cam.viewInverse, float4(normalize(target.xyz), 0)).xyz;
|
||||
rayDesc.TMin = 0.001;
|
||||
rayDesc.TMax = 10000.0;
|
||||
|
||||
Payload payload;
|
||||
TraceRay(rs, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload);
|
||||
|
||||
image[int2(LaunchID.xy)] = float4(payload.hitValue, 0.0);
|
||||
}
|
||||
BIN
data/shaders/hlsl/raytracingshadows/raygen.rgen.spv
Normal file
BIN
data/shaders/hlsl/raytracingshadows/raygen.rgen.spv
Normal file
Binary file not shown.
7
data/shaders/hlsl/raytracingshadows/shadow.rmiss
Normal file
7
data/shaders/hlsl/raytracingshadows/shadow.rmiss
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright 2020 Google LLC
|
||||
|
||||
[shader("miss")]
|
||||
void main([[vk::location(2)]] in bool shadowed)
|
||||
{
|
||||
shadowed = false;
|
||||
}
|
||||
BIN
data/shaders/hlsl/raytracingshadows/shadow.rmiss.spv
Normal file
BIN
data/shaders/hlsl/raytracingshadows/shadow.rmiss.spv
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue