9 #include <pxr/base/gf/vec2f.h>
10 #include <pxr/imaging/hd/extComputationUtils.h>
20 output.reserve(primitiveParams.size());
21 const T &
input = value.Get<
T>();
23 for (
size_t i = 0; i < primitiveParams.size(); ++i) {
24 const int faceIndex = HdMeshUtil::DecodeFaceIndexFromCoarseFaceParam(primitiveParams[i]);
33 const HdType valueType,
34 const VtIntArray &primitiveParams)
38 return ComputeTriangulatedUniformPrimvar<VtFloatArray>(value, primitiveParams);
40 return ComputeTriangulatedUniformPrimvar<VtVec2fArray>(value, primitiveParams);
42 return ComputeTriangulatedUniformPrimvar<VtVec3fArray>(value, primitiveParams);
44 return ComputeTriangulatedUniformPrimvar<VtVec4fArray>(value, primitiveParams);
46 TF_RUNTIME_ERROR(
"Unsupported attribute type %d",
static_cast<int>(valueType));
52 const HdType valueType,
55 if (meshUtil.ComputeTriangulatedFaceVaryingPrimvar(
56 HdGetValueData(value), value.GetArraySize(), valueType, &value)) {
82 #
if PXR_VERSION < 2102
84 const SdfPath &instancerId
88 #
if PXR_VERSION < 2102
93 _util(&_topology, rprimId)
104 bits |= HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyNormals |
105 HdChangeTracker::DirtyPrimvar | HdChangeTracker::DirtyTopology |
106 HdChangeTracker::DirtyDisplayStyle | HdChangeTracker::DirtySubdivTags;
110 HdDirtyBits HdCyclesMesh::_PropagateDirtyBits(HdDirtyBits bits)
const
112 if (bits & (HdChangeTracker::DirtyMaterialId)) {
114 bits |= HdChangeTracker::DirtyTopology;
117 if (bits & (HdChangeTracker::DirtyTopology | HdChangeTracker::DirtyDisplayStyle |
118 HdChangeTracker::DirtySubdivTags)) {
120 bits |= HdChangeTracker::DirtyTopology | HdChangeTracker::DirtyDisplayStyle |
121 HdChangeTracker::DirtySubdivTags;
124 if (bits & (HdChangeTracker::DirtyTopology)) {
126 bits |= HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyNormals |
127 HdChangeTracker::DirtyPrimvar;
133 void HdCyclesMesh::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyBits,
bool &rebuild)
135 if (HdChangeTracker::IsTopologyDirty(dirtyBits, GetId())) {
136 PopulateTopology(sceneDelegate);
139 if (dirtyBits & HdChangeTracker::DirtyPoints) {
140 PopulatePoints(sceneDelegate);
144 if (dirtyBits & HdChangeTracker::DirtyNormals) {
145 PopulateNormals(sceneDelegate);
149 if (dirtyBits & HdChangeTracker::DirtyPrimvar) {
150 PopulatePrimvars(sceneDelegate);
153 rebuild = (
_geom->triangles_is_modified()) || (
_geom->subd_start_corner_is_modified()) ||
154 (
_geom->subd_num_corners_is_modified()) || (
_geom->subd_shader_is_modified()) ||
155 (
_geom->subd_smooth_is_modified()) || (
_geom->subd_ptex_offset_is_modified()) ||
156 (
_geom->subd_face_corners_is_modified());
159 void HdCyclesMesh::PopulatePoints(HdSceneDelegate *sceneDelegate)
163 for (
const HdExtComputationPrimvarDescriptor &desc :
164 sceneDelegate->GetExtComputationPrimvarDescriptors(GetId(), HdInterpolationVertex)) {
165 if (desc.name == HdTokens->points) {
166 auto valueStore = HdExtComputationUtils::GetComputedPrimvarValues({desc}, sceneDelegate);
167 const auto valueStoreIt = valueStore.find(desc.name);
168 if (valueStoreIt != valueStore.end()) {
169 value = std::move(valueStoreIt->second);
175 if (value.IsEmpty()) {
176 value = GetPoints(sceneDelegate);
179 if (!value.IsHolding<VtVec3fArray>()) {
180 TF_WARN(
"Invalid points data for %s", GetId().GetText());
184 const auto &points = value.UncheckedGet<VtVec3fArray>();
186 TF_VERIFY(points.size() >=
static_cast<size_t>(_topology.GetNumPoints()));
189 pointsDataCycles.
reserve(points.size());
190 for (
const GfVec3f &
point : points) {
194 _geom->set_verts(pointsDataCycles);
197 void HdCyclesMesh::PopulateNormals(HdSceneDelegate *sceneDelegate)
208 HdInterpolation interpolation = HdInterpolationCount;
210 for (
int i = 0; i < HdInterpolationCount && interpolation == HdInterpolationCount; ++i) {
211 for (
const HdExtComputationPrimvarDescriptor &desc :
212 sceneDelegate->GetExtComputationPrimvarDescriptors(GetId(),
213 static_cast<HdInterpolation
>(i))) {
214 if (desc.name == HdTokens->normals) {
215 auto valueStore = HdExtComputationUtils::GetComputedPrimvarValues({desc}, sceneDelegate);
216 const auto valueStoreIt = valueStore.find(desc.name);
217 if (valueStoreIt != valueStore.end()) {
218 value = std::move(valueStoreIt->second);
219 interpolation =
static_cast<HdInterpolation
>(i);
226 if (value.IsEmpty()) {
228 if (interpolation == HdInterpolationCount) {
232 value = GetNormals(sceneDelegate);
235 if (!value.IsHolding<VtVec3fArray>()) {
236 TF_WARN(
"Invalid normals data for %s", GetId().GetText());
240 const auto &
normals = value.UncheckedGet<VtVec3fArray>();
242 if (interpolation == HdInterpolationConstant) {
243 TF_VERIFY(
normals.size() == 1);
245 const GfVec3f constantNormal =
normals[0];
248 for (
size_t i = 0; i <
_geom->get_verts().
size(); ++i) {
249 N[i] =
make_float3(constantNormal[0], constantNormal[1], constantNormal[2]);
252 else if (interpolation == HdInterpolationUniform) {
253 TF_VERIFY(
normals.size() ==
static_cast<size_t>(_topology.GetNumFaces()));
256 for (
size_t i = 0; i <
_geom->num_triangles(); ++i) {
257 const int faceIndex = HdMeshUtil::DecodeFaceIndexFromCoarseFaceParam(_primitiveParams[i]);
262 else if (interpolation == HdInterpolationVertex || interpolation == HdInterpolationVarying) {
263 TF_VERIFY(
normals.size() ==
static_cast<size_t>(_topology.GetNumPoints()) &&
264 static_cast<size_t>(_topology.GetNumPoints()) ==
_geom->get_verts().size());
267 for (
size_t i = 0; i <
_geom->get_verts().
size(); ++i) {
271 else if (interpolation == HdInterpolationFaceVarying) {
272 TF_VERIFY(
normals.size() ==
static_cast<size_t>(_topology.GetNumFaceVaryings()));
274 if (!_util.ComputeTriangulatedFaceVaryingPrimvar(
279 const auto &normalsTriangulated = value.UncheckedGet<VtVec3fArray>();
283 for (
size_t i = 0; i <
_geom->num_triangles(); ++i) {
284 GfVec3f averageNormal = normalsTriangulated[i * 3] + normalsTriangulated[i * 3 + 1] +
285 normalsTriangulated[i * 3 + 2];
286 GfNormalize(&averageNormal);
288 N[i] =
make_float3(averageNormal[0], averageNormal[1], averageNormal[2]);
293 void HdCyclesMesh::PopulatePrimvars(HdSceneDelegate *sceneDelegate)
300 const std::pair<HdInterpolation, AttributeElement> interpolations[] = {
308 for (
const auto &interpolation : interpolations) {
309 for (
const HdPrimvarDescriptor &desc :
310 GetPrimvarDescriptors(sceneDelegate, interpolation.first)) {
312 if (desc.name == HdTokens->points || desc.name == HdTokens->normals) {
316 VtValue value = GetPrimvar(sceneDelegate, desc.name);
317 if (value.IsEmpty()) {
321 const ustring name(desc.name.GetString());
324 if (desc.role == HdPrimvarRoleTokens->textureCoordinate) {
327 else if (interpolation.first == HdInterpolationVertex) {
328 if (desc.name == HdTokens->displayColor || desc.role == HdPrimvarRoleTokens->color) {
331 else if (desc.name == HdTokens->normals) {
335 else if (desc.name == HdTokens->displayColor &&
336 interpolation.first == HdInterpolationConstant) {
337 if (value.IsHolding<VtVec3fArray>() && value.GetArraySize() == 1) {
338 const GfVec3f
color = value.UncheckedGet<VtVec3fArray>()[0];
346 const HdType valueType = HdGetValueTupleType(value).type;
350 if (interpolation.first == HdInterpolationUniform) {
352 if (value.IsEmpty()) {
356 else if (interpolation.first == HdInterpolationFaceVarying) {
358 if (value.IsEmpty()) {
370 void HdCyclesMesh::PopulateTopology(HdSceneDelegate *sceneDelegate)
375 const HdDisplayStyle displayStyle = GetDisplayStyle(sceneDelegate);
376 _topology = HdMeshTopology(GetMeshTopology(sceneDelegate), displayStyle.refineLevel);
378 const TfToken subdivScheme = _topology.GetScheme();
379 if (subdivScheme == PxOsdOpenSubdivTokens->bilinear && _topology.GetRefineLevel() > 0) {
382 else if (subdivScheme == PxOsdOpenSubdivTokens->catmullClark && _topology.GetRefineLevel() > 0) {
389 const bool smooth = !displayStyle.flatShadingEnabled;
393 VtIntArray faceShaders(_topology.GetNumFaces(), 0);
395 HdGeomSubsets
const &geomSubsets = _topology.GetGeomSubsets();
396 if (!geomSubsets.empty()) {
401 std::unordered_map<SdfPath, int, SdfPath::Hash>
materials;
403 for (
const HdGeomSubset &geomSubset : geomSubsets) {
404 TF_VERIFY(geomSubset.type == HdGeomSubset::TypeFaceSet);
407 const auto it =
materials.find(geomSubset.materialId);
413 sceneDelegate->GetRenderIndex().GetSprim(HdPrimTypeTokens->material,
414 geomSubset.materialId));
417 shader =
static_cast<int>(usedShaders.
size());
420 materials.emplace(geomSubset.materialId, shader);
424 for (
int face : geomSubset.indices) {
425 faceShaders[face] = shader;
429 _geom->set_used_shaders(usedShaders);
432 const VtIntArray vertIndx = _topology.GetFaceVertexIndices();
433 const VtIntArray vertCounts = _topology.GetFaceVertexCounts();
436 VtVec3iArray triangles;
437 _util.ComputeTriangleIndices(&triangles, &_primitiveParams);
439 _geom->reserve_mesh(_topology.GetNumPoints(), triangles.size());
441 for (
size_t i = 0; i < _primitiveParams.size(); ++i) {
442 const int faceIndex = HdMeshUtil::DecodeFaceIndexFromCoarseFaceParam(_primitiveParams[i]);
444 const GfVec3i triangle = triangles[i];
445 _geom->add_triangle(triangle[0], triangle[1], triangle[2], faceShaders[faceIndex],
smooth);
449 PxOsdSubdivTags subdivTags = GetSubdivTags(sceneDelegate);
450 _topology.SetSubdivTags(subdivTags);
453 size_t numCorners = 0;
454 for (
int vertCount : vertCounts) {
455 numNgons += (vertCount == 4) ? 0 : 1;
456 numCorners += vertCount;
459 _geom->reserve_subd_faces(_topology.GetNumFaces(), numNgons, numCorners);
462 size_t faceIndex = 0;
463 size_t indexOffset = 0;
464 for (
int vertCount : vertCounts) {
465 _geom->add_subd_face(&vertIndx[indexOffset], vertCount, faceShaders[faceIndex],
smooth);
468 indexOffset += vertCount;
471 const VtIntArray creaseLengths = subdivTags.GetCreaseLengths();
472 if (!creaseLengths.empty()) {
473 size_t numCreases = 0;
474 for (
int creaseLength : creaseLengths) {
475 numCreases += creaseLength - 1;
478 _geom->reserve_subd_creases(numCreases);
480 const VtIntArray creaseIndices = subdivTags.GetCreaseIndices();
481 const VtFloatArray creaseWeights = subdivTags.GetCreaseWeights();
484 size_t creaseLengthOffset = 0;
485 size_t createWeightOffset = 0;
486 for (
int creaseLength : creaseLengths) {
487 for (
int j = 0; j < creaseLength - 1; ++j, ++createWeightOffset) {
488 const int v0 = creaseIndices[indexOffset + j];
489 const int v1 = creaseIndices[indexOffset + j + 1];
491 float weight = creaseWeights.size() == creaseLengths.size() ?
492 creaseWeights[creaseLengthOffset] :
493 creaseWeights[createWeightOffset];
495 _geom->add_edge_crease(v0,
v1, weight);
498 indexOffset += creaseLength;
499 creaseLengthOffset++;
502 const VtIntArray cornerIndices = subdivTags.GetCornerIndices();
503 const VtFloatArray cornerWeights = subdivTags.GetCornerWeights();
505 for (
size_t i = 0; i < cornerIndices.size(); ++i) {
506 _geom->add_vertex_crease(cornerIndices[i], cornerWeights[i]);
510 _geom->set_subd_dicing_rate(1.0f);
511 _geom->set_subd_max_level(_topology.GetRefineLevel());
518 _topology = HdMeshTopology();
519 _primitiveParams.clear();
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
virtual void Finalize(PXR_NS::HdRenderParam *renderParam) override
PXR_NS::HdInterpolation GetPrimvarInterpolation(PXR_NS::HdSceneDelegate *sceneDelegate, const PXR_NS::TfToken &name) const
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
std::vector< CCL_NS::Object * > _instances
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
HdCyclesMesh(const PXR_NS::SdfPath &rprimId, const PXR_NS::SdfPath &instancerId={})
void Finalize(PXR_NS::HdRenderParam *renderParam) override
void push_back_reserved(const T &t)
T * resize(size_t newsize)
void reserve(size_t newcapacity)
void push_back_slow(const T &t)
smooth(Type::VEC4, "color_mul") .smooth(Type gpFillTexture gpSceneDepthTexture materials[GPENCIL_MATERIAL_BUFFER_LEN]
HDCYCLES_NAMESPACE_OPEN_SCOPE void ApplyPrimvars(AttributeSet &attributes, const ustring &name, VtValue value, AttributeElement elem, AttributeStandard std)
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
Transform convert_transform(const GfMatrix4d &matrix)
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
VtValue ComputeTriangulatedFaceVaryingPrimvar(VtValue value, const HdType valueType, HdMeshUtil &meshUtil)
VtValue ComputeTriangulatedUniformPrimvar(VtValue value, const HdType valueType, const VtIntArray &primitiveParams)
MutableSpan< float3 > normals
smooth(Type::FLOAT, "mask_weight")
@ SUBDIVISION_CATMULL_CLARK