This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
meshSamplers.h
1//
2// Copyright 2017 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
8#define PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/plugin/hdEmbree/sampler.h"
12#include "pxr/imaging/hd/meshUtil.h"
13#include "pxr/base/vt/types.h"
14
15#include <embree3/rtcore.h>
16#include <embree3/rtcore_geometry.h>
17
18#include <bitset>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
27{
28public:
31 : _bitset(0) {}
32
36 int Allocate();
37
40 void Free(int buffer);
41
43 unsigned int NumBuffers();
44
48 static constexpr int PXR_MAX_USER_VERTEX_BUFFERS = 16;
49
50private:
51 std::bitset<PXR_MAX_USER_VERTEX_BUFFERS> _bitset;
52};
53
54
55
56// ----------------------------------------------------------------------
57// The classes below implement the HdEmbreePrimvarSampler interface for
58// the different interpolation modes that hydra supports. In some cases,
59// implementations are broken out by geometry type (e.g. triangles vs
60// subdiv).
61
68public:
73 VtValue const& value)
74 : _buffer(name, value)
75 , _sampler(_buffer) {}
76
86 virtual bool Sample(unsigned int element, float u, float v, void* value,
87 HdTupleType dataType) const;
88
89private:
90 HdVtBufferSource const _buffer;
91 HdEmbreeBufferSampler const _sampler;
92};
93
104public:
111 VtValue const& value,
112 VtIntArray const& primitiveParams)
113 : _buffer(name, value)
114 , _sampler(_buffer)
115 , _primitiveParams(primitiveParams) {}
116
121 VtValue const& value)
122 : _buffer(name, value)
123 , _sampler(_buffer) {}
124
136 virtual bool Sample(unsigned int element, float u, float v, void* value,
137 HdTupleType dataType) const;
138
139private:
140 HdVtBufferSource const _buffer;
141 HdEmbreeBufferSampler const _sampler;
142 VtIntArray const _primitiveParams;
143};
144
154public:
161 VtValue const& value,
162 VtVec3iArray const& indices)
163 : _buffer(name, value)
164 , _sampler(_buffer)
165 , _indices(indices) {}
166
179 virtual bool Sample(unsigned int element, float u, float v, void* value,
180 HdTupleType dataType) const;
181
182private:
183 HdVtBufferSource const _buffer;
184 HdEmbreeBufferSampler const _sampler;
185 VtVec3iArray const _indices;
186};
187
205public:
212 VtValue const& value,
213 HdMeshUtil &meshUtil)
214 : _buffer(name, _Triangulate(name, value, meshUtil))
215 , _sampler(_buffer) {}
216
230 virtual bool Sample(unsigned int element, float u, float v, void* value,
231 HdTupleType dataType) const;
232
233private:
234 HdVtBufferSource const _buffer;
235 HdEmbreeBufferSampler const _sampler;
236
237 // Pass the "value" parameter through HdMeshUtils'
238 // ComputeTriangulatedFaceVaryingPrimvar(), which adjusts the primvar
239 // buffer data for the triangulated topology. HdMeshUtil is provided
240 // the source topology at construction time, so this class doesn't need
241 // to provide it.
242 static VtValue _Triangulate(TfToken const& name, VtValue const& value,
243 HdMeshUtil &meshUtil);
244};
245
254public:
266 VtValue const& value,
267 RTCScene meshScene,
268 unsigned meshId,
269 HdEmbreeRTCBufferAllocator *allocator);
270
273
284 virtual bool Sample(unsigned int element, float u, float v, void* value,
285 HdTupleType dataType) const;
286
287private:
288 int _embreeBufferId;
289 HdVtBufferSource const _buffer;
290 RTCScene _meshScene;
291 unsigned _meshId;
292 HdEmbreeRTCBufferAllocator *_allocator;
293};
294
295PXR_NAMESPACE_CLOSE_SCOPE
296
297#endif // PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
Defines all the types "TYPED" for which Vt creates a VtTYPEDArray typedef.
A utility class that knows how to sample an element from a type-tagged buffer (like HdVtBufferSource)...
Definition: sampler.h:79
This class implements the HdEmbreePrimvarSampler interface for primvars with "constant" interpolation...
Definition: meshSamplers.h:67
HdEmbreeConstantSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:72
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
An abstract base class that knows how to sample a primvar signal given a ray hit coordinate: an <elem...
Definition: sampler.h:119
Utility class to track which embree user vertex buffers are currently in use.
Definition: meshSamplers.h:27
HdEmbreeRTCBufferAllocator()
Constructor. By default, set everything to unallocated.
Definition: meshSamplers.h:30
int Allocate()
Allocate a buffer by finding the first clear bit, using that as the buffer number,...
unsigned int NumBuffers()
Query how many buffers are currently in user for this geometry.
void Free(int buffer)
Free a buffer by clearing its bit.
static constexpr int PXR_MAX_USER_VERTEX_BUFFERS
As of Embree3 the number of buffers was greatly increased however the maximum is only defined locally...
Definition: meshSamplers.h:48
This class implements the HdEmbreePrimvarSampler interface for primvars on subdiv meshes with "vertex...
Definition: meshSamplers.h:253
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
virtual ~HdEmbreeSubdivVertexSampler()
Destructor. Frees the embree user vertex buffer.
HdEmbreeSubdivVertexSampler(TfToken const &name, VtValue const &value, RTCScene meshScene, unsigned meshId, HdEmbreeRTCBufferAllocator *allocator)
Constructor.
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with "face...
Definition: meshSamplers.h:204
HdEmbreeTriangleFaceVaryingSampler(TfToken const &name, VtValue const &value, HdMeshUtil &meshUtil)
Constructor.
Definition: meshSamplers.h:211
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with "vert...
Definition: meshSamplers.h:153
HdEmbreeTriangleVertexSampler(TfToken const &name, VtValue const &value, VtVec3iArray const &indices)
Constructor.
Definition: meshSamplers.h:160
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
This class implements the HdEmbreePrimvarSampler interface for primvars with "uniform" interpolation ...
Definition: meshSamplers.h:103
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value, VtIntArray const &primitiveParams)
Constructor.
Definition: meshSamplers.h:110
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:120
A collection of utility algorithms for generating triangulation and quadrangulation of an input topol...
Definition: meshUtil.h:66
An implementation of HdBufferSource where the source data value is a VtValue.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:343