All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 PXR_NAMESPACE_OPEN_SCOPE
36 
42 {
43 public:
46  : _bitset(0) {}
47 
51  int Allocate();
52 
55  void Free(int buffer);
56 
58  unsigned int NumBuffers();
59 
63  static constexpr int PXR_MAX_USER_VERTEX_BUFFERS = 16;
64 
65 private:
66  std::bitset<PXR_MAX_USER_VERTEX_BUFFERS> _bitset;
67 };
68 
69 
70 
71 // ----------------------------------------------------------------------
72 // The classes below implement the HdEmbreePrimvarSampler interface for
73 // the different interpolation modes that hydra supports. In some cases,
74 // implementations are broken out by geometry type (e.g. triangles vs
75 // subdiv).
76 
83 public:
88  VtValue const& value)
89  : _buffer(name, value)
90  , _sampler(_buffer) {}
91 
101  virtual bool Sample(unsigned int element, float u, float v, void* value,
102  HdTupleType dataType) const;
103 
104 private:
105  HdVtBufferSource const _buffer;
106  HdEmbreeBufferSampler const _sampler;
107 };
108 
119 public:
126  VtValue const& value,
127  VtIntArray const& primitiveParams)
128  : _buffer(name, value)
129  , _sampler(_buffer)
130  , _primitiveParams(primitiveParams) {}
131 
136  VtValue const& value)
137  : _buffer(name, value)
138  , _sampler(_buffer) {}
139 
151  virtual bool Sample(unsigned int element, float u, float v, void* value,
152  HdTupleType dataType) const;
153 
154 private:
155  HdVtBufferSource const _buffer;
156  HdEmbreeBufferSampler const _sampler;
157  VtIntArray const _primitiveParams;
158 };
159 
169 public:
176  VtValue const& value,
177  VtVec3iArray const& indices)
178  : _buffer(name, value)
179  , _sampler(_buffer)
180  , _indices(indices) {}
181 
194  virtual bool Sample(unsigned int element, float u, float v, void* value,
195  HdTupleType dataType) const;
196 
197 private:
198  HdVtBufferSource const _buffer;
199  HdEmbreeBufferSampler const _sampler;
200  VtVec3iArray const _indices;
201 };
202 
220 public:
227  VtValue const& value,
228  HdMeshUtil &meshUtil)
229  : _buffer(name, _Triangulate(name, value, meshUtil))
230  , _sampler(_buffer) {}
231 
245  virtual bool Sample(unsigned int element, float u, float v, void* value,
246  HdTupleType dataType) const;
247 
248 private:
249  HdVtBufferSource const _buffer;
250  HdEmbreeBufferSampler const _sampler;
251 
252  // Pass the "value" parameter through HdMeshUtils'
253  // ComputeTriangulatedFaceVaryingPrimvar(), which adjusts the primvar
254  // buffer data for the triangulated topology. HdMeshUtil is provided
255  // the source topology at construction time, so this class doesn't need
256  // to provide it.
257  static VtValue _Triangulate(TfToken const& name, VtValue const& value,
258  HdMeshUtil &meshUtil);
259 };
260 
269 public:
281  VtValue const& value,
282  RTCScene meshScene,
283  unsigned meshId,
284  HdEmbreeRTCBufferAllocator *allocator);
285 
288 
299  virtual bool Sample(unsigned int element, float u, float v, void* value,
300  HdTupleType dataType) const;
301 
302 private:
303  int _embreeBufferId;
304  HdVtBufferSource const _buffer;
305  RTCScene _meshScene;
306  unsigned _meshId;
307  HdEmbreeRTCBufferAllocator *_allocator;
308 };
309 
310 PXR_NAMESPACE_CLOSE_SCOPE
311 
312 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_MESH_SAMPLERS_H
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value, VtIntArray const &primitiveParams)
Constructor.
Definition: meshSamplers.h:125
HdEmbreeTriangleFaceVaryingSampler(TfToken const &name, VtValue const &value, HdMeshUtil &meshUtil)
Constructor.
Definition: meshSamplers.h:226
unsigned int NumBuffers()
Query how many buffers are currently in user for this geometry.
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.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:325
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 &lt;elem...
Definition: sampler.h:137
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const
Sample the primvar at an (element, u, v) location.
HdEmbreeRTCBufferAllocator()
Constructor. By default, set everything to unallocated.
Definition: meshSamplers.h:45
HdEmbreeTriangleVertexSampler(TfToken const &name, VtValue const &value, VtVec3iArray const &indices)
Constructor.
Definition: meshSamplers.h:175
int Allocate()
Allocate a buffer by finding the first clear bit, using that as the buffer number, and setting the bit to mark it as used.
This class implements the HdEmbreePrimvarSampler interface for primvars with &quot;uniform&quot; interpolation ...
Definition: meshSamplers.h:118
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:41
HdEmbreeConstantSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:87
virtual ~HdEmbreeSubdivVertexSampler()
Destructor. Frees the embree user vertex buffer.
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 &quot;vert...
Definition: meshSamplers.h:168
This class implements the HdEmbreePrimvarSampler interface for primvars on triangle meshes with &quot;face...
Definition: meshSamplers.h:219
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 subdiv meshes with &quot;vertex...
Definition: meshSamplers.h:268
A utility class that knows how to sample an element from a type-tagged buffer (like HdVtBufferSource)...
Definition: sampler.h:97
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:63
This class implements the HdEmbreePrimvarSampler interface for primvars with &quot;constant&quot; interpolation...
Definition: meshSamplers.h:82
HdEmbreeUniformSampler(TfToken const &name, VtValue const &value)
Constructor.
Definition: meshSamplers.h:135
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:174
A collection of utility algorithms for generating triangulation and quadrangulation of an input topol...
Definition: meshUtil.h:81
An implementation of HdBufferSource where the source data value is a VtValue.