-
Notifications
You must be signed in to change notification settings - Fork 59
/
render_pass.h
executable file
·154 lines (133 loc) · 5.99 KB
/
render_pass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2019 Luma Pictures
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Modifications Copyright 2022 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// @file render_pass.h
///
/// Utilities for handling Render Passes.
#pragma once
#include <pxr/pxr.h>
#include "api.h"
#include <pxr/base/gf/matrix4d.h>
#include <pxr/imaging/hd/renderPass.h>
#ifndef USD_DO_NOT_BLIT
#ifdef USD_HAS_FULLSCREEN_SHADER
#include <pxr/imaging/hdx/fullscreenShader.h>
#else
#include <pxr/imaging/hdx/compositor.h>
#endif
#endif
#include "render_buffer.h"
#include "render_delegate.h"
#include <ai.h>
PXR_NAMESPACE_OPEN_SCOPE
/// Utility class for handling Render Passes.
class HdArnoldRenderPass : public HdRenderPass {
public:
/// Constructor for HdArnoldRenderPass.
///
/// @param renderDelegate Pointer to the Render Delegate.
/// @param index Pointer to the Render Index.
/// @param collection RPrim Collection to bind for rendering.
HDARNOLD_API
HdArnoldRenderPass(
HdArnoldRenderDelegate* renderDelegate, HdRenderIndex* index, const HdRprimCollection& collection);
/// Destructor for HdArnoldRenderPass.
HDARNOLD_API
~HdArnoldRenderPass() override;
/// Returns true if the render has converged.
///
/// @return True if the render has converged.
bool IsConverged() const override { return _isConverged; }
protected:
/// Executing the Render Pass.
///
/// This function is continously executed, until IsConverged returns true.
///
/// @param renderPassState Pointer to the Hydra Render Pass State.
/// @param renderTags List of tags to render, currently unused.
HDARNOLD_API
void _Execute(const HdRenderPassStateSharedPtr& renderPassState, const TfTokenVector& renderTags) override;
/// Tells if the aov bindings has changed.
///
/// \param aovBindings Hydra AOV bindings from the render pass.
/// \return Returns true if the aov bindings are the same, false otherwise.
HDARNOLD_API
bool _RenderBuffersChanged(const HdRenderPassAovBindingVector& aovBindings);
/// Clears render buffers and destroys any assigned filter.
HDARNOLD_API
void _ClearRenderBuffers();
private:
HdArnoldRenderBufferStorage _renderBuffers; ///< Render buffer storage.
HdArnoldRenderBufferStorage _fallbackBuffers; ///< Render buffer storage if there are no aov bindings.
HdArnoldRenderBuffer _fallbackColor; ///< Color render buffer if there are no aov bindings.
HdArnoldRenderBuffer _fallbackDepth; ///< Depth render buffer if there are no aov bindings.
HdArnoldRenderBuffer _fallbackPrimId; ///< Prim ID buffer if there are no aov bindings.
AtArray* _fallbackOutputs; ///< AtArray storing the fallback outputs definitions.
AtArray* _fallbackAovShaders; ///< AtArray storing the fallback AOV shaders.
std::vector<AtNode*> _aovShaders; ///< Pointer to list of user aov shaders
HdArnoldRenderDelegate* _renderDelegate; ///< Pointer to the Render Delegate.
AtNode* _camera = nullptr; ///< Pointer to the Arnold Camera.
AtNode* _defaultFilter = nullptr; ///< Pointer to the default Arnold Filter.
AtNode* _closestFilter = nullptr; ///< Pointer to the closest Arnold Filter.
AtNode* _mainDriver = nullptr; ///< Pointer to the Arnold Driver writing color, position and depth.
AtNode* _primIdWriter = nullptr; ///< Pointer to the Arnold prim ID writer shader.
AtNode* _primIdReader = nullptr; ///< Pointer to the Arnold prim ID reader shader.
struct DeepRenderVar {
/// Definition for the output string.
AtString output;
/// Optional writer node for each AOV.
AtNode* writer = nullptr;
/// Optional reader node for each AOV.
AtNode* reader = nullptr;
};
// Each deep driver handles multiple AOVs.
struct DeepProduct {
/// List of the RenderVars.
std::vector<DeepRenderVar> renderVars;
/// Deep EXR driver.
AtNode* driver = nullptr;
/// Filter for the Deep EXR driver.
AtNode* filter = nullptr;
};
std::vector<DeepProduct> _deepProducts; ///< List of Deep Render Products.
#ifndef USD_DO_NOT_BLIT
#ifdef USD_HAS_FULLSCREEN_SHADER
HdxFullscreenShader _fullscreenShader; ///< Hydra utility to blit to OpenGL.
#else
HdxCompositor _compositor; ///< Hydra compositor to blit to OpenGL.
#endif
#endif
GfMatrix4d _viewMtx; ///< View matrix of the camera.
GfMatrix4d _projMtx; ///< Projection matrix of the camera.
int _width = 0; ///< Width of the render buffer.
int _height = 0; ///< Height of the render buffer.
// Window NDC region, that can be used for overscan, or to adjust the frustum
GfVec4f _windowNDC = GfVec4f(0.f, 0.f, 1.f, 1.f);
bool _isConverged = false; ///< State of the render convergence.
bool _usingFallbackBuffers = false; ///< If the render pass is using the fallback buffers.
};
PXR_NAMESPACE_CLOSE_SCOPE