scene/records/instances.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include "chrono_batch_render/stage/schema/ids.h" | ||
| 5 | #include "chrono_batch_render/stage/schema/schema.h" | ||
| 6 | |||
| 7 | namespace chrono::batch_render { | ||
| 8 | |||
| 9 | struct SurfaceRecord { | ||
| 10 | uint64_t points; | ||
| 11 | uint64_t indices; | ||
| 12 | uint64_t corners; | ||
| 13 | uint64_t faces; | ||
| 14 | uint64_t normals; | ||
| 15 | uint64_t normalIndices; | ||
| 16 | uint64_t smooth; | ||
| 17 | uint64_t opacities; | ||
| 18 | uint64_t opacityIndices; | ||
| 19 | uint opacityCount; | ||
| 20 | uint opacityIndexCount; | ||
| 21 | uint opacityStride; | ||
| 22 | uint opacityFlags; | ||
| 23 | uint normalsInterpolation; | ||
| 24 | uint normalsCount; | ||
| 25 | uint normalIndexCount; | ||
| 26 | uint meshRow; | ||
| 27 | uint orientation; | ||
| 28 | uint padding0; | ||
| 29 | ArrayRef primvars; | ||
| 30 | ArrayRef instancerPrimvars; | ||
| 31 | Float3 displayColor; | ||
| 32 | float displayOpacity; | ||
| 33 | int64_t instanceId; | ||
| 34 | }; | ||
| 35 | |||
| 36 | CHRONO_BATCH_RENDER_CHECK_SIZE(SurfaceRecord, 168); | ||
| 37 | |||
| 38 | static const uint kOpacityPerPoint = 1u; | ||
| 39 | static const uint kOpacityInteger = 2u; | ||
| 40 | static const uint kOpacityInterpolationShift = 8; | ||
| 41 | |||
| 42 | static const float kRenderOriginCell = 64; | ||
| 43 | |||
| 44 | struct RenderOrigin { | ||
| 45 | Float3 high; | ||
| 46 | Float3 low; | ||
| 47 | }; | ||
| 48 | |||
| 49 | CHRONO_BATCH_RENDER_CHECK_SIZE(RenderOrigin, 24); | ||
| 50 | |||
| 51 | static const float kInfinitePlane = 1e6f; | ||
| 52 | |||
| 53 | CHRONO_BATCH_RENDER_ENUM(ShapeKind){ | ||
| 54 | Mesh, | ||
| 55 | Sphere, | ||
| 56 | Box, | ||
| 57 | Plane, | ||
| 58 | Cylinder, | ||
| 59 | Cone, | ||
| 60 | Capsule, | ||
| 61 | Disk, | ||
| 62 | Tube, | ||
| 63 | Points, | ||
| 64 | Curves, | ||
| 65 | }; | ||
| 66 | |||
| 67 | static const uint kGeometryMask = 1u; | ||
| 68 | static const uint kCameraEmitterMask = 2u; | ||
| 69 | static const uint kEmitterMask = 4u; | ||
| 70 | |||
| 71 | struct ShapeRecord { | ||
| 72 | uint kind; | ||
| 73 | float param; | ||
| 74 | uint row; | ||
| 75 | uint padding; | ||
| 76 | }; | ||
| 77 | |||
| 78 | CHRONO_BATCH_RENDER_CHECK_SIZE(ShapeRecord, 16); | ||
| 79 | |||
| 80 | 1551 | CHRONO_BATCH_RENDER_SHARED bool IsEmitter(uint schema) { | |
| 81 | 1551 | switch (SchemaId(schema)) { | |
| 82 | case SchemaId::SphereLight: | ||
| 83 | case SchemaId::RectLight: | ||
| 84 | case SchemaId::DiskLight: | ||
| 85 | case SchemaId::CylinderLight: | ||
| 86 | return true; | ||
| 87 | 25 | default: | |
| 88 | 25 | return false; | |
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | static const uint kInstancerSlot = 0x80000000u; | ||
| 93 | static const uint kNoNested = 0xFFFFFFFFu; | ||
| 94 | static const uint kMostNesting = 4; | ||
| 95 | |||
| 96 | struct InstancerBlock { | ||
| 97 | uint instancer; | ||
| 98 | uint first; | ||
| 99 | uint count; | ||
| 100 | uint width; | ||
| 101 | uint prototypes; | ||
| 102 | uint prototypeCount; | ||
| 103 | uint native; | ||
| 104 | uint hidden; | ||
| 105 | uint lightWidth; | ||
| 106 | uint padding0; | ||
| 107 | uint padding1; | ||
| 108 | uint padding2; | ||
| 109 | }; | ||
| 110 | |||
| 111 | CHRONO_BATCH_RENDER_CHECK_SIZE(InstancerBlock, 48); | ||
| 112 | |||
| 113 | struct PrototypeEntry { | ||
| 114 | uint first; | ||
| 115 | uint count; | ||
| 116 | uint parent; | ||
| 117 | uint width; | ||
| 118 | uint lights; | ||
| 119 | uint padding0; | ||
| 120 | uint padding1; | ||
| 121 | uint padding2; | ||
| 122 | }; | ||
| 123 | |||
| 124 | CHRONO_BATCH_RENDER_CHECK_SIZE(PrototypeEntry, 32); | ||
| 125 | |||
| 126 | struct PrototypePiece { | ||
| 127 | uint prim; | ||
| 128 | uint start; | ||
| 129 | uint slots; | ||
| 130 | uint nested; | ||
| 131 | uint lightStart; | ||
| 132 | uint lights; | ||
| 133 | uint padding0; | ||
| 134 | uint padding1; | ||
| 135 | }; | ||
| 136 | |||
| 137 | CHRONO_BATCH_RENDER_CHECK_SIZE(PrototypePiece, 32); | ||
| 138 | |||
| 139 | struct SlotHit { | ||
| 140 | uint prim; | ||
| 141 | uint instancer; | ||
| 142 | uint instance; | ||
| 143 | uint offset; | ||
| 144 | }; | ||
| 145 | |||
| 146 | CHRONO_BATCH_RENDER_CHECK_SIZE(SlotHit, 16); | ||
| 147 | |||
| 148 | struct InstanceLayout { | ||
| 149 | Ptr<uint64_t> handles; | ||
| 150 | Ptr<uint> firstInstances; | ||
| 151 | Ptr<uint> instanceCounts; | ||
| 152 | Ptr<uint> instancePrims; | ||
| 153 | Ptr<ShapeRecord> shapes; | ||
| 154 | Ptr<uint> worldOrigins; | ||
| 155 | Ptr<SlotHit> hits; | ||
| 156 | Ptr<InstancerBlock> blocks; | ||
| 157 | Ptr<PrototypeEntry> prototypes; | ||
| 158 | Ptr<PrototypePiece> pieces; | ||
| 159 | Ptr<uint> hiddenRanges; | ||
| 160 | uint64_t hiddenIds; | ||
| 161 | uint64_t records; | ||
| 162 | Ptr<uint> offsetBases; | ||
| 163 | Ptr<Float3> offsets; | ||
| 164 | uint worldCount; | ||
| 165 | uint displayColorName; | ||
| 166 | uint padding0; | ||
| 167 | uint padding1; | ||
| 168 | }; | ||
| 169 | |||
| 170 | CHRONO_BATCH_RENDER_CHECK_SIZE(InstanceLayout, 136); | ||
| 171 | |||
| 172 | #ifdef __SLANG__ | ||
| 173 | |||
| 174 | SlotHit Drawn(uint prim, uint instancer, uint instance, uint offset) { | ||
| 175 | SlotHit hit; | ||
| 176 | hit.prim = prim; | ||
| 177 | hit.instancer = instancer; | ||
| 178 | hit.instance = instance; | ||
| 179 | hit.offset = offset; | ||
| 180 | return hit; | ||
| 181 | } | ||
| 182 | |||
| 183 | float3 ShownOffset(InstanceLayout* layout, uint view, uint world) { | ||
| 184 | if (view >= layout->worldCount || world >= layout->worldCount) { | ||
| 185 | return float3(0); | ||
| 186 | } | ||
| 187 | const uint base = layout->offsetBases[view]; | ||
| 188 | if (base == kNoRow) { | ||
| 189 | return float3(0); | ||
| 190 | } | ||
| 191 | const float3 offset = layout->offsets[base + world].Vector(); | ||
| 192 | return isnan(offset.x) ? float3(0) : offset; | ||
| 193 | } | ||
| 194 | |||
| 195 | float3 RelativeTranslation(RenderOrigin origin, WorldTransform w) { | ||
| 196 | return (w.high.Vector() - origin.high.Vector()) + (w.low.Vector() - origin.low.Vector()); | ||
| 197 | } | ||
| 198 | |||
| 199 | #endif | ||
| 200 | |||
| 201 | } | ||
| 202 |