RayTracingDispatch.azsl 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/Features/SrgSemantics.azsli>
  9. #include "RayTracingCommon.azsli"
  10. // top level ray generation shader, each thread casts a ray straight into the scene
  11. [shader("raygeneration")]
  12. void RayGenerationShader()
  13. {
  14. float2 dims = (float2)DispatchRaysDimensions();
  15. float2 halfDims = dims / 2;
  16. float2 lerpValues = (float2)DispatchRaysIndex() / dims;
  17. RayDesc ray;
  18. ray.Origin = float3(lerp(-halfDims.x, halfDims.x, lerpValues.x), lerp(halfDims.y, -halfDims.y, lerpValues.y), 0.0f);
  19. ray.Direction = float3(0.0f, 0.0f, 1.0f);
  20. ray.TMin = 0.001f;
  21. ray.TMax = 10000.0f;
  22. RayPayload payload = { float4(0.0f, 0.0f, 0.0f, 0.0f) };
  23. TraceRay(RayTracingGlobalSrg::m_scene, RAY_FLAG_CULL_BACK_FACING_TRIANGLES, 0xFF, 0, 0, 0, ray, payload);
  24. RayTracingGlobalSrg::m_output[DispatchRaysIndex().xy] = payload.color;
  25. }