diff --git a/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl b/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl index d42565687..cc77e5af2 100644 --- a/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl +++ b/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/Raytracing.hlsl @@ -21,7 +21,7 @@ ConstantBuffer g_rayGenCB : register(b0); typedef BuiltInTriangleIntersectionAttributes MyAttributes; struct RayPayload { - float4 color; + uint2 dispatchRayIndex; }; bool IsInsideViewport(float2 p, Viewport viewport) @@ -53,11 +53,8 @@ void MyRaygenShader() // TMin should be kept small to prevent missing geometry at close contact areas. ray.TMin = 0.001; ray.TMax = 10000.0; - RayPayload payload = { float4(0, 0, 0, 0) }; + RayPayload payload = { uint2(DispatchRaysIndex().xy) }; TraceRay(Scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, ~0, 0, 1, 0, ray, payload); - - // Write the raytraced color to the output texture. - RenderTarget[DispatchRaysIndex().xy] = payload.color; } else { @@ -70,13 +67,15 @@ void MyRaygenShader() void MyClosestHitShader(inout RayPayload payload, in MyAttributes attr) { float3 barycentrics = float3(1 - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y); - payload.color = float4(barycentrics, 1); + // Write the raytraced color to the output texture. + RenderTarget[payload.dispatchRayIndex.xy] = float4(barycentrics, 1); } [shader("miss")] void MyMissShader(inout RayPayload payload) { - payload.color = float4(0, 0, 0, 1); + // Write the raytraced color to the output texture. + RenderTarget[payload.dispatchRayIndex.xy] = float4(0.0, 0.0, 0.0, 1.0); } #endif // RAYTRACING_HLSL \ No newline at end of file