Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pxr_library(hdSt
commandBuffer
computation
copyComputation
capsule
debugCodes
dependencyForwardingSceneIndexPlugin
dependencySceneIndexPlugin
Expand Down Expand Up @@ -191,6 +192,7 @@ pxr_library(hdSt
RESOURCE_FILES
plugInfo.json
shaders/basisCurves.glslfx
shaders/capsule.glslfx
shaders/compute.glslfx
shaders/coordUtils.glslfx
shaders/domeLight.glslfx
Expand Down
95 changes: 95 additions & 0 deletions pxr/imaging/hdSt/capsule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// Copyright 2026 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#include "pxr/pxr.h"

#include "pxr/imaging/hdSt/capsule.h"
#include "pxr/imaging/hdSt/drawItem.h"
#include "pxr/imaging/hdSt/resourceRegistry.h"

#include "pxr/imaging/hd/bufferSpec.h"
#include "pxr/imaging/hd/capsuleSchema.h"
#include "pxr/imaging/hd/perfLog.h"
#include "pxr/imaging/hd/sceneIndexAdapterSceneDelegate.h"
#include "pxr/imaging/hd/tokens.h"
#include "pxr/imaging/hd/vtBufferSource.h"

#include "pxr/base/vt/value.h"

PXR_NAMESPACE_OPEN_SCOPE

HdStCapsule::HdStCapsule(SdfPath const &id)
: HdStImplicitSurface(
id,
HdPrimTypeTokens->capsule,
HdBufferSpecVector{
HdBufferSpec(HdCapsuleSchemaTokens->height,
HdTupleType{HdTypeFloat, 1}),
HdBufferSpec(HdCapsuleSchemaTokens->radiusTop,
HdTupleType{HdTypeFloat, 1}),
HdBufferSpec(HdCapsuleSchemaTokens->radiusBottom,
HdTupleType{HdTypeFloat, 1}),
HdBufferSpec(HdCapsuleSchemaTokens->axis,
HdTupleType{HdTypeInt32, 1})})
{
}

void
HdStCapsule::_PopulateCustomConstantPrimvars(HdSceneDelegate *sceneDelegate,
HdRenderParam *renderParam,
HdStDrawItem *drawItem)
{
HD_TRACE_FUNCTION();
HF_MALLOC_TAG_FUNCTION();

HdStResourceRegistrySharedPtr resourceRegistry =
std::static_pointer_cast<HdStResourceRegistry>(
sceneDelegate->GetRenderIndex().GetResourceRegistry());

HdBufferArrayRangeSharedPtr const& bar = drawItem->GetConstantPrimvarRange();

const VtValue heightValue = sceneDelegate->Get(
GetId(), HdCapsuleSchemaTokens->height);
const VtValue radiusValue = sceneDelegate->Get(
GetId(), HdCapsuleSchemaTokens->radius);
const VtValue radiusTopValue = sceneDelegate->Get(
GetId(), HdCapsuleSchemaTokens->radiusTop);
const VtValue radiusBottomValue = sceneDelegate->Get(
GetId(), HdCapsuleSchemaTokens->radiusBottom);
const VtValue axisValue = sceneDelegate->Get(
GetId(), HdCapsuleSchemaTokens->axis);

const float height = heightValue.IsHolding<double>()
? static_cast<float>(heightValue.UncheckedGet<double>()) : 1.0f;
const float legacyRadius = radiusValue.IsHolding<double>()
? static_cast<float>(radiusValue.UncheckedGet<double>()) : 0.5f;
const float radiusTop = radiusTopValue.IsHolding<double>()
? static_cast<float>(radiusTopValue.UncheckedGet<double>())
: legacyRadius;
const float radiusBottom = radiusBottomValue.IsHolding<double>()
? static_cast<float>(radiusBottomValue.UncheckedGet<double>())
: legacyRadius;

const TfToken axis = axisValue.IsHolding<TfToken>()
? axisValue.UncheckedGet<TfToken>() : HdCapsuleSchemaTokens->Z;
const int axisIndex = axis == HdCapsuleSchemaTokens->X ? 0
: axis == HdCapsuleSchemaTokens->Y ? 1 : 2;

HdBufferSourceSharedPtrVector sources = {
std::make_shared<HdVtBufferSource>(
HdCapsuleSchemaTokens->height, VtValue(height)),
std::make_shared<HdVtBufferSource>(
HdCapsuleSchemaTokens->radiusTop, VtValue(radiusTop)),
std::make_shared<HdVtBufferSource>(
HdCapsuleSchemaTokens->radiusBottom, VtValue(radiusBottom)),
std::make_shared<HdVtBufferSource>(
HdCapsuleSchemaTokens->axis, VtValue(axisIndex))
};

resourceRegistry->AddSources(bar, std::move(sources));
}

PXR_NAMESPACE_CLOSE_SCOPE
43 changes: 43 additions & 0 deletions pxr/imaging/hdSt/capsule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Copyright 2026 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#ifndef PXR_IMAGING_HD_ST_CAPSULE_H
#define PXR_IMAGING_HD_ST_CAPSULE_H

#include "pxr/pxr.h"
#include "pxr/imaging/hdSt/api.h"
#include "pxr/imaging/hdSt/implicitSurface.h"
#include "pxr/imaging/hd/version.h"

#include "pxr/usd/sdf/path.h"

PXR_NAMESPACE_OPEN_SCOPE

/// \class HdStCapsule
///
/// Represents a capsule prim that can be rendered natively by Storm.
///
class HdStCapsule final : public HdStImplicitSurface
{
public:
HF_MALLOC_TAG_NEW("new HdStCapsule");

HDST_API
explicit HdStCapsule(SdfPath const &id);

HDST_API
~HdStCapsule() override = default;

protected:
HDST_API
void _PopulateCustomConstantPrimvars(HdSceneDelegate *sceneDelegate,
HdRenderParam *renderParam,
HdStDrawItem *drawItem) override;
};

PXR_NAMESPACE_CLOSE_SCOPE

#endif // PXR_IMAGING_HD_ST_CAPSULE_H
8 changes: 5 additions & 3 deletions pxr/imaging/hdSt/implicitSurfaceSceneIndexPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const HdContainerDataSourceHandle _LocalInputArgs()
{
// Configure the scene index to generate meshes for implicit primitives
// that are not natively supported by Storm. With
// HDST_ENABLE_NATIVE_SPHERES enabled, spheres can be rendered natively,
// so we avoid converting them to meshes here.
// When native implicit rendering is enabled for a prim type, avoid
// converting that type to a mesh here.
HdDataSourceBaseHandle const toMeshSrc =
HdRetainedTypedSampledDataSource<TfToken>::New(
HdsiImplicitSurfaceSceneIndexTokens->toMesh);
Expand All @@ -61,13 +61,15 @@ const HdContainerDataSourceHandle _LocalInputArgs()
HdPrimTypeTokens->cube,
HdPrimTypeTokens->cone,
HdPrimTypeTokens->cylinder,
HdPrimTypeTokens->capsule,
HdPrimTypeTokens->plane
};

if (!HdStRenderDelegate::IsEnabledNativeSphereRenderingSupport()) {
names.emplace_back(HdPrimTypeTokens->sphere);
}
if (!HdStRenderDelegate::IsEnabledNativeCapsuleRenderingSupport()) {
names.emplace_back(HdPrimTypeTokens->capsule);
}

std::vector<HdDataSourceBaseHandle> values(names.size(), toMeshSrc);

Expand Down
14 changes: 13 additions & 1 deletion pxr/imaging/hdSt/implicitSurfaceShaderKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ TF_DEFINE_PRIVATE_TOKENS(
((sphereVertex, "ImplicitSurface.Vertex.Sphere"))
((sphereFragment, "ImplicitSurface.Fragment.Sphere"))

((capsuleTypeDef, "ImplicitSurface.TypeDef.Capsule"))
((capsuleBounds, "ImplicitSurface.Bounds.Capsule"))
((capsuleIntersection, "ImplicitSurface.Intersection.Capsule"))
((capsuleVertex, "ImplicitSurface.Vertex.Capsule"))
((capsuleFragment, "ImplicitSurface.Fragment.Capsule"))

// main for all the shader stages
((mainVS, "ImplicitSurface.Vertex"))
((mainFS, "ImplicitSurface.Fragment"))
Expand Down Expand Up @@ -108,7 +114,13 @@ const _ShapeSections &_GetShapeSections(TfToken const &primType)
_tokens->sphereBounds,
_tokens->sphereIntersection,
_tokens->sphereVertex,
_tokens->sphereFragment } }
_tokens->sphereFragment } },
{ HdPrimTypeTokens->capsule,
{ _tokens->capsuleTypeDef,
_tokens->capsuleBounds,
_tokens->capsuleIntersection,
_tokens->capsuleVertex,
_tokens->capsuleFragment } }
};

for (auto const &entry : shapeTable) {
Expand Down
16 changes: 16 additions & 0 deletions pxr/imaging/hdSt/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pxr/imaging/hdSt/renderDelegate.h"

#include "pxr/imaging/hdSt/basisCurves.h"
#include "pxr/imaging/hdSt/capsule.h"
#include "pxr/imaging/hdSt/drawItemsCache.h"
#include "pxr/imaging/hdSt/drawTarget.h"
#include "pxr/imaging/hdSt/extComputation.h"
Expand Down Expand Up @@ -64,6 +65,10 @@ TF_DEFINE_ENV_SETTING(HDST_ENABLE_NATIVE_SPHERES, false,
"Enable native rendering of sphere primitives in Storm instead of "
"converting them to meshes via the implicit surface scene index.");

TF_DEFINE_ENV_SETTING(HDST_ENABLE_NATIVE_CAPSULES, false,
"Enable native rendering of capsule primitives in Storm instead of "
"converting them to meshes via the implicit surface scene index.");

namespace {
const TfTokenVector _SupportedRprimTypes()
{
Expand All @@ -77,6 +82,9 @@ const TfTokenVector _SupportedRprimTypes()
if (TfGetEnvSetting(HDST_ENABLE_NATIVE_SPHERES)) {
supportedTypes.emplace_back(HdPrimTypeTokens->sphere);
}
if (TfGetEnvSetting(HDST_ENABLE_NATIVE_CAPSULES)) {
supportedTypes.emplace_back(HdPrimTypeTokens->capsule);
}

return supportedTypes;
}
Expand Down Expand Up @@ -430,6 +438,8 @@ HdStRenderDelegate::CreateRprim(TfToken const& typeId,
return new HdStVolume(rprimId);
} else if (typeId == HdPrimTypeTokens->sphere) {
return new HdStSphere(rprimId);
} else if (typeId == HdPrimTypeTokens->capsule) {
return new HdStCapsule(rprimId);
} else {
TF_CODING_ERROR("Unknown Rprim Type %s", typeId.GetText());
}
Expand Down Expand Up @@ -730,4 +740,10 @@ HdStRenderDelegate::IsEnabledNativeSphereRenderingSupport()
return TfGetEnvSetting(HDST_ENABLE_NATIVE_SPHERES);
}

bool
HdStRenderDelegate::IsEnabledNativeCapsuleRenderingSupport()
{
return TfGetEnvSetting(HDST_ENABLE_NATIVE_CAPSULES);
}

PXR_NAMESPACE_CLOSE_SCOPE
3 changes: 3 additions & 0 deletions pxr/imaging/hdSt/renderDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class HdStRenderDelegate final : public HdRenderDelegate

HDST_API
static bool IsEnabledNativeSphereRenderingSupport();

HDST_API
static bool IsEnabledNativeCapsuleRenderingSupport();

private:
void _ApplyTextureSettings();
Expand Down
Loading
Loading