Ray Generation Shader
A shader that calls TraceRay to generate rays. The initial user-defined ray payload for each ray is provided to the TraceRay call site. CallShader may also be used in ray generation shaders to invoke callable shaders.
DispatchRays invokes a grid of ray generation shader invocations. Each invocation (thread) of a ray generation shader knows its location in the overall grid, can generate arbitrary rays via TraceRay, and operates independently of other invocations. There is no defined order of execution of threads with respect to each other.
Shader Type attribute
[shader("raygeneration")]
Example
struct SceneConstantStructure { ... };
ConstantBuffer<SceneConstantStructure> SceneConstants;
RaytracingAccelerationStructure MyAccelerationStructure : register(t3);
struct MyPayload { ... };
[shader("raygeneration")]
void raygen_main()
{
RayDesc myRay = {
SceneConstants.CameraOrigin,
SceneConstants.TMin,
computeRayDirection(SceneConstants.LensParams, DispatchRaysIndex(),
DispatchRaysDimensions()),
SceneConstants.TMax};
MyPayload payload = { ... }; // init payload
TraceRay(
MyAccelerationStructure,
SceneConstants.RayFlags,
SceneConstants.InstanceInclusionMask,
SceneConstants.RayContributionToHitGroupIndex,
SceneConstants.MultiplierForGeometryContributionToHitGroupIndex,
SceneConstants.MissShaderIndex,
myRay,
payload);
WriteFinalPixel(DispatchRaysIndex(), payload);
}