All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorCorrectionTask.h
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef HDX_COLORCORRECTION_TASK_H
25 #define HDX_COLORCORRECTION_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/path.h"
29 #include "pxr/imaging/hdx/api.h"
30 #include "pxr/imaging/hdx/task.h"
31 #include "pxr/imaging/hdx/tokens.h"
32 #include "pxr/imaging/hgi/attachmentDesc.h"
33 #include "pxr/imaging/hgi/buffer.h"
34 #include "pxr/imaging/hgi/graphicsPipeline.h"
35 #include "pxr/imaging/hgi/resourceBindings.h"
36 #include "pxr/imaging/hgi/shaderProgram.h"
37 #include "pxr/imaging/hgi/texture.h"
38 
39 #include <string>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 
50 {
51 public:
52  HDX_API
53  HdxColorCorrectionTask(HdSceneDelegate* delegate, SdfPath const& id);
54 
55  HDX_API
56  ~HdxColorCorrectionTask() override;
57 
59  HDX_API
60  void Prepare(HdTaskContext* ctx,
61  HdRenderIndex* renderIndex) override;
62 
64  HDX_API
65  void Execute(HdTaskContext* ctx) override;
66 
67 protected:
69  HDX_API
70  void _Sync(HdSceneDelegate* delegate,
71  HdTaskContext* ctx,
72  HdDirtyBits* dirtyBits) override;
73 
74 private:
75  HdxColorCorrectionTask() = delete;
76  HdxColorCorrectionTask(const HdxColorCorrectionTask &) = delete;
77  HdxColorCorrectionTask &operator =(const HdxColorCorrectionTask &) = delete;
78 
79  // Utility to create OCIO resources and returns the OCIO shadercode
80  std::string _CreateOpenColorIOResources();
81 
82  // Utility to check if OCIO should be used
83  bool _GetUseOcio() const;
84 
85  // Utility function to create the GL program for color correction
86  bool _CreateShaderResources();
87 
88  // Utility function to create buffer resources.
89  bool _CreateBufferResources();
90 
91  // Utility to create resource bindings
92  bool _CreateResourceBindings(HgiTextureHandle const& aovTexture);
93 
94  // Utility to create a pipeline
95  bool _CreatePipeline(HgiTextureHandle const& aovTexture);
96 
97  // Utility to create a texture sampler
98  bool _CreateSampler();
99 
100  // Apply color correction to the currently bound framebuffer.
101  void _ApplyColorCorrection(HgiTextureHandle const& aovTexture);
102 
103  // Destroy shader program and the shader functions it holds.
104  void _DestroyShaderProgram();
105 
106  // Print shader compile errors.
107  void _PrintCompileErrors();
108 
109  HgiAttachmentDesc _attachment0;
110  HgiBufferHandle _indexBuffer;
111  HgiBufferHandle _vertexBuffer;
112  HgiTextureHandle _texture3dLUT;
113  HgiSamplerHandle _sampler;
114  HgiShaderProgramHandle _shaderProgram;
115  HgiResourceBindingsHandle _resourceBindings;
116  HgiGraphicsPipelineHandle _pipeline;
117 
118  TfToken _colorCorrectionMode;
119  std::string _displayOCIO;
120  std::string _viewOCIO;
121  std::string _colorspaceOCIO;
122  std::string _looksOCIO;
123  int _lut3dSizeOCIO;
124 
125  float _screenSize[2];
126 
127  TfToken _aovName;
128 };
129 
130 
136 // OCIO resampling.
139 {
140  HDX_API
142 
143  // Switch between HdColorCorrectionTokens.
144  // We default to 'disabled' to be backwards compatible with clients that are
145  // still running with sRGB buffers.
146  TfToken colorCorrectionMode;
147 
148  // 'display', 'view', 'colorspace' and 'look' are options the client may
149  // supply to configure OCIO. If one is not provided the default values
150  // is substituted. You can find the values for these strings inside the
151  // profile/config .ocio file. For example:
152  //
153  // displays:
154  // rec709g22:
155  // !<View> {name: studio, colorspace: linear, looks: studio_65_lg2}
156  //
157  std::string displayOCIO;
158  std::string viewOCIO;
159  std::string colorspaceOCIO;
160  std::string looksOCIO;
161 
162  // The width, height and depth used for the GPU LUT 3d texture.
163  int lut3dSizeOCIO;
164 
165  // The name of the aov to color correct
166  TfToken aovName;
167 };
168 
169 // VtValue requirements
170 HDX_API
171 std::ostream& operator<<(std::ostream& out, const HdxColorCorrectionTaskParams& pv);
172 HDX_API
174  const HdxColorCorrectionTaskParams& rhs);
175 HDX_API
177  const HdxColorCorrectionTaskParams& rhs);
178 
179 
180 PXR_NAMESPACE_CLOSE_SCOPE
181 
182 #endif
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:116
A task for performing color correction (and optionally color grading) on a color buffer to transform ...
Describes the properties of a framebuffer attachment.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
ColorCorrectionTask parameters.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
HDX_API void Execute(HdTaskContext *ctx) override
Execute the color correction task.
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
Base class for (some) tasks in Hdx that provides common progressive rendering and Hgi functionality...
Definition: task.h:44
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.