HDK
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
visualizeAovTask.h
Go to the documentation of this file.
1
//
2
// Copyright 2021 Pixar
3
//
4
// Licensed under the terms set forth in the LICENSE.txt file available at
5
// https://openusd.org/license.
6
//
7
#ifndef HDX_VISUALIZE_AOV_TASK_H
8
#define HDX_VISUALIZE_AOV_TASK_H
9
10
#include "
pxr/pxr.h
"
11
#include "
pxr/base/gf/vec3i.h
"
12
#include "
pxr/imaging/hdx/api.h
"
13
#include "
pxr/imaging/hdx/task.h
"
14
#include "
pxr/imaging/hdx/tokens.h
"
15
#include "
pxr/imaging/hgi/attachmentDesc.h
"
16
#include "
pxr/imaging/hgi/buffer.h
"
17
#include "
pxr/imaging/hgi/graphicsPipeline.h
"
18
#include "
pxr/imaging/hgi/resourceBindings.h
"
19
#include "
pxr/imaging/hgi/shaderProgram.h
"
20
#include "
pxr/imaging/hgi/texture.h
"
21
#include "
pxr/usd/sdf/path.h
"
22
23
PXR_NAMESPACE_OPEN_SCOPE
24
25
struct
HdxVisualizeAovTaskParams
;
26
27
/// \class HdxVisualizeAovTask
28
///
29
/// A task for visualizing non-color AOVs such as depth, normals, primId.
30
///
31
/// Different kernels are used depending on the AOV:
32
/// Depth: Renormalized from the range [0.0, 1.0] to [min, max] depth
33
/// to provide better contrast.
34
/// Normals: Transform each component from [-1.0, 1.0] tp [0.0, 1.0] so that
35
/// negative components don't appear black.
36
/// Ids: Integer ids are colorized by multiplying by a large prime and
37
/// shuffling resulting bits so that neighboring ids are easily
38
/// distinguishable.
39
/// Other Aovs: A fallback kernel that transfers the AOV contents into a
40
/// float texture is used.
41
///
42
/// This task updates the 'color' entry of the task context with the colorized
43
/// texture contents.
44
///
45
class
HdxVisualizeAovTask
:
public
HdxTask
46
{
47
public
:
48
using
TaskParams
=
HdxVisualizeAovTaskParams
;
49
50
HDX_API
51
HdxVisualizeAovTask
(
HdSceneDelegate
* delegate,
SdfPath
const
&
id
);
52
53
HDX_API
54
~HdxVisualizeAovTask
()
override
;
55
56
HDX_API
57
void
Prepare
(
HdTaskContext
* ctx,
58
HdRenderIndex
* renderIndex)
override
;
59
60
HDX_API
61
void
Execute
(
HdTaskContext
* ctx)
override
;
62
63
protected
:
64
HDX_API
65
void
_Sync
(
HdSceneDelegate
* delegate,
66
HdTaskContext
* ctx,
67
HdDirtyBits
* dirtyBits)
override
;
68
69
private
:
70
// Enumeration of visualization kernels
71
enum
VizKernel {
72
VizKernelDepth = 0,
73
VizKernelId,
74
VizKernelNormal,
75
VizKernelFallback,
76
VizKernelNone
77
};
78
79
HdxVisualizeAovTask
() =
delete
;
80
HdxVisualizeAovTask
(
const
HdxVisualizeAovTask
&) =
delete
;
81
HdxVisualizeAovTask
&operator =(
const
HdxVisualizeAovTask
&) =
delete
;
82
83
// Returns true if the enum member was updated, indicating that the kernel
84
// to be used has changed.
85
bool
_UpdateVizKernel(
TfToken
const
&aovName);
86
87
// Returns a token used in sampling the texture based on the kernel used.
88
TfToken
const
& _GetTextureIdentifierForShader()
const
;
89
90
// Returns the fragment shader mixin based on the kernel used.
91
TfToken
const
& _GetFragmentMixin()
const
;
92
93
// ------------- Hgi resource creation/deletion utilities ------------------
94
// Utility function to create the GL program for color correction
95
bool
_CreateShaderResources(
HgiTextureDesc
const
& inputAovTextureDesc);
96
97
// Utility function to create buffer resources.
98
bool
_CreateBufferResources();
99
100
// Utility to create resource bindings
101
bool
_CreateResourceBindings(
HgiTextureHandle
const
& inputAovTexture);
102
103
// Utility to create a pipeline
104
bool
_CreatePipeline(
HgiTextureDesc
const
& outputTextureDesc);
105
106
// Utility to create a texture sampler
107
bool
_CreateSampler(
HgiTextureDesc
const
& inputAovTextureDesc);
108
109
// Create texture to write the colorized results into.
110
bool
_CreateOutputTexture(
GfVec3i
const
&dimensions);
111
112
// Destroy shader program and the shader functions it holds.
113
void
_DestroyShaderProgram();
114
115
// Print shader compile errors.
116
void
_PrintCompileErrors();
117
// -------------------------------------------------------------------------
118
119
// Readback the depth AOV on the CPU to update min, max values.
120
void
_UpdateMinMaxDepth(
HgiTextureHandle
const
&inputAovTexture);
121
122
// Execute the appropriate kernel and update the task context 'color' entry.
123
void
_ApplyVisualizationKernel(
HgiTextureHandle
const
& outputTexture);
124
125
// Kernel dependent resources
126
HgiTextureHandle
_outputTexture;
127
GfVec3i
_outputTextureDimensions;
128
HgiAttachmentDesc
_outputAttachmentDesc;
129
HgiShaderProgramHandle
_shaderProgram;
130
HgiResourceBindingsHandle
_resourceBindings;
131
HgiGraphicsPipelineHandle
_pipeline;
132
133
// Kernel independent resources
134
HgiBufferHandle
_indexBuffer;
135
HgiBufferHandle
_vertexBuffer;
136
HgiSamplerHandle
_sampler;
137
138
float
_screenSize[2];
139
float
_minMaxDepth[2];
140
VizKernel _vizKernel;
141
};
142
143
144
/// \class HdxVisualizeAovTaskParams
145
///
146
/// `aovName`: The name of the aov to visualize.
147
///
148
/// The Hgi texture resource backing the AOV is retreived from the task context
149
/// instead of fetching the render buffer prim via its render index path.
150
/// HdxAovInputTask is responsible for updating the task context entry for
151
/// the active AOV.
152
///
153
struct
HdxVisualizeAovTaskParams
154
{
155
HDX_API
156
HdxVisualizeAovTaskParams
();
157
158
TfToken
aovName
;
159
};
160
161
// VtValue requirements
162
HDX_API
163
std::ostream&
operator<<
(std::ostream& out,
const
HdxVisualizeAovTaskParams
& pv);
164
HDX_API
165
bool
operator==
(
const
HdxVisualizeAovTaskParams
& lhs,
166
const
HdxVisualizeAovTaskParams
& rhs);
167
HDX_API
168
bool
operator!=
(
const
HdxVisualizeAovTaskParams
& lhs,
169
const
HdxVisualizeAovTaskParams
& rhs);
170
171
PXR_NAMESPACE_CLOSE_SCOPE
172
173
#endif
HdxVisualizeAovTaskParams::HdxVisualizeAovTaskParams
HDX_API HdxVisualizeAovTaskParams()
HdRenderIndex
Definition:
renderIndex.h:104
HgiAttachmentDesc
Definition:
attachmentDesc.h:48
HdDirtyBits
uint32_t HdDirtyBits
Definition:
types.h:143
HdxVisualizeAovTask::Prepare
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
HdxVisualizeAovTask
Definition:
visualizeAovTask.h:45
HgiTextureHandle
int HgiHandle< class HgiTexture > HgiTextureHandle
Definition:
ptexTextureObject.h:36
shaderProgram.h
HDX_API
#define HDX_API
Definition:
api.h:23
HgiTextureDesc
Definition:
texture.h:90
TfToken
Definition:
token.h:70
operator<<
HDX_API std::ostream & operator<<(std::ostream &out, const HdxVisualizeAovTaskParams &pv)
HdxVisualizeAovTaskParams
Definition:
visualizeAovTask.h:153
tokens.h
pxr.h
HdSceneDelegate
Definition:
sceneDelegate.h:404
openvdb::OPENVDB_VERSION_NAME::math::Mat3::operator!=
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition:
Mat3.h:556
HdxVisualizeAovTask::~HdxVisualizeAovTask
HDX_API ~HdxVisualizeAovTask() override
texture.h
GfVec3i
Definition:
vec3i.h:43
SdfPath
Definition:
path.h:273
HdTaskContext
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition:
renderIndex.h:61
path.h
task.h
HdxTask
Definition:
task.h:27
graphicsPipeline.h
resourceBindings.h
HdxVisualizeAovTaskParams::aovName
TfToken aovName
Definition:
visualizeAovTask.h:158
PXR_NAMESPACE_OPEN_SCOPE
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition:
path.h:1425
buffer.h
api.h
PXR_NAMESPACE_CLOSE_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition:
pxr.h:74
HdxVisualizeAovTask::Execute
HDX_API void Execute(HdTaskContext *ctx) override
vec3i.h
attachmentDesc.h
HdxVisualizeAovTask::_Sync
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
HgiHandle< class HgiShaderProgram >
openvdb::OPENVDB_VERSION_NAME::math::Mat3::operator==
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition:
Mat3.h:542
pxr
imaging
hdx
visualizeAovTask.h
Generated on Thu Sep 4 2025 02:39:04 for HDK by
1.8.6