| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include "Common.hlsl"
- [shader("raygeneration")]
- void RayGen()
- {
- // Initialize the ray payload
- HitInfo rayPayload;
- rayPayload.hitCount = 0;
- float4 color = float4(0, 0, 0, 0);
- // Get the location within the dispatched 2D grid of work items
- // (often maps to pixels, so this could represent a pixel coordinate).
- float2 dispatchDimensions = float2(DispatchRaysDimensions().xy);
- uint2 dispatchIndex = DispatchRaysIndex().xy;
- float2 dispatchPercentage = (dispatchIndex + 0.5) / dispatchDimensions;
-
- if (useRays)
- {
- float2 d = (dispatchPercentage * 2.f - 1.f);
- RayDesc ray;
- ray.Origin = mul(inverseView, float4(0, 0, 0, 1)).xyz;
- float4 target = mul(inverseProjection, float4(d.x, -d.y, -1, 1));
- target.w = 1;
- ray.Direction = mul(inverseView, target).xyz - ray.Origin;
- ray.TMin = minDistance;
- ray.TMax = maxDistance;
- TraceRay(TLAS, /*RayFlags*/0, /*InstanceInclusionMask*/0xFF, /*RayContributionToHitGroupIndex*/0,
- /*MultiplierForGeometryContributionToHitGroupIndex*/0, /*MissShaderIndex*/0, ray, rayPayload);
- color = rayPayload.color[rayPayload.hitCount - 1];
- for (int i = rayPayload.hitCount - 2; i >= 0; i--)
- {
- color.rgb = rayPayload.color[i].rgb * rayPayload.color[i].a + color.rgb * (1 - rayPayload.color[i].a);
- }
- }
-
- uint outWidth, outHeight;
- gOutput.GetDimensions(outWidth, outHeight);
- uint2 outputIndex = uint2(dispatchPercentage * float2(outWidth, outHeight));
- if (renderGui)
- {
- uint guiWidth, guiHeight;
- guiTexture.GetDimensions(guiWidth, guiHeight);
- uint2 guiIndex = uint2(dispatchPercentage * float2(guiWidth, guiHeight));
- float4 guiColor = guiTexture[guiIndex];
- color.rgb = color.rgb * (1 - guiColor.a) + guiColor.rgb * guiColor.a;
- }
- gOutput[outputIndex] = float4(color.rgb, 1.f);
- }
|