diff options
author | Patrick Mours <pmours@nvidia.com> | 2022-03-23 18:07:43 +0300 |
---|---|---|
committer | Patrick Mours <pmours@nvidia.com> | 2022-03-23 18:39:05 +0300 |
commit | d350976ba06d4ef93aa53fc4cd9da57be46ae924 (patch) | |
tree | 808f38e6b0c663c7a50f1d98619c96ca0bd82018 /intern/cycles/hydra/volume.cpp | |
parent | 827e9ccb29dd50d155972444d608c35cf4698d6a (diff) |
Cycles: Add Hydra render delegate
This patch adds a Hydra render delegate to Cycles, allowing Cycles to be used for rendering
in applications that provide a Hydra viewport. The implementation was written from scratch
against Cycles X, for integration into the Blender repository to make it possible to continue
developing it in step with the rest of Cycles. For this purpose it follows the style of the rest of
the Cycles code and can be built with a CMake option
(`WITH_CYCLES_HYDRA_RENDER_DELEGATE=1`) similar to the existing standalone version
of Cycles.
Since Hydra render delegates need to be built against the exact USD version and other
dependencies as the target application is using, this is intended to be built separate from
Blender (`WITH_BLENDER=0` CMake option) and with support for library versions different
from what Blender is using. As such the CMake build scripts for Windows had to be modified
slightly, so that the Cycles Hydra render delegate can e.g. be built with MSVC 2017 again
even though Blender requires MSVC 2019 now, and it's possible to specify custom paths to
the USD SDK etc. The codebase supports building against the latest USD release 22.03 and all
the way back to USD 20.08 (with some limitations).
Reviewed By: brecht, LazyDodo
Differential Revision: https://developer.blender.org/D14398
Diffstat (limited to 'intern/cycles/hydra/volume.cpp')
-rw-r--r-- | intern/cycles/hydra/volume.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/intern/cycles/hydra/volume.cpp b/intern/cycles/hydra/volume.cpp new file mode 100644 index 00000000000..7b965c613ed --- /dev/null +++ b/intern/cycles/hydra/volume.cpp @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2022 NVIDIA Corporation + * Copyright 2022 Blender Foundation */ + +#include "hydra/volume.h" +#include "hydra/field.h" +#include "hydra/geometry.inl" +#include "scene/volume.h" + +HDCYCLES_NAMESPACE_OPEN_SCOPE + +// clang-format off +TF_DEFINE_PRIVATE_TOKENS(_tokens, + (openvdbAsset) +); +// clang-format on + +HdCyclesVolume::HdCyclesVolume(const SdfPath &rprimId +#if PXR_VERSION < 2102 + , + const SdfPath &instancerId +#endif + ) + : HdCyclesGeometry(rprimId +#if PXR_VERSION < 2102 + , + instancerId +#endif + ) +{ +} + +HdCyclesVolume::~HdCyclesVolume() +{ +} + +HdDirtyBits HdCyclesVolume::GetInitialDirtyBitsMask() const +{ + HdDirtyBits bits = HdCyclesGeometry::GetInitialDirtyBitsMask(); + bits |= HdChangeTracker::DirtyVolumeField; + return bits; +} + +void HdCyclesVolume::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyBits, bool &rebuild) +{ + Scene *const scene = (Scene *)_geom->get_owner(); + + if (dirtyBits & HdChangeTracker::DirtyVolumeField) { + for (const HdVolumeFieldDescriptor &field : + sceneDelegate->GetVolumeFieldDescriptors(GetId())) { + if (const auto openvdbAsset = static_cast<HdCyclesField *>( + sceneDelegate->GetRenderIndex().GetBprim(_tokens->openvdbAsset, field.fieldId))) { + const ustring name(field.fieldName.GetString()); + + AttributeStandard std = ATTR_STD_NONE; + if (name == Attribute::standard_name(ATTR_STD_VOLUME_DENSITY)) { + std = ATTR_STD_VOLUME_DENSITY; + } + else if (name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR)) { + std = ATTR_STD_VOLUME_COLOR; + } + else if (name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME)) { + std = ATTR_STD_VOLUME_FLAME; + } + else if (name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT)) { + std = ATTR_STD_VOLUME_HEAT; + } + else if (name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE)) { + std = ATTR_STD_VOLUME_TEMPERATURE; + } + else if (name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY)) { + std = ATTR_STD_VOLUME_VELOCITY; + } + + // Skip attributes that are not needed + if ((std != ATTR_STD_NONE && _geom->need_attribute(scene, std)) || + _geom->need_attribute(scene, name)) { + Attribute *const attr = (std != ATTR_STD_NONE) ? + _geom->attributes.add(std) : + _geom->attributes.add( + name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); + attr->data_voxel() = openvdbAsset->GetImageHandle(); + } + } + } + + rebuild = true; + } +} + +HDCYCLES_NAMESPACE_CLOSE_SCOPE |