render/ray_cast/ray_cast.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <limits> | ||
| 6 | #include <memory> | ||
| 7 | #include <optional> | ||
| 8 | #include <string> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "chrono_batch_render/device/operation.h" | ||
| 12 | #include "chrono_batch_render/device/ref.h" | ||
| 13 | #include "chrono_batch_render/device/stream.h" | ||
| 14 | #include "chrono_batch_render/device/tensor.h" | ||
| 15 | #include "chrono_batch_render/export.h" | ||
| 16 | #include "chrono_batch_render/scene/prim.h" | ||
| 17 | #include "chrono_batch_render/stage/schema/ids.h" | ||
| 18 | |||
| 19 | namespace chrono::batch_render { | ||
| 20 | |||
| 21 | class Scene; | ||
| 22 | |||
| 23 | enum class RayOutput : uint32_t { | ||
| 24 | None = 0, | ||
| 25 | Distance = 1u << 0, | ||
| 26 | Prim = 1u << 1, | ||
| 27 | Normal = 1u << 2, | ||
| 28 | Position = 1u << 3, | ||
| 29 | InstanceId = 1u << 4, | ||
| 30 | }; | ||
| 31 | |||
| 32 | constexpr RayOutput operator|(RayOutput a, RayOutput b) { | ||
| 33 | return RayOutput(uint32_t(a) | uint32_t(b)); | ||
| 34 | } | ||
| 35 | |||
| 36 | 1445 | constexpr bool operator&(RayOutput a, RayOutput b) { | |
| 37 | 1445 | return (uint32_t(a) & uint32_t(b)) != 0; | |
| 38 | } | ||
| 39 | |||
| 40 | enum class RayCastMode : uint8_t { Closest, Any }; | ||
| 41 | |||
| 42 | struct CHRONO_BATCH_RENDER_API Rays { | ||
| 43 | device::Tensor origins; | ||
| 44 | device::Tensor directions; | ||
| 45 | device::Tensor tMins; | ||
| 46 | device::Tensor tMaxes; | ||
| 47 | device::Tensor worlds; | ||
| 48 | float minDistance = 0; | ||
| 49 | float maxDistance = std::numeric_limits<float>::infinity(); | ||
| 50 | uint32_t world = kGlobalWorld; | ||
| 51 | std::optional<Prim> space; | ||
| 52 | }; | ||
| 53 | |||
| 54 | struct CHRONO_BATCH_RENDER_API RayHits { | ||
| 55 | device::Tensor hit; | ||
| 56 | device::Tensor distance; | ||
| 57 | device::Tensor prim; | ||
| 58 | device::Tensor normal; | ||
| 59 | device::Tensor position; | ||
| 60 | device::Tensor instance; | ||
| 61 | device::Operation done; | ||
| 62 | }; | ||
| 63 | |||
| 64 | 298 | struct CHRONO_BATCH_RENDER_API RayCastDesc { | |
| 65 | RayCastMode mode = RayCastMode::Closest; | ||
| 66 | RayOutput outputs = RayOutput::Distance | RayOutput::Prim; | ||
| 67 | std::string label = "RayCast"; | ||
| 68 | std::vector<Prim> ignore; | ||
| 69 | }; | ||
| 70 | |||
| 71 | class CHRONO_BATCH_RENDER_API RayCaster { | ||
| 72 | public: | ||
| 73 | explicit RayCaster(Ref<Scene> scene); | ||
| 74 | ~RayCaster(); | ||
| 75 | RayCaster(RayCaster&&) noexcept; | ||
| 76 | RayCaster& operator=(RayCaster&&) noexcept; | ||
| 77 | |||
| 78 | device::Operation Cast(const Rays& rays, RayHits& hits, const RayCastDesc& desc = {}, | ||
| 79 | Stream stream = Stream::None()); | ||
| 80 | RayHits Cast(const Rays& rays, const RayCastDesc& desc = {}); | ||
| 81 | Scene& GetScene() const; | ||
| 82 | |||
| 83 | private: | ||
| 84 | struct State; | ||
| 85 | std::unique_ptr<State> m_state; | ||
| 86 | }; | ||
| 87 | |||
| 88 | } | ||
| 89 |