Add vk_ray_trace_indirect_scissor sample

This commit is contained in:
mklefrancois 2020-12-15 09:06:54 +01:00
parent 27d8a79ce3
commit a6690f149a
30 changed files with 4498 additions and 6 deletions

View file

@ -0,0 +1,71 @@
#version 460
#extension GL_EXT_ray_tracing : require
#extension GL_GOOGLE_include_directive : enable
#include "raycommon.glsl"
layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
layout(binding = 1, set = 0, rgba32f) uniform image2D image;
layout(location = 0) rayPayloadEXT hitPayload prd;
layout(binding = 0, set = 1) uniform CameraProperties
{
mat4 view;
mat4 proj;
mat4 viewInverse;
mat4 projInverse;
}
cam;
layout(binding = 2, set = 0) buffer LanternArray { LanternIndirectEntry lanterns[]; } lanterns;
void main()
{
// Global light pass is a full screen rectangle (lower corner 0,0), but
// lantern passes are only run within rectangles that may be offset.
ivec2 pixelOffset = ivec2(0);
if (pushC.lanternPassNumber >= 0)
{
pixelOffset.x = lanterns.lanterns[pushC.lanternPassNumber].offsetX;
pixelOffset.y = lanterns.lanterns[pushC.lanternPassNumber].offsetY;
}
const ivec2 pixelIntCoord = ivec2(gl_LaunchIDEXT.xy) + pixelOffset;
const vec2 pixelCenter = vec2(pixelIntCoord) + vec2(0.5);
const vec2 inUV = pixelCenter / vec2(pushC.screenX, pushC.screenY);
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), 0);
uint rayFlags = gl_RayFlagsOpaqueEXT;
float tMin = 0.001;
float tMax = 10000.0;
// Lanterns (self-illuminating) and miss shader (constant background color)
// do not use additive blending. Only normal OBJ geometry is additive,
// OBJ closest hit sets this to true.
prd.additiveBlending = false;
traceRayEXT(topLevelAS, // acceleration structure
rayFlags, // rayFlags
0xFF, // cullMask
0, // sbtRecordOffset
0, // sbtRecordStride
0, // missIndex
origin.xyz, // ray origin
tMin, // ray min range
direction.xyz, // ray direction
tMax, // ray max range
0 // payload (location = 0)
);
// Either add to or replace output image color based on prd.additiveBlending.
// Global pass always replaces color as it is the first pass.
vec3 oldColor = vec3(0);
if (prd.additiveBlending && pushC.lanternPassNumber >= 0) {
oldColor = imageLoad(image, pixelIntCoord).rgb;
}
imageStore(image, pixelIntCoord, vec4(prd.hitValue + oldColor, 1.0));
}