7#ifndef PXR_IMAGING_HDX_PICK_TASK_H
8#define PXR_IMAGING_HDX_PICK_TASK_H
11#include "pxr/imaging/hdx/api.h"
13#include "pxr/imaging/hdSt/textureUtils.h"
14#include "pxr/imaging/hd/dataSource.h"
15#include "pxr/imaging/hd/enums.h"
17#include "pxr/imaging/hd/renderPass.h"
18#include "pxr/imaging/hd/renderPassState.h"
19#include "pxr/imaging/hd/rprimCollection.h"
20#include "pxr/imaging/hd/task.h"
29#include "pxr/usd/sdf/path.h"
34PXR_NAMESPACE_OPEN_SCOPE
36#define HDX_PICK_RESOLVE_MODE_TOKENS \
37 (resolveNearestToCamera) \
38 (resolveNearestToCenter) \
44 HdxPickResolveModeTokens, HDX_API, HDX_PICK_RESOLVE_MODE_TOKENS);
46#define HDX_PICK_TOKENS \
51 (pickPrimsAndInstances) \
55 (pickPointsAndInstances) \
57 HDX_PICK_RESOLVE_MODE_TOKENS
60 HdxPickTokens, HDX_API, HDX_PICK_TOKENS);
62class HdStRenderBuffer;
64using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
74 : cullStyle(HdCullStyleNothing)
77 HdCullStyle cullStyle;
109 inline bool IsValid()
const {
114 size_t GetHash()
const;
117using HdxPickHitVector = std::vector<HdxPickHit>;
192 static std::vector<HdxPrimOriginInfo>
194 const std::vector<HdxPickHit> &hits);
203 static std::vector<HdxPrimOriginInfo>
205 const std::vector<HdxPickHit> &hits);
215 const TfToken &nameInPrimOrigin =
216 HdPrimOriginSchemaTokens->scenePath)
const;
226 const TfToken &nameInPrimOrigin =
227 HdPrimOriginSchemaTokens->scenePath)
const;
271 using DepthMaskCallback = std::function<void(
void)>;
274 : resolution(128, 128)
275 , maxNumDeepEntries(32000)
276 , pickTarget(HdxPickTokens->pickPrimsAndInstances)
277 , resolveMode(HdxPickTokens->resolveNearestToCamera)
278 , doUnpickablesOcclude(
false)
280 , projectionMatrix(1)
282 , depthMaskCallback(
nullptr)
284 , alphaThreshold(0.0001f)
289 int maxNumDeepEntries;
292 bool doUnpickablesOcclude;
295 std::vector<GfVec4d> clipPlanes;
296 DepthMaskCallback depthMaskCallback;
298 float alphaThreshold;
299 HdxPickHitVector *outHits;
329 HdDirtyBits* dirtyBits)
override;
345 return (int32_t(idColor[0] & 0xff) << 0) |
346 (int32_t(idColor[1] & 0xff) << 8) |
347 (int32_t(idColor[2] & 0xff) << 16) |
348 (int32_t(idColor[3] & 0xff) << 24);
355 bool _useOverlayPass;
361 void _InitIfNeeded();
362 void _CreateAovBindings();
363 void _CleanupAovBindings();
364 void _ResizeOrCreateBufferForAOV(
367 void _ConditionStencilWithGLCallback(
368 HdxPickTaskContextParams::DepthMaskCallback maskCallback,
371 bool _UseOcclusionPass()
const;
372 bool _UseOverlayPass()
const;
373 void _UpdateUseOverlayPass();
375 void _ClearPickBuffer();
379 HdStTextureUtils::AlignedBuffer<T>
380 _ReadAovBuffer(
TfToken const & aovName)
const;
386 HdRenderPassSharedPtr _pickableRenderPass;
387 HdRenderPassSharedPtr _occluderRenderPass;
388 HdRenderPassSharedPtr _overlayRenderPass;
392 HdRenderPassStateSharedPtr _pickableRenderPassState;
393 HdRenderPassStateSharedPtr _occluderRenderPassState;
394 HdRenderPassStateSharedPtr _overlayRenderPassState;
398 std::vector<std::unique_ptr<HdStRenderBuffer>> _pickableAovBuffers;
399 HdRenderPassAovBindingVector _pickableAovBindings;
401 size_t _pickableDepthIndex;
403 std::unique_ptr<HdStRenderBuffer> _overlayDepthStencilBuffer;
404 HdRenderPassAovBindingVector _overlayAovBindings;
407 HdBufferArrayRangeSharedPtr _pickBuffer;
437 int const* instanceIds,
438 int const* elementIds,
486 bool _ResolveHit(
int index,
int x,
int y,
float z,
HdxPickHit* hit)
const;
488 size_t _GetHash(
int index)
const;
489 bool _IsValidHit(
int index)
const;
493 int _GetPrimId(
int index)
const {
494 return _primIds ? _primIds[index] : -1;
496 int _GetInstanceId(
int index)
const {
497 return _instanceIds ? _instanceIds[index] : -1;
499 int _GetElementId(
int index)
const {
500 return _elementIds ? _elementIds[index] : -1;
502 int _GetEdgeId(
int index)
const {
503 return _edgeIds ? _edgeIds[index] : -1;
505 int _GetPointId(
int index)
const {
506 return _pointIds ? _pointIds[index] : -1;
512 GfVec3f _GetNormal(
int index)
const;
515 int const* _instanceIds;
516 int const* _elementIds;
518 int const* _pointIds;
520 float const* _depths;
536std::ostream& operator<<(std::ostream& out,
const HdxPickHit& h);
561PXR_NAMESPACE_CLOSE_SCOPE
Provide architecture-specific memory-alignment information.
Stores a 4x4 matrix of double elements.
Basic type for a vector of 2 float components.
Basic type for a vector of 2 int components.
Basic type for a vector of 3 double components.
Basic type for a vector of 3 float components.
Basic type for a vector of 4 int components.
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
The render index is part of the Hydra 1.0 API and is only used for emulation purposes so that HdScene...
A named, semantic collection of objects.
Adapter class providing data exchange with the client scene graph.
A set of rendering parameters used among render passes.
HdTask represents a unit of work to perform during a Hydra render.
A utility class for resolving ID buffers into hits.
HDX_API void ResolveUnique(HdxPickHitVector *allHits) const
Return the set of unique hit points, keeping only the nearest depth value.
HDX_API void ResolveNearestToCenter(HdxPickHitVector *allHits) const
Return the nearest single hit point from the center of the viewport.
HDX_API bool IsValid() const
Return whether the result was given well-formed parameters.
HDX_API void ResolveAll(HdxPickHitVector *allHits) const
Return all hit points.
HDX_API void ResolveNearestToCamera(HdxPickHitVector *allHits) const
Return the nearest single hit point.
A task for running picking queries against the current scene.
static int DecodeIDRenderColor(unsigned char const idColor[4])
Utility: Given a UNorm8Vec4 pixel, unpack it into an int32 ID.
HDX_API const TfTokenVector & GetRenderTags() const override
Render Tag Gather.
HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the pick task.
HDX_API void Execute(HdTaskContext *ctx) override
Execute the pick task.
Hydra Graphics Interface.
A path value used to locate objects in layers or scenegraphs.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Token for efficient comparison, assignment, and hashing of known strings.
Standard pointer typedefs.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
Information about an instancer instancing a picked object (or an instancer instancing such an instanc...
HdContainerDataSourceHandle instancerPrimOrigin
The prim origin data source of the instancer.
HdContainerDataSourceHandle instancePrimOrigin
The prim origin data source of the picked (implicit) instance.
int instanceId
Index of the picked instance.
SdfPath instanceSceneIndexPath
For implicit instancing (native instancing in USD), the path of the picked instance in the scene inde...
SdfPath instancerSceneIndexPath
The path of the instancer in the scene index.
float normalizedDepth
normalizedDepth is in the range [0,1].
SdfPath delegateId
delegateID of HdSceneDelegate that provided the picked prim.
SdfPath objectId
Path computed from scenePath's in primOrigin data source of picked prim and instancers if provided by...
SdfPath instancerId
Only supported for scene delegates, see HdxPrimOriginInfo for scene indices.
Pick task context params.
A helper to extract information about the picked prim that allows modern applications to identify a p...
static HDX_API std::vector< HdxPrimOriginInfo > FromPickHits(HdRenderIndex *renderIndex, const std::vector< HdxPickHit > &hits)
Vectorized implementation of function to query terminal scene index of render index for information a...
static HDX_API std::vector< HdxPrimOriginInfo > FromPickHits(HdSceneIndexBaseRefPtr const &terminalSceneIndex, const std::vector< HdxPickHit > &hits)
Vectorized implementation of function to query terminal scene index for information about picked prim...
static HDX_API HdxPrimOriginInfo FromPickHit(HdSceneIndexBaseRefPtr const &terminalSceneIndex, const HdxPickHit &hit)
Query terminal scene index for information about picked prim.
HdContainerDataSourceHandle primOrigin
The prim origin data source for the picked prim if provided by the scene index.
std::vector< HdxInstancerContext > instancerContexts
Information about the instancers instancing the picked object.
static HDX_API HdxPrimOriginInfo FromPickHit(HdRenderIndex *renderIndex, const HdxPickHit &hit)
Query terminal scene index of render index for information about picked prim.
HDX_API HdInstancerContext ComputeInstancerContext(const TfToken &nameInPrimOrigin=HdPrimOriginSchemaTokens->scenePath) const
Computes an HdInstancerContext object (equivalent to the one computed by GetScenePrimPath) from the v...
HDX_API SdfPath GetFullPath(const TfToken &nameInPrimOrigin=HdPrimOriginSchemaTokens->scenePath) const
Combines instance scene paths and prim scene path to obtain the full scene path.
std::vector< TfToken > TfTokenVector
Convenience types.