Loading...
Searching...
No Matches
visualizeAovTask.h
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
23PXR_NAMESPACE_OPEN_SCOPE
24
44{
45public:
46 HDX_API
47 HdxVisualizeAovTask(HdSceneDelegate* delegate, SdfPath const& id);
48
49 HDX_API
50 ~HdxVisualizeAovTask() override;
51
52 HDX_API
53 void Prepare(HdTaskContext* ctx,
54 HdRenderIndex* renderIndex) override;
55
56 HDX_API
57 void Execute(HdTaskContext* ctx) override;
58
59protected:
60 HDX_API
61 void _Sync(HdSceneDelegate* delegate,
62 HdTaskContext* ctx,
63 HdDirtyBits* dirtyBits) override;
64
65private:
66 // Enumeration of visualization kernels
67 enum VizKernel {
68 VizKernelDepth = 0,
69 VizKernelId,
70 VizKernelNormal,
71 VizKernelFallback,
72 VizKernelNone
73 };
74
75 HdxVisualizeAovTask() = delete;
77 HdxVisualizeAovTask &operator =(const HdxVisualizeAovTask &) = delete;
78
79 // Returns true if the enum member was updated, indicating that the kernel
80 // to be used has changed.
81 bool _UpdateVizKernel(TfToken const &aovName);
82
83 // Returns a token used in sampling the texture based on the kernel used.
84 TfToken const& _GetTextureIdentifierForShader() const;
85
86 // Returns the fragment shader mixin based on the kernel used.
87 TfToken const& _GetFragmentMixin() const;
88
89 // ------------- Hgi resource creation/deletion utilities ------------------
90 // Utility function to create the GL program for color correction
91 bool _CreateShaderResources(HgiTextureDesc const& inputAovTextureDesc);
92
93 // Utility function to create buffer resources.
94 bool _CreateBufferResources();
95
96 // Utility to create resource bindings
97 bool _CreateResourceBindings(HgiTextureHandle const& inputAovTexture);
98
99 // Utility to create a pipeline
100 bool _CreatePipeline(HgiTextureDesc const& outputTextureDesc);
101
102 // Utility to create a texture sampler
103 bool _CreateSampler();
104
105 // Create texture to write the colorized results into.
106 bool _CreateOutputTexture(GfVec3i const &dimensions);
107
108 // Destroy shader program and the shader functions it holds.
109 void _DestroyShaderProgram();
110
111 // Print shader compile errors.
112 void _PrintCompileErrors();
113 // -------------------------------------------------------------------------
114
115 // Readback the depth AOV on the CPU to update min, max values.
116 void _UpdateMinMaxDepth(HgiTextureHandle const &inputAovTexture);
117
118 // Execute the appropriate kernel and update the task context 'color' entry.
119 void _ApplyVisualizationKernel(HgiTextureHandle const& outputTexture);
120
121 // Kernel dependent resources
122 HgiTextureHandle _outputTexture;
123 GfVec3i _outputTextureDimensions;
124 HgiAttachmentDesc _outputAttachmentDesc;
125 HgiShaderProgramHandle _shaderProgram;
126 HgiResourceBindingsHandle _resourceBindings;
128
129 // Kernel independent resources
130 HgiBufferHandle _indexBuffer;
131 HgiBufferHandle _vertexBuffer;
132 HgiSamplerHandle _sampler;
133
134 float _screenSize[2];
135 float _minMaxDepth[2];
136 VizKernel _vizKernel;
137};
138
139
150{
151 HDX_API
153
154 TfToken aovName;
155};
156
157// VtValue requirements
158HDX_API
159std::ostream& operator<<(std::ostream& out, const HdxVisualizeAovTaskParams& pv);
160HDX_API
161bool operator==(const HdxVisualizeAovTaskParams& lhs,
162 const HdxVisualizeAovTaskParams& rhs);
163HDX_API
164bool operator!=(const HdxVisualizeAovTaskParams& lhs,
165 const HdxVisualizeAovTaskParams& rhs);
166
167PXR_NAMESPACE_CLOSE_SCOPE
168
169#endif
Basic type for a vector of 3 int components.
Definition: vec3i.h:44
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:104
Adapter class providing data exchange with the client scene graph.
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality.
Definition: task.h:28
A task for visualizing non-color AOVs such as depth, normals, primId.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
aovName: The name of the aov to visualize.
Describes the properties of a framebuffer attachment.
Describes the properties needed to create a GPU texture.
Definition: texture.h:91