Vulkan-Docs/chapters/VK_NVX_raytracing/raytracing-shaders.txt

92 lines
3.3 KiB
Plaintext

// This section is included inside the Shaders chapter (shaders.txt)
[[shaders-raytracing-shaders]]
[[shaders-ray-generation]]
== Ray Generation Shaders
A ray generation shader is similar to a compute shader.
Its main purpose is to execute ray tracing queries using code:OpTraceNVX
instructions and process the results.
[[shaders-ray-generation-execution]]
=== Ray Generation Shader Execution
One ray generation shader is executed per ray tracing dispatch.
Its location in the shader binding table (see <<shader-binding-table,Shader
Binding Table>> for details) is passed directly into fname:vkCmdTraceRaysNVX
using the pname:raygenShaderBindingTableBuffer and
pname:raygenShaderBindingOffset parameters.
[[shaders-intersection]]
== Intersection Shaders
Intersection shaders enable the implementation of arbitrary, application
defined geometric primitives.
An intersection shader for a primitive is executed whenever its axis-aligned
bounding box is hit by a ray.
A built-in intersection shader for triangle primitives that is used
automatically whenever geometry of type ename:VK_GEOMETRY_TYPE_TRIANGLES_NVX
is specified.
Like other raytracing shader domains, an intersection shader operates on a
single ray at a time.
It also operates on a single primitive at a time.
It is therefore the purpose of an intersection shader to compute the
ray-primitive intersections and report them.
To report an intersection, the shader calls the code:OpReportIntersectionNVX
instruction.
An intersection shader communicates with any hit and closest shaders by
generating attribute values that they can read.
Intersection shaders cannot read or modify the ray payload.
[[shaders-intersection-execution]]
=== Intersection Shader Execution
[[shaders-any-hit]]
== Any Hit Shaders
The any hit shader is executed after the intersection shader reports an
intersection that lies within the current [tmin,tmax] of the ray.
The main use of any hit shaders is to programmatically decide whether or not
an intersection should be accepted.
The intersection will be accepted unless the shader calls the
code:OpIgnoreIntersectionNVX instruction.
[[shaders-any-hit-execution]]
=== Any Hit Shader Execution
The order in which intersections are found along a ray, and therefore the
order in which any hit shaders are executed, is unspecified.
The any hit shader of the closest hit is guaranteed to be executed at some
point during traversal, unless the ray is forcibly terminated.
[[shaders-closest-hit]]
== Closest Hit Shaders
Closest hit shaders have read-only access to the attributes generated by the
corresponding intersection shader, and may: read or modify the ray payload.
They also have access to a number of system-generated values.
Closest hit shaders may call code:OpTraceNVX to recursively trace rays.
[[shaders-closest-hit-execution]]
=== Closest Hit Shader Execution
Exactly one closest hit shader is executed when traversal is finished and an
intersection has been found and accepted.
[[shaders-miss]]
== Miss Shaders
Miss shaders can access the ray payload and can trace new rays through the
code:OpTraceNVX instruction, but cannot access attributes since they are not
associated with an intersection.
[[shaders-miss-execution]]
=== Miss Shader Execution
A miss shader is executed instead of a closest hit shader if no intersection
was found during traversal.