renderPassState.h
1 //
2 // Copyright 2016 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 PXR_IMAGING_HD_RENDER_PASS_STATE_H
25 #define PXR_IMAGING_HD_RENDER_PASS_STATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/aov.h"
30 #include "pxr/imaging/hd/version.h"
31 #include "pxr/imaging/hd/enums.h"
32 
33 #include "pxr/imaging/cameraUtil/framing.h"
34 
35 #include "pxr/usd/sdf/path.h"
36 
37 #include "pxr/base/tf/token.h"
38 #include "pxr/base/vt/value.h"
39 #include "pxr/base/gf/matrix4d.h"
40 #include "pxr/base/gf/vec2f.h"
41 #include "pxr/base/gf/vec4d.h"
42 #include "pxr/base/gf/vec4f.h"
43 
44 #include <memory>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 
49 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
50 using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
51 
52 class HdCamera;
53 
61 {
62 public:
63  HD_API
65  HD_API
66  virtual ~HdRenderPassState();
67 
72  HD_API
73  virtual void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry);
74 
75  // ---------------------------------------------------------------------- //
77  // ---------------------------------------------------------------------- //
78 
79  using ClipPlanesVector = std::vector<GfVec4d>;
80 
90  HD_API
92  HdCamera const *camera,
93  CameraUtilFraming const &framing,
94  const std::pair<bool, CameraUtilConformWindowPolicy> &
95  overrideWindowPolicy);
96 
98  HdCamera const *
99  GetCamera() const { return _camera; }
100 
103  const CameraUtilFraming &
104  GetFraming() const { return _framing; }
105 
108  const std::pair<bool, CameraUtilConformWindowPolicy> &
109  GetOverrideWindowPolicy() const { return _overrideWindowPolicy; }
110 
114  HD_API
115  CameraUtilConformWindowPolicy
116  GetWindowPolicy() const;
117 
122  HD_API
123  void SetCameraAndViewport(HdCamera const *camera,
124  GfVec4d const& viewport);
129  HD_API
130  virtual GfMatrix4d GetWorldToViewMatrix() const;
131 
134  HD_API
135  virtual GfMatrix4d GetProjectionMatrix() const;
136 
140  GfVec4f const & GetViewport() const { return _viewport; }
141 
146  HD_API
148 
151  HD_API
152  virtual ClipPlanesVector const & GetClipPlanes() const;
153 
154  // ---------------------------------------------------------------------- //
156  // ---------------------------------------------------------------------- //
157 
160  HD_API
161  void SetOverrideColor(GfVec4f const &color);
162  const GfVec4f& GetOverrideColor() const { return _overrideColor; }
163 
166  HD_API
167  void SetWireframeColor(GfVec4f const &color);
168  const GfVec4f& GetWireframeColor() const { return _wireframeColor; }
169 
170  HD_API
171  void SetMaskColor(GfVec4f const &color);
172  const GfVec4f& GetMaskColor() const { return _maskColor; }
173 
174  HD_API
175  void SetIndicatorColor(GfVec4f const &color);
176  const GfVec4f& GetIndicatorColor() const { return _indicatorColor; }
177 
180  HD_API
181  void SetPointColor(GfVec4f const &color);
182  const GfVec4f& GetPointColor() const { return _pointColor; }
183 
185  HD_API
186  void SetPointSize(float size);
187  float GetPointSize() const { return _pointSize; }
188 
190  HD_API
191  void SetPointSelectedSize(float size);
192  float GetPointSelectedSize() const { return _pointSelectedSize; }
193 
195  HD_API
196  void SetLightingEnabled(bool enabled);
197  bool GetLightingEnabled() const { return _lightingEnabled; }
198 
199  HD_API
200  void SetClippingEnabled(bool enabled);
201  bool GetClippingEnabled() const { return _clippingEnabled; }
202 
203  // ---------------------------------------------------------------------- //
205  // ---------------------------------------------------------------------- //
206 
208  HD_API
209  void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings);
210  HD_API
211  HdRenderPassAovBindingVector const& GetAovBindings() const;
212 
214  HD_API
215  void SetAovInputBindings(HdRenderPassAovBindingVector const &aovBindings);
216  HD_API
217  HdRenderPassAovBindingVector const& GetAovInputBindings() const;
218 
221  HD_API
222  void SetUseAovMultiSample(bool state);
223  HD_API
224  bool GetUseAovMultiSample() const;
225 
226  HD_API
227  void SetCullStyle(HdCullStyle cullStyle);
228  HD_API
229  HdCullStyle GetCullStyle() const { return _cullStyle; }
230 
231  HD_API
232  void SetAlphaThreshold(float alphaThreshold);
233  float GetAlphaThreshold() const { return _alphaThreshold; }
234 
235  HD_API
236  void SetTessLevel(float level);
237  float GetTessLevel() const { return _tessLevel; }
238 
239  HD_API
240  void SetDrawingRange(GfVec2f const &drawRange);
241  GfVec2f GetDrawingRange() const { return _drawRange; } // in pixel
242  HD_API
243  GfVec2f GetDrawingRangeNDC() const; // in ndc
244 
245  HD_API
246  void SetDepthBiasUseDefault(bool useDefault);
247  bool GetDepthBiasUseDefault() const { return _depthBiasUseDefault; }
248 
249  HD_API
250  void SetDepthBiasEnabled(bool enabled);
251  bool GetDepthBiasEnabled() const { return _depthBiasEnabled; }
252 
253  HD_API
254  void SetDepthBias(float constantFactor, float slopeFactor);
255 
256  HD_API
257  void SetDepthFunc(HdCompareFunction depthFunc);
258  HdCompareFunction GetDepthFunc() const { return _depthFunc; }
259 
260  HD_API
261  void SetEnableDepthMask(bool state);
262  HD_API
263  bool GetEnableDepthMask() const;
264 
265  HD_API
266  void SetEnableDepthTest(bool enabled);
267  HD_API
268  bool GetEnableDepthTest() const;
269 
270  HD_API
271  void SetEnableDepthClamp(bool enabled);
272  HD_API
273  bool GetEnableDepthClamp() const;
274 
275  HD_API
276  void SetDepthRange(GfVec2f const &depthRange);
277  HD_API
278  const GfVec2f& GetDepthRange() const;
279 
280  HD_API
281  void SetStencil(HdCompareFunction func, int ref, int mask,
282  HdStencilOp fail, HdStencilOp zfail, HdStencilOp zpass);
283  HdCompareFunction GetStencilFunc() const { return _stencilFunc; }
284  int GetStencilRef() const { return _stencilRef; }
285  int GetStencilMask() const { return _stencilMask; }
286  HdStencilOp GetStencilFailOp() const { return _stencilFailOp; }
287  HdStencilOp GetStencilDepthFailOp() const { return _stencilZFailOp; }
288  HdStencilOp GetStencilDepthPassOp() const { return _stencilZPassOp; }
289  HD_API
290  void SetStencilEnabled(bool enabled);
291  HD_API
292  bool GetStencilEnabled() const;
293 
294  HD_API
295  void SetLineWidth(float width);
296  float GetLineWidth() const { return _lineWidth; }
297 
298  HD_API
299  void SetBlend(HdBlendOp colorOp,
300  HdBlendFactor colorSrcFactor,
301  HdBlendFactor colorDstFactor,
302  HdBlendOp alphaOp,
303  HdBlendFactor alphaSrcFactor,
304  HdBlendFactor alphaDstFactor);
305  HdBlendOp GetBlendColorOp() { return _blendColorOp; }
306  HdBlendFactor GetBlendColorSrcFactor() { return _blendColorSrcFactor; }
307  HdBlendFactor GetBlendColorDstFactor() { return _blendColorDstFactor; }
308  HdBlendOp GetBlendAlphaOp() { return _blendAlphaOp; }
309  HdBlendFactor GetBlendAlphaSrcFactor() { return _blendAlphaSrcFactor; }
310  HdBlendFactor GetBlendAlphaDstFactor() { return _blendAlphaDstFactor; }
311  HD_API
312  void SetBlendConstantColor(GfVec4f const & color);
313  const GfVec4f& GetBlendConstantColor() const { return _blendConstantColor; }
314  HD_API
315  void SetBlendEnabled(bool enabled);
316 
317  HD_API
318  void SetAlphaToCoverageEnabled(bool enabled);
319  bool GetAlphaToCoverageEnabled() const { return _alphaToCoverageEnabled; }
320 
321  HD_API
322  void SetColorMaskUseDefault(bool useDefault);
323  bool GetColorMaskUseDefault() const { return _colorMaskUseDefault;}
324 
325  HD_API
326  void SetConservativeRasterizationEnabled(bool enabled);
327  bool GetConservativeRasterizationEnabled() const {
328  return _conservativeRasterizationEnabled;
329  }
330 
331  HD_API
332  void SetVolumeRenderingConstants(float stepSize, float stepSizeLighting);
333 
334  enum ColorMask {
335  ColorMaskNone,
336  ColorMaskRGB,
337  ColorMaskRGBA
338  };
339 
340  HD_API
341  void SetColorMasks(std::vector<ColorMask> const& masks);
342  std::vector<ColorMask> const& GetColorMasks() const { return _colorMasks; }
343 
344  HD_API
345  void SetMultiSampleEnabled(bool enabled);
346  bool GetMultiSampleEnabled() const { return _multiSampleEnabled; }
347 
348 protected:
349  // ---------------------------------------------------------------------- //
350  // Camera and framing state
351  // ---------------------------------------------------------------------- //
352  HdCamera const *_camera;
353  GfVec4f _viewport;
354  CameraUtilFraming _framing;
355  std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
356 
357  // ---------------------------------------------------------------------- //
358  // Application rendering state
359  // ---------------------------------------------------------------------- //
360  GfVec4f _overrideColor;
361  GfVec4f _wireframeColor;
362  GfVec4f _pointColor;
363  float _pointSize;
364  bool _lightingEnabled;
365  bool _clippingEnabled;
366 
367  GfVec4f _maskColor;
368  GfVec4f _indicatorColor;
369  float _pointSelectedSize;
370 
371  // ---------------------------------------------------------------------- //
372  // Render pipeline state
373  // ---------------------------------------------------------------------- //
374  float _alphaThreshold;
375  float _tessLevel;
376  GfVec2f _drawRange;
377 
378  bool _depthBiasUseDefault; // inherit existing state, ignore values below.
379  bool _depthBiasEnabled;
380  float _depthBiasConstantFactor;
381  float _depthBiasSlopeFactor;
382  HdCompareFunction _depthFunc;
383  bool _depthMaskEnabled;
384  bool _depthTestEnabled;
385  bool _depthClampEnabled;
386  GfVec2f _depthRange;
387 
388  HdCullStyle _cullStyle;
389 
390  // Stencil RenderPassState
391  HdCompareFunction _stencilFunc;
392  int _stencilRef;
393  int _stencilMask;
394  HdStencilOp _stencilFailOp;
395  HdStencilOp _stencilZFailOp;
396  HdStencilOp _stencilZPassOp;
397  bool _stencilEnabled;
398 
399  // Line width
400  float _lineWidth;
401 
402  // Blending
403  HdBlendOp _blendColorOp;
404  HdBlendFactor _blendColorSrcFactor;
405  HdBlendFactor _blendColorDstFactor;
406  HdBlendOp _blendAlphaOp;
407  HdBlendFactor _blendAlphaSrcFactor;
408  HdBlendFactor _blendAlphaDstFactor;
409  GfVec4f _blendConstantColor;
410  bool _blendEnabled;
411 
412  // alpha to coverage
413  bool _alphaToCoverageEnabled;
414 
415  bool _colorMaskUseDefault;
416  std::vector<ColorMask> _colorMasks;
417 
418  HdRenderPassAovBindingVector _aovBindings;
419  HdRenderPassAovBindingVector _aovInputBindings;
420  bool _useMultiSampleAov;
421 
422  bool _conservativeRasterizationEnabled;
423 
424  float _stepSize;
425  float _stepSizeLighting;
426 
427  bool _multiSampleEnabled;
428 };
429 
430 PXR_NAMESPACE_CLOSE_SCOPE
431 
432 #endif // PXR_IMAGING_HD_RENDER_PASS_STATE_H
HD_API void SetUseAovMultiSample(bool state)
Returns true if the render pass wants to render into the multi-sample aovs.
const CameraUtilFraming & GetFraming() const
Get framing information determining how the filmback plane maps to pixels.
HD_API void SetOverrideColor(GfVec4f const &color)
Set an override color for rendering where the R, G and B components are the color and the alpha compo...
const std::pair< bool, CameraUtilConformWindowPolicy > & GetOverrideWindowPolicy() const
The override value for the window policy to conform the camera frustum that can be specified by the a...
HD_API void SetLightingEnabled(bool enabled)
XXX: Hacky way of disabling lighting.
HD_API void SetCameraAndFraming(HdCamera const *camera, CameraUtilFraming const &framing, const std::pair< bool, CameraUtilConformWindowPolicy > &overrideWindowPolicy)
Camera setter API.
HD_API CameraUtilConformWindowPolicy GetWindowPolicy() const
The resolved window policy to conform the camera frustum.
HD_API void SetWireframeColor(GfVec4f const &color)
Set a wireframe color for rendering where the R, G and B components are the color and the alpha compo...
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition: camera.h:79
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
A set of rendering parameters used among render passes.
HD_API void SetPointSize(float size)
Set the point size for unselected points.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
GfVec4f const & GetViewport() const
Only use when clients did not specify a camera framing.
virtual HD_API ClipPlanesVector const & GetClipPlanes() const
Returns HdCamera's clip planes.
HdCamera const * GetCamera() const
Get camera.
HD_API void SetPointSelectedSize(float size)
Set the point size for selected points.
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
HD_API void SetAovInputBindings(HdRenderPassAovBindingVector const &aovBindings)
Set the AOVs that this renderpass needs to read from.
virtual HD_API GfMatrix4d GetWorldToViewMatrix() const
Camera getter API.
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
HD_API void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings)
Set the attachments for this renderpass to render into.
HD_API void SetPointColor(GfVec4f const &color)
Set a point color for rendering where the R, G and B components are the color and the alpha component...
HD_API GfMatrix4d GetImageToWorldMatrix() const
Compute a transform from window relative coordinates (x,y,z,1) to homogeneous world coordinates (x,...
HD_API void SetCameraAndViewport(HdCamera const *camera, GfVec4d const &viewport)
Camera setter API The view, projection and clipping plane info of the camera will be used.
virtual HD_API GfMatrix4d GetProjectionMatrix() const
Compute projection matrix using physical attributes of an HdCamera.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
virtual HD_API void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry)
Schedule to update renderPassState parameters.
Framing information.
Definition: framing.h:79