Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ConstantBuffer<RayGenConstantBuffer> g_rayGenCB : register(b0);
typedef BuiltInTriangleIntersectionAttributes MyAttributes;
struct RayPayload
{
float4 color;
uint2 dispatchRayIndex;
};

bool IsInsideViewport(float2 p, Viewport viewport)
Expand Down Expand Up @@ -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
{
Expand All @@ -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