meshSamplers.h
1 //
2 // Copyright 2017 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
25 #define PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/plugin/hdEmbree/sampler.h"
29 #include "pxr/imaging/hd/meshUtil.h"
30 #include "pxr/base/vt/types.h"
31 
32 #include <embree3/rtcore.h>
33 #include <embree3/rtcore_geometry.h>
34 
35 #include <bitset>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
44 {
45 public:
48  : _bitset(0) {}
49 
53  int Allocate();
54 
57  void Free(int buffer);
58 
60  unsigned int NumBuffers();
61 
65  static constexpr int PXR_MAX_USER_VERTEX_BUFFERS = 16;
66 
67 private:
68  std::bitset<PXR_MAX_USER_VERTEX_BUFFERS> _bitset;
69 };
70 
71 
72 
73 // ----------------------------------------------------------------------
74 // The classes below implement the HdEmbreePrimvarSampler interface for
75 // the different interpolation modes that hydra supports. In some cases,
76 // implementations are broken out by geometry type (e.g. triangles vs
77 // subdiv).
78 
85 public:
90  VtValue const& value)
91  : _buffer(name, value)
92  , _sampler(_buffer) {}
93 
103  virtual bool Sample(unsigned int element, float u, float v, void* value,
104  HdTupleType dataType) const;
105 
106 private:
107  HdVtBufferSource const _buffer;
108  HdEmbreeBufferSampler const _sampler;
109 };
110 
121 public:
128  VtValue const& value,
129  VtIntArray const& primitiveParams)
130  : _buffer(name, value)
131  , _sampler(_buffer)
132  , _primitiveParams(primitiveParams) {}
133 
138  VtValue const& value)
139  : _buffer(name, value)
140  , _sampler(_buffer) {}
141 
153  virtual bool Sample(unsigned int element, float u, float v, void* value,
154  HdTupleType dataType) const;
155 
156 private:
157  HdVtBufferSource const _buffer;
158  HdEmbreeBufferSampler const _sampler;
159  VtIntArray const _primitiveParams;
160 };
161 
171 public:
178  VtValue const& value,
179  VtVec3iArray const& indices)
180  : _buffer(name, value)
181  , _sampler(_buffer)
182  , _indices(indices) {}
183 
196  virtual bool Sample(unsigned int element, float u, float v, void* value,
197  HdTupleType dataType) const;
198 
199 private:
200  HdVtBufferSource const _buffer;
201  HdEmbreeBufferSampler const _sampler;
202  VtVec3iArray const _indices;
203 };
204 
222 public:
229  VtValue const& value,
230  HdMeshUtil &meshUtil)
231  : _buffer(name, _Triangulate(name, value, meshUtil))
232  , _sampler(_buffer) {}
233 
247  virtual bool Sample(unsigned int element, float u, float v, void* value,
248  HdTupleType dataType) const;
249 
250 private:
251  HdVtBufferSource const _buffer;
252  HdEmbreeBufferSampler const _sampler;
253 
254  // Pass the "value" parameter through HdMeshUtils'
255  // ComputeTriangulatedFaceVaryingPrimvar(), which adjusts the primvar
256  // buffer data for the triangulated topology. HdMeshUtil is provided
257  // the source topology at construction time, so this class doesn't need
258  // to provide it.
259  static VtValue _Triangulate(TfToken const& name, VtValue const& value,
260  HdMeshUtil &meshUtil);
261 };
262 
271 public:
283  VtValue const& value,
284  RTCScene meshScene,
285  unsigned meshId,
286  HdEmbreeRTCBufferAllocator *allocator);
287 
290 
301  virtual bool Sample(unsigned int element, float u, float v, void* value,
302  HdTupleType dataType) const;
303 
304 private:
305  int _embreeBufferId;
306  HdVtBufferSource const _buffer;
307  RTCScene _meshScene;
308  unsigned _meshId;
309  HdEmbreeRTCBufferAllocator *_allocator;
310 };
311 
312 PXR_NAMESPACE_CLOSE_SCOPE
313 
314 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value, VtIntArray const &primitiveParams)
Constructor.
Definition: meshSamplers.h:127
HdEmbreeTriangleFaceVaryingSampler(TfToken const &name, VtValue const &value, HdMeshUtil &meshUtil)
Constructor.
Definition: meshSamplers.h:228
unsigned int NumBuffers()
Query how many buffers are currently in user for this geometry.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:358
void Free(int buffer)
Free a buffer by clearing its bit.
An abstract base class that knows how to sample a primvar signal given a ray hit coordinate: an <elem...
Definition: sampler.h:136
HdEmbreeRTCBufferAllocator()
Constructor. By default, set everything to unallocated.
Definition: meshSamplers.h:47
HdEmbreeTriangleVertexSampler(TfToken const &name, VtValue const &value, VtVec3iArray const &indices)
Constructor.
Definition: meshSamplers.h:177
int Allocate()
Allocate a buffer by finding the first clear bit, using that as the buffer number,...
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:120
HdEmbreeSubdivVertexSampler(TfToken const &name, VtValue const &value, RTCScene meshScene, unsigned meshId, HdEmbreeRTCBufferAllocator *allocator)
Constructor.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Utility class to track which embree user vertex buffers are currently in use.
Definition: meshSamplers.h:43
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
Defines all the types "TYPED" for which Vt creates a VtTYPEDArray typedef.
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 bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
HdEmbreeConstantSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:89
virtual ~HdEmbreeSubdivVertexSampler()
Destructor. Frees the embree user vertex buffer.
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with "vert...
Definition: meshSamplers.h:170
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with "face...
Definition: meshSamplers.h:221
This class implements the HdEmbreePrimvarSampler interface for primvars on subdiv meshes with "vertex...
Definition: meshSamplers.h:270
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
A utility class that knows how to sample an element from a type-tagged buffer (like HdVtBufferSource)...
Definition: sampler.h:96
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:65
This class implements the HdEmbreePrimvarSampler interface for primvars with "constant" interpolation...
Definition: meshSamplers.h:84
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:137
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
A collection of utility algorithms for generating triangulation and quadrangulation of an input topol...
Definition: meshUtil.h:82
An implementation of HdBufferSource where the source data value is a VtValue.