raytracing-shaders.txt
1 // This section is included inside the Shaders chapter (shaders.txt) 2 3 [[shaders-raytracing-shaders]] 4 [[shaders-ray-generation]] 5 == Ray Generation Shaders 6 7 A ray generation shader is similar to a compute shader. 8 Its main purpose is to execute ray tracing queries using code:OpTraceNV 9 instructions and process the results. 10 11 [[shaders-ray-generation-execution]] 12 === Ray Generation Shader Execution 13 14 One ray generation shader is executed per ray tracing dispatch. 15 Its location in the shader binding table (see <<shader-binding-table,Shader 16 Binding Table>> for details) is passed directly into fname:vkCmdTraceRaysNV 17 using the pname:raygenShaderBindingTableBuffer and 18 pname:raygenShaderBindingOffset parameters. 19 20 [[shaders-intersection]] 21 == Intersection Shaders 22 23 Intersection shaders enable the implementation of arbitrary, application 24 defined geometric primitives. 25 An intersection shader for a primitive is executed whenever its axis-aligned 26 bounding box is hit by a ray. 27 28 A built-in intersection shader for triangle primitives that is used 29 automatically whenever geometry of type ename:VK_GEOMETRY_TYPE_TRIANGLES_NV 30 is specified. 31 32 Like other ray tracing shader domains, an intersection shader operates on a 33 single ray at a time. 34 It also operates on a single primitive at a time. 35 It is therefore the purpose of an intersection shader to compute the 36 ray-primitive intersections and report them. 37 To report an intersection, the shader calls the code:OpReportIntersectionNV 38 instruction. 39 40 An intersection shader communicates with any-hit and closest shaders by 41 generating attribute values that they can: read. 42 Intersection shaders cannot: read or modify the ray payload. 43 44 [[shaders-intersection-execution]] 45 === Intersection Shader Execution 46 The order in which intersections are found along a ray, and therefore the 47 order in which intersection shaders are executed, is unspecified. 48 49 The intersection shader of the closest AABB which intersects the ray is 50 guaranteed to be executed at some point during traversal, unless the ray is 51 forcibly terminated. 52 53 [[shaders-any-hit]] 54 == Any-Hit Shaders 55 56 The any-hit shader is executed after the intersection shader reports an 57 intersection that lies within the current [eq]#[tmin,tmax]# of the ray. 58 The main use of any-hit shaders is to programmatically decide whether or not 59 an intersection will be accepted. 60 The intersection will be accepted unless the shader calls the 61 code:OpIgnoreIntersectionNV instruction. 62 63 [[shaders-any-hit-execution]] 64 === Any-Hit Shader Execution 65 66 The order in which intersections are found along a ray, and therefore the 67 order in which any-hit shaders are executed, is unspecified. 68 69 The any-hit shader of the closest hit is guaranteed to be executed at some 70 point during traversal, unless the ray is forcibly terminated. 71 72 [[shaders-closest-hit]] 73 == Closest Hit Shaders 74 75 Closest hit shaders have read-only access to the attributes generated by the 76 corresponding intersection shader, and can: read or modify the ray payload. 77 They also have access to a number of system-generated values. 78 Closest hit shaders can: call code:OpTraceNV to recursively trace rays. 79 80 [[shaders-closest-hit-execution]] 81 === Closest Hit Shader Execution 82 83 Exactly one closest hit shader is executed when traversal is finished and an 84 intersection has been found and accepted. 85 86 [[shaders-miss]] 87 == Miss Shaders 88 89 Miss shaders can: access the ray payload and can: trace new rays through the 90 code:OpTraceNV instruction, but cannot: access attributes since they are not 91 associated with an intersection. 92 93 [[shaders-miss-execution]] 94 === Miss Shader Execution 95 96 A miss shader is executed instead of a closest hit shader if no intersection 97 was found during traversal. 98 99 [[shaders-callable]] 100 == Callable Shaders 101 102 Callable shaders can: access a callable payload that works similarly to ray 103 payloads to do subroutine work. 104 105 [[shaders-callable-execution]] 106 === Callable Shader Execution 107 108 A callable shader is executed by calling code:OpExecuteCallableNV from an 109 allowed shader stage.