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/hd/task.h"
31 #include "pxr/imaging/hdx/tokens.h"
32 #include "pxr/imaging/garch/gl.h"
33 #include <string>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 class HdStGLSLProgram;
38 typedef boost::shared_ptr<class HdStGLSLProgram> HdStGLSLProgramSharedPtr;
39 
40 
46 class HdxColorCorrectionTask : public HdTask
47 {
48 public:
49  HDX_API
50  HdxColorCorrectionTask(HdSceneDelegate* delegate, SdfPath const& id);
51 
52  HDX_API
53  virtual ~HdxColorCorrectionTask();
54 
56  HDX_API
57  virtual void Sync(HdSceneDelegate* delegate,
58  HdTaskContext* ctx,
59  HdDirtyBits* dirtyBits) override;
60 
62  HDX_API
63  virtual void Prepare(HdTaskContext* ctx,
64  HdRenderIndex* renderIndex) override;
65 
67  HDX_API
68  virtual void Execute(HdTaskContext* ctx) override;
69 
70 private:
71  HdxColorCorrectionTask() = delete;
72  HdxColorCorrectionTask(const HdxColorCorrectionTask &) = delete;
73  HdxColorCorrectionTask &operator =(const HdxColorCorrectionTask &) = delete;
74 
75  // Utility to create OCIO resources and returns the OCIO shadercode
76  std::string _CreateOpenColorIOResources();
77 
78  // Utility function to create the GL program for color correction
79  bool _CreateShaderResources();
80 
81  // Utility function to create buffer resources.
82  bool _CreateBufferResources();
83 
84  // Utility function to setup the copy-framebuffer
85  bool _CreateFramebufferResources();
86 
87  // Copies the client framebuffer texture into ours
88  void _CopyTexture();
89 
91  void _ApplyColorCorrection();
92 
93  HdStGLSLProgramSharedPtr _shaderProgram;
94  GLuint _texture;
95  GLuint _texture3dLUT;
96  GfVec2i _textureSize;
97  GLint _locations[4];
98  GLuint _vertexBuffer;
99 
100  GLuint _copyFramebuffer;
101  GfVec2i _framebufferSize;
102 
103  TfToken _colorCorrectionMode;
104  std::string _displayOCIO;
105  std::string _viewOCIO;
106  std::string _colorspaceOCIO;
107  std::string _looksOCIO;
108  int _lut3dSizeOCIO = 0;
109 
110  TfToken _aovName;
111  SdfPath _aovBufferPath;
112  HdRenderBuffer* _aovBuffer;
113  class HgiGLTexture* _aovTexture;
114  GLuint _aovFramebuffer;
115 };
116 
117 
123 {
125 
126  // Resolution of bound framebuffer we are color correcting.
127  // This must be set if the viewport and framebuffer do not match.
128  GfVec2i framebufferSize = GfVec2i(0);
129 
130  // Switch between HdColorCorrectionTokens.
131  // We default to 'disabled' to be backwards compatible with clients that are
132  // still running with sRGB buffers.
133  TfToken colorCorrectionMode = HdxColorCorrectionTokens->disabled;
134 
135  // 'display', 'view', 'colorspace' and 'look' are options the client may
136  // supply to configure OCIO. If one is not provided the default values
137  // is substituted. You can find the values for these strings inside the
138  // profile/config .ocio file. For example:
139  //
140  // displays:
141  // rec709g22:
142  // !<View> {name: studio, colorspace: linear, looks: studio_65_lg2}
143  //
144  std::string displayOCIO;
145  std::string viewOCIO;
146  std::string colorspaceOCIO;
147  std::string looksOCIO;
148 
149  // The width, height and depth used for the GPU LUT 3d texture.
150  // A value of 0 indicates we should use an appropriate default size.
151  int lut3dSizeOCIO = 0;
152 
153  // When no AOV is provided ColorCorrection will operate on the default FB
154  // color attachment.
155  TfToken aovName;
156  SdfPath aovBufferPath;
157 };
158 
159 // VtValue requirements
160 HDX_API
161 std::ostream& operator<<(std::ostream& out, const HdxColorCorrectionTaskParams& pv);
162 HDX_API
164  const HdxColorCorrectionTaskParams& rhs);
165 HDX_API
167  const HdxColorCorrectionTaskParams& rhs);
168 
169 
170 PXR_NAMESPACE_CLOSE_SCOPE
171 
172 #endif
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
A task for performing color correction (and optionally color grading) on a color buffer to transform ...
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
An instance of a glsl program.
Definition: glslProgram.h:44
virtual HDX_API void Execute(HdTaskContext *ctx) override
Execute the color correction task.
ColorCorrectionTask parameters.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
virtual HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
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
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
virtual HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
Represents a OpenGL GPU texture resource.
Definition: texture.h:38
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:51