HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorCorrectionTask.h
Go to the documentation of this file.
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"
33 #include "pxr/imaging/hgi/buffer.h"
38 
39 #include <string>
40 
42 
43 
44 /// \class HdxColorCorrectionTask
45 ///
46 /// A task for performing color correction (and optionally color grading) on a
47 /// color buffer to transform its color for display.
48 ///
50 {
51 public:
52  HDX_API
53  HdxColorCorrectionTask(HdSceneDelegate* delegate, SdfPath const& id);
54 
55  HDX_API
56  ~HdxColorCorrectionTask() override;
57 
58  /// Prepare the tasks resources
59  HDX_API
60  void Prepare(HdTaskContext* ctx,
61  HdRenderIndex* renderIndex) override;
62 
63  /// Execute the color correction task
64  HDX_API
65  void Execute(HdTaskContext* ctx) override;
66 
67 protected:
68  /// Sync the render pass resources
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 
131 /// \class HdxColorCorrectionTaskParams
132 ///
133 /// ColorCorrectionTask parameters.
134 ///
135 /// `lut3dSizeOCIO`: We default to 65 (0-64) samples which works well with
136 // OCIO resampling.
137 ///
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.
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  //
161 
162  // The width, height and depth used for the GPU LUT 3d texture.
164 
165  // The name of the aov to color correct
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 
181 
182 #endif
uint32_t HdDirtyBits
Definition: types.h:127
int HgiHandle< class HgiTexture > HgiTextureHandle
#define HDX_API
Definition: api.h:40
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
HDX_API std::ostream & operator<<(std::ostream &out, const HdxColorCorrectionTaskParams &pv)
Definition: token.h:87
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
HDX_API ~HdxColorCorrectionTask() override
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:570
Definition: path.h:288
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:72
Definition: task.h:44
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDX_API void Execute(HdTaskContext *ctx) override
Execute the color correction task.
HDX_API void _Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:556