add usd-21-05-win64_py37

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:16:25 +01:00
1 parent 41d23e71ba
commit 66bc054336
15675 files changed
+3061008

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_AOV_INPUT_TASK_H
#define PXR_IMAGING_HDX_AOV_INPUT_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hgi/texture.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxAovInputTask
///
/// A task for taking input AOV data comming from a render buffer that was
/// filled by render tasks and converting it to a HgiTexture.
/// The aov render buffer can be a GPU or CPU buffer, while the resulting output
/// HgiTexture will always be a GPU texture.
///
/// The HgiTexture is placed in the shared task context so that following tasks
/// maybe operate on this HgiTexture without having to worry about converting
/// the aov data from CPU to GPU.
///
class HdxAovInputTask : public HdxTask
{
public:
HDX_API
HdxAovInputTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxAovInputTask() override;
/// Hooks for progressive rendering.
bool IsConverged() const override;
HDX_API
void Prepare(
HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
HDX_API
void _Sync(
HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
void _UpdateTexture(
HdTaskContext* ctx,
HgiTextureHandle& texture,
HdRenderBuffer* buffer);
void _UpdateIntermediateTexture(
HgiTextureHandle& texture,
HdRenderBuffer* buffer);
bool _converged;
SdfPath _aovBufferPath;
SdfPath _depthBufferPath;
HdRenderBuffer* _aovBuffer;
HdRenderBuffer* _depthBuffer;
HgiTextureHandle _aovTexture;
HgiTextureHandle _depthTexture;
HgiTextureHandle _aovTextureIntermediate;
HdxAovInputTask() = delete;
HdxAovInputTask(const HdxAovInputTask &) = delete;
HdxAovInputTask &operator =(const HdxAovInputTask &) = delete;
};
/// \class HdxAovInputTaskParams
///
/// AovInput parameters.
///
struct HdxAovInputTaskParams
{
HdxAovInputTaskParams()
: aovBufferPath()
, depthBufferPath()
{}
SdfPath aovBufferPath;
SdfPath depthBufferPath;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxAovInputTaskParams& pv);
HDX_API
bool operator==(const HdxAovInputTaskParams& lhs,
const HdxAovInputTaskParams& rhs);
HDX_API
bool operator!=(const HdxAovInputTaskParams& lhs,
const HdxAovInputTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_API_H
#define PXR_IMAGING_HDX_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define HDX_API
# define HDX_API_TEMPLATE_CLASS(...)
# define HDX_API_TEMPLATE_STRUCT(...)
# define HDX_LOCAL
#else
# if defined(HDX_EXPORTS)
# define HDX_API ARCH_EXPORT
# define HDX_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define HDX_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define HDX_API ARCH_IMPORT
# define HDX_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define HDX_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define HDX_LOCAL ARCH_HIDDEN
#endif
#endif // PXR_IMAGING_HDX_API_H
+125
View File
@@ -0,0 +1,125 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef HDX_COLORCHANNEL_TASK_H
#define HDX_COLORCHANNEL_TASK_H
#include "pxr/pxr.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hdx/tokens.h"
#include "pxr/imaging/hgi/graphicsCmds.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxColorChannelTask
///
/// A task for choosing a color channel for display.
///
class HdxColorChannelTask : public HdxTask
{
public:
HDX_API
HdxColorChannelTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxColorChannelTask() override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute the color channel task
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
HdxColorChannelTask() = delete;
HdxColorChannelTask(const HdxColorChannelTask &) = delete;
HdxColorChannelTask &operator =(const HdxColorChannelTask &) = delete;
// Utility function to update the shader uniform parameters.
// Returns true if the values were updated. False if unchanged.
bool _UpdateParameterBuffer(float screenSizeX, float screenSizeY);
/// Apply the color channel filtering.
void _ApplyColorChannel();
// This struct must match ParameterBuffer in colorChannel.glslfx.
// Be careful to remember the std430 rules.
struct _ParameterBuffer
{
float screenSize[2];
int channel;
bool operator==(const _ParameterBuffer& other) const {
return channel == other.channel &&
screenSize[0] == other.screenSize[0] &&
screenSize[1] == other.screenSize[1];
}
};
std::unique_ptr<class HdxFullscreenShader> _compositor;
_ParameterBuffer _parameterData;
// The color channel to be rendered (see HdxColorChannelTokens for the
// possible values).
TfToken _channel;
};
/// \class HdxColorChannelTaskParams
///
/// ColorChannelTask parameters.
///
struct HdxColorChannelTaskParams
{
HdxColorChannelTaskParams() {}
// Specifies which output color channel should be drawn. Defaults to 'color'
// (untouched RGBA).
TfToken channel = HdxColorChannelTokens->color;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxColorChannelTaskParams& pv);
HDX_API
bool operator==(const HdxColorChannelTaskParams& lhs,
const HdxColorChannelTaskParams& rhs);
HDX_API
bool operator!=(const HdxColorChannelTaskParams& lhs,
const HdxColorChannelTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,182 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef HDX_COLORCORRECTION_TASK_H
#define HDX_COLORCORRECTION_TASK_H
#include "pxr/pxr.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hdx/tokens.h"
#include "pxr/imaging/hgi/attachmentDesc.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/graphicsPipeline.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/shaderProgram.h"
#include "pxr/imaging/hgi/texture.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxColorCorrectionTask
///
/// A task for performing color correction (and optionally color grading) on a
/// color buffer to transform its color for display.
///
class HdxColorCorrectionTask : public HdxTask
{
public:
HDX_API
HdxColorCorrectionTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxColorCorrectionTask() override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute the color correction task
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
HdxColorCorrectionTask() = delete;
HdxColorCorrectionTask(const HdxColorCorrectionTask &) = delete;
HdxColorCorrectionTask &operator =(const HdxColorCorrectionTask &) = delete;
// Utility to create OCIO resources and returns the OCIO shadercode
std::string _CreateOpenColorIOResources();
// Utility to check if OCIO should be used
bool _GetUseOcio() const;
// Utility function to create the GL program for color correction
bool _CreateShaderResources();
// Utility function to create buffer resources.
bool _CreateBufferResources();
// Utility to create resource bindings
bool _CreateResourceBindings(HgiTextureHandle const& aovTexture);
// Utility to create a pipeline
bool _CreatePipeline(HgiTextureHandle const& aovTexture);
// Utility to create a texture sampler
bool _CreateSampler();
// Apply color correction to the currently bound framebuffer.
void _ApplyColorCorrection(HgiTextureHandle const& aovTexture);
// Destroy shader program and the shader functions it holds.
void _DestroyShaderProgram();
// Print shader compile errors.
void _PrintCompileErrors();
HgiAttachmentDesc _attachment0;
HgiBufferHandle _indexBuffer;
HgiBufferHandle _vertexBuffer;
HgiTextureHandle _texture3dLUT;
HgiSamplerHandle _sampler;
HgiShaderProgramHandle _shaderProgram;
HgiResourceBindingsHandle _resourceBindings;
HgiGraphicsPipelineHandle _pipeline;
TfToken _colorCorrectionMode;
std::string _displayOCIO;
std::string _viewOCIO;
std::string _colorspaceOCIO;
std::string _looksOCIO;
int _lut3dSizeOCIO;
float _screenSize[2];
TfToken _aovName;
};
/// \class HdxColorCorrectionTaskParams
///
/// ColorCorrectionTask parameters.
///
/// `lut3dSizeOCIO`: We default to 65 (0-64) samples which works well with
// OCIO resampling.
///
struct HdxColorCorrectionTaskParams
{
HDX_API
HdxColorCorrectionTaskParams();
// Switch between HdColorCorrectionTokens.
// We default to 'disabled' to be backwards compatible with clients that are
// still running with sRGB buffers.
TfToken colorCorrectionMode;
// 'display', 'view', 'colorspace' and 'look' are options the client may
// supply to configure OCIO. If one is not provided the default values
// is substituted. You can find the values for these strings inside the
// profile/config .ocio file. For example:
//
// displays:
// rec709g22:
// !<View> {name: studio, colorspace: linear, looks: studio_65_lg2}
//
std::string displayOCIO;
std::string viewOCIO;
std::string colorspaceOCIO;
std::string looksOCIO;
// The width, height and depth used for the GPU LUT 3d texture.
int lut3dSizeOCIO;
// The name of the aov to color correct
TfToken aovName;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxColorCorrectionTaskParams& pv);
HDX_API
bool operator==(const HdxColorCorrectionTaskParams& lhs,
const HdxColorCorrectionTaskParams& rhs);
HDX_API
bool operator!=(const HdxColorCorrectionTaskParams& lhs,
const HdxColorCorrectionTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,172 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
#define PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
#include "pxr/pxr.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hgi/texture.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxColorizeSelectionTaskParams
///
/// Input parameters for HdxColorizeSelectionTask
///
struct HdxColorizeSelectionTaskParams
{
HdxColorizeSelectionTaskParams()
: enableSelection(false)
, selectionColor(0)
, locateColor(0)
, enableOutline(false)
, outlineRadius(5)
, primIdBufferPath()
, instanceIdBufferPath()
, elementIdBufferPath()
{}
bool enableSelection;
GfVec4f selectionColor;
GfVec4f locateColor;
bool enableOutline;
unsigned int outlineRadius;
SdfPath primIdBufferPath;
SdfPath instanceIdBufferPath;
SdfPath elementIdBufferPath;
};
/// \class HdxColorizeSelectionTask
///
/// A task for taking ID buffer data and turning it into a "selection overlay"
/// that can be composited on top of hydra's color output.
///
/// If enableOutline is true then instead of overlaying the ID buffer as is, an
/// outline with thickness of outlineRadius pixels around the areas with IDs
/// will be overlaid. Otherwise, the ID buffer will be overlaid as is.
class HdxColorizeSelectionTask : public HdxTask
{
public:
HDX_API
HdxColorizeSelectionTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxColorizeSelectionTask() override;
/// Hooks for progressive rendering.
bool IsConverged() const override;
/// Prepare the render pass resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute the task
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
// The core colorizing logic of this task: given the ID buffers and the
// selection buffer, produce a color output at each pixel.
void _ColorizeSelection();
GfVec4f _GetColorForMode(int mode) const;
// Utility function to update the shader uniform parameters.
// Returns true if the values were updated. False if unchanged.
bool _UpdateParameterBuffer();
// Create a new GPU texture for the provided format and pixel data.
// If an old texture exists it will be destroyed first.
void _CreateTexture(
int width,
int height,
HdFormat format,
void *data);
// This struct must match ParameterBuffer in outline.glslfx.
// Be careful to remember the std430 rules.
struct _ParameterBuffer
{
// Size of a colorIn texel - to iterate adjacent texels.
GfVec2f texelSize;
// Draws outline when enabled, or color overlay when disabled.
int enableOutline = 0;
// The outline radius (thickness).
int radius = 5;
bool operator==(const _ParameterBuffer& other) const {
return texelSize == other.texelSize &&
enableOutline == other.enableOutline &&
radius == other.radius;
}
};
// Incoming data
HdxColorizeSelectionTaskParams _params;
int _lastVersion;
bool _hasSelection;
VtIntArray _selectionOffsets;
HdRenderBuffer *_primId;
HdRenderBuffer *_instanceId;
HdRenderBuffer *_elementId;
uint8_t *_outputBuffer;
size_t _outputBufferSize;
bool _converged;
std::unique_ptr<class HdxFullscreenShader> _compositor;
_ParameterBuffer _parameterData;
HgiTextureHandle _texture;
bool _pipelineCreated;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out,
const HdxColorizeSelectionTaskParams& pv);
HDX_API
bool operator==(const HdxColorizeSelectionTaskParams& lhs,
const HdxColorizeSelectionTaskParams& rhs);
HDX_API
bool operator!=(const HdxColorizeSelectionTaskParams& lhs,
const HdxColorizeSelectionTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_COLORIZE_SELECTION_TASK_H
+191
View File
@@ -0,0 +1,191 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
#define PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/tf/declarePtrs.h"
PXR_NAMESPACE_OPEN_SCOPE
class HdStDrawTarget;
class HdStDrawTargetRenderPassState;
using HdStRenderPassStateSharedPtr
= std::shared_ptr<class HdStRenderPassState>;
using HdStSimpleLightingShaderSharedPtr
= std::shared_ptr<class HdStSimpleLightingShader>;
TF_DECLARE_REF_PTRS(GlfSimpleLightingContext);
// Not strictly necessary here.
// But without it, would require users of the class to include it anyway
class HdxDrawTargetTask : public HdTask
{
public:
HDX_API
HdxDrawTargetTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxDrawTargetTask() override;
/// Sync the render pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
/// Collect Render Tags used by the task.
HDX_API
const TfTokenVector &GetRenderTags() const override;
private:
struct _RenderPassInfo;
struct _CameraInfo;
using _RenderPassInfoVector = std::vector<_RenderPassInfo>;
static _RenderPassInfoVector _ComputeRenderPassInfos(
HdRenderIndex * renderIndex);
static _CameraInfo _ComputeCameraInfo(
const HdRenderIndex &renderIndex,
const HdStDrawTarget * drawTarget);
static void _UpdateLightingContext(
const _CameraInfo &cameraInfo,
GlfSimpleLightingContextConstRefPtr const &srcContext,
GlfSimpleLightingContextRefPtr const &ctx);
void _UpdateRenderPassState(
const HdRenderIndex &renderIndex,
const _CameraInfo &cameraInfo,
HdStSimpleLightingShaderSharedPtr const &lightingShader,
const HdStDrawTargetRenderPassState *srcState,
HdStRenderPassStateSharedPtr const &state) const;
static void _UpdateRenderPass(
_RenderPassInfo *info);
unsigned _currentDrawTargetSetVersion;
_RenderPassInfoVector _renderPassesInfo;
// Raster State - close match to render task
// but doesn't have enableHardwareShading
// as that has to be enabled for draw targets.
// typedef std::vector<GfVec4d> ClipPlanesVector;
// ClipPlanesVector _clipPlanes;
GfVec4f _overrideColor;
GfVec4f _wireframeColor;
bool _enableLighting;
float _alphaThreshold;
/// Polygon Offset State
bool _depthBiasUseDefault;
bool _depthBiasEnable;
float _depthBiasConstantFactor;
float _depthBiasSlopeFactor;
HdCompareFunction _depthFunc;
// Viewer's Render Style
HdCullStyle _cullStyle;
// Alpha sample alpha to coverage
bool _enableSampleAlphaToCoverage;
TfTokenVector _renderTags;
HdxDrawTargetTask() = delete;
HdxDrawTargetTask(const HdxDrawTargetTask &) = delete;
HdxDrawTargetTask &operator =(const HdxDrawTargetTask &) = delete;
};
struct HdxDrawTargetTaskParams
{
HdxDrawTargetTaskParams()
: overrideColor(0.0)
, wireframeColor(0.0)
, enableLighting(false)
, alphaThreshold(0.0)
, depthBiasUseDefault(true)
, depthBiasEnable(false)
, depthBiasConstantFactor(0.0f)
, depthBiasSlopeFactor(1.0f)
, depthFunc(HdCmpFuncLEqual)
// XXX: When rendering draw targets we need alpha to coverage
// at least until we support a transparency pass
, enableAlphaToCoverage(true)
, cullStyle(HdCullStyleBackUnlessDoubleSided)
{}
// ClipPlanesVector clipPlanes;
GfVec4f overrideColor;
GfVec4f wireframeColor;
bool enableLighting;
float alphaThreshold;
// Depth Bias Raster State
// When use default is true - state
// is inherited and onther values are
// ignored. Otherwise the raster state
// is set using the values specified.
bool depthBiasUseDefault;
bool depthBiasEnable;
float depthBiasConstantFactor;
float depthBiasSlopeFactor;
HdCompareFunction depthFunc;
bool enableAlphaToCoverage;
// Viewer's Render Style
HdCullStyle cullStyle;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxDrawTargetTaskParams& pv);
HDX_API
bool operator==(
const HdxDrawTargetTaskParams& lhs,
const HdxDrawTargetTaskParams& rhs);
HDX_API
bool operator!=(
const HdxDrawTargetTaskParams& lhs,
const HdxDrawTargetTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
@@ -0,0 +1,99 @@
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_FREE_CAMERA_SCENE_DELEGATE_H
#define PXR_IMAGING_HDX_FREE_CAMERA_SCENE_DELEGATE_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hd/sceneDelegate.h"
#include "pxr/base/gf/camera.h"
#include "pxr/imaging/cameraUtil/conformWindow.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxFreeCameraSceneDelegate
///
/// A simple scene delegate adding a camera prim to the given
/// render index.
///
class HdxFreeCameraSceneDelegate : public HdSceneDelegate
{
public:
/// Constructs delegate and adds camera to render index if
/// cameras are supported by render delegate.
HDX_API
HdxFreeCameraSceneDelegate(HdRenderIndex *renderIndex,
SdfPath const &delegateId);
HDX_API
~HdxFreeCameraSceneDelegate() override;
/// Path of added camera (in render index). Empty if cameras are not
/// supported by render delegate.
const SdfPath &GetCameraId() const {
return _cameraId;
}
/// Set state of camera from GfCamera.
HDX_API
void SetCamera(const GfCamera &camera);
/// Set window policy of camera.
HDX_API
void SetWindowPolicy(CameraUtilConformWindowPolicy policy);
/// For transition, set camera state from OpenGL-style
/// view and projection matrix. GfCamera is preferred.
HDX_API
void SetMatrices(GfMatrix4d const &viewMatrix,
GfMatrix4d const &projMatrix);
/// For transition, set clip planes for camera. GfCamera is preferred.
HDX_API
void SetClipPlanes(std::vector<GfVec4f> const &clipPlanes);
// HdSceneDelegate interface
HDX_API
GfMatrix4d GetTransform(SdfPath const &id) override;
HDX_API
VtValue GetCameraParamValue(SdfPath const &id,
TfToken const &key) override;
private:
// Mark camera dirty in render index.
void _MarkDirty(HdDirtyBits bits);
// Path of camera in render index.
const SdfPath _cameraId;
// State of camera
GfCamera _camera;
// Window policy of camera.
CameraUtilConformWindowPolicy _policy;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_FREE_CAMERA_SCENE_DELEGATE_H
+206
View File
@@ -0,0 +1,206 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_FULLSCREENSHADER_H
#define PXR_IMAGING_HDX_FULLSCREENSHADER_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hd/types.h"
#include "pxr/base/gf/vec2i.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/graphicsPipeline.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/shaderProgram.h"
#include "pxr/imaging/hgi/texture.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class Hgi;
/// \class HdxFullscreenShader
///
/// This class is a utility for rendering deep raytracer or aov output
/// (color/depth) to a hgi texture. This lets callers composite results
/// into existing scenes.
///
class HdxFullscreenShader
{
public:
/// Create a new fullscreen shader object.
/// 'debugName' is assigned to the fullscreen pass as gpu debug group that
/// is helpful when inspecting the frame on a gpu debugger.
HDX_API
HdxFullscreenShader(Hgi* hgi, std::string const& debugName);
/// Destroy the fullscreen shader object, releasing GPU resources.
HDX_API
~HdxFullscreenShader();
/// Set the program for the class to use for its fragment shader.
/// The vertex shader is always hdx/shaders/fullscreen.glslfx,
/// "FullScreenVertex", which draws a full-screen triangle.
/// The fragment shader should expect a varying called "uv", and
/// whatever textures or uniforms have been passed in by the caller.
/// \param glslfx The name of the glslfx file where the fragment shader
/// is located.
/// \param shaderName The (technique) name of the fragment shader.
/// \param vertDesc Describes inputs, outputs and stage of vertex shader.
/// \param fragDesc Describes inputs, outputs and stage of fragment shader.
HDX_API
void SetProgram(
TfToken const& glslfx,
TfToken const& shaderName,
HgiShaderFunctionDesc &fragDesc,
HgiShaderFunctionDesc vertDesc = GetFullScreenVertexDesc()
);
/// Bind a (externally managed) buffer to the shader program.
/// This function can be used to bind buffers to a custom shader program.
/// The lifetime of the buffer is managed by the caller. HdxFullscreenShader
/// does not take ownership. To update values in the buffer, the client can
/// use a blitCmds to copy new data into their buffer.
/// If an invalid 'buffer' is passed, the binding will be cleared.
HDX_API
void BindBuffer(HgiBufferHandle const& buffer, uint32_t bindingIndex);
/// Bind (externally managed) textures to the shader program.
/// This function can be used to bind textures to a custom shader program.
/// The lifetime of textures is managed by the caller. HdxFullscreenShader
/// does not take ownership.
/// If an invalid 'texture' is passed, the binding will be cleared.
HDX_API
void BindTextures(
TfTokenVector const& names,
HgiTextureHandleVector const& textures);
/// By default HdxFullscreenShader creates a pipeline object that enables
/// depth testing and enables depth write if there is a depth texture.
/// This function allows you to override the depth and stencil state.
HDX_API
void SetDepthState(HgiDepthStencilState const& state);
/// By default HdxFullscreenShader uses no blending (opaque).
/// This function allows you to override blend state (e.g. alpha blending)
HDX_API
void SetBlendState(
bool enableBlending,
HgiBlendFactor srcColorBlendFactor,
HgiBlendFactor dstColorBlendFactor,
HgiBlendOp colorBlendOp,
HgiBlendFactor srcAlphaBlendFactor,
HgiBlendFactor dstAlphaBlendFactor,
HgiBlendOp alphaBlendOp);
/// Provide the shader constant values (uniforms).
/// The data values are copied, so you do not have to set them
/// each frame if they do not change in value.
HDX_API
void SetShaderConstants(
uint32_t byteSize,
const void* data);
/// Draw the internal textures to the provided destination textures.
/// `depth` is optional.
HDX_API
void Draw(HgiTextureHandle const& colorDst,
HgiTextureHandle const& depthDst);
private:
HdxFullscreenShader() = delete;
using TextureMap = std::map<TfToken, HgiTextureHandle>;
using BufferMap = std::map<uint32_t, HgiBufferHandle>;
// Utility function to create buffer resources.
void _CreateBufferResources();
// Destroy shader program and the shader functions it holds.
void _DestroyShaderProgram();
// Utility to create resource bindings
bool _CreateResourceBindings(TextureMap const& textures);
// Utility to create default vertex buffer descriptor
void _CreateVertexBufferDescriptor();
// Utility to create a pipeline
bool _CreatePipeline(
HgiTextureHandle const& colorDst,
HgiTextureHandle const& depthDst,
bool depthWrite);
// Utility to create a texture sampler
bool _CreateSampler();
// Internal draw method
void _Draw(TextureMap const& textures,
HgiTextureHandle const& colorDst,
HgiTextureHandle const& depthDst,
bool depthWrite);
static HgiShaderFunctionDesc GetFullScreenVertexDesc();
// Print shader compile errors.
void _PrintCompileErrors();
class Hgi* _hgi;
std::string _debugName;
TextureMap _textures;
BufferMap _buffers;
TfToken _glslfx;
TfToken _shaderName;
HgiBufferHandle _indexBuffer;
HgiBufferHandle _vertexBuffer;
HgiShaderProgramHandle _shaderProgram;
HgiResourceBindingsHandle _resourceBindings;
HgiGraphicsPipelineHandle _pipeline;
HgiSamplerHandle _sampler;
HgiVertexBufferDesc _vboDesc;
HgiDepthStencilState _depthState;
bool _blendingEnabled;
HgiBlendFactor _srcColorBlendFactor;
HgiBlendFactor _dstColorBlendFactor;
HgiBlendOp _colorBlendOp;
HgiBlendFactor _srcAlphaBlendFactor;
HgiBlendFactor _dstAlphaBlendFactor;
HgiBlendOp _alphaBlendOp;
HgiAttachmentDesc _attachment0;
HgiAttachmentDesc _depthAttachment;
std::vector<uint8_t> _constantsData;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_FULLSCREENSHADER_H
+52
View File
@@ -0,0 +1,52 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_HGI_CONVERSIONS_H
#define PXR_IMAGING_HDX_HGI_CONVERSIONS_H
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hd/types.h"
#include "pxr/imaging/hgi/types.h"
PXR_NAMESPACE_OPEN_SCOPE
///
/// \class HdxHgiConversions
///
/// Converts from Hd types to Hgi types
///
class HdxHgiConversions
{
public:
HDX_API
static HgiFormat GetHgiFormat(HdFormat hdFormat);
HDX_API
static HdFormat GetHdFormat(HgiFormat hgiFormat);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,73 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_OIT_BUFFER_ACCESSOR_H
#define PXR_IMAGING_HDX_OIT_BUFFER_ACCESSOR_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/task.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
using HdBufferArrayRangeSharedPtr =
std::shared_ptr<class HdBufferArrayRange>;
using HdStRenderPassShaderSharedPtr =
std::shared_ptr<class HdStRenderPassShader>;
/// Class for OIT render tasks to access the OIT buffers.
class HdxOitBufferAccessor {
public:
static bool IsOitEnabled();
HDX_API
HdxOitBufferAccessor(HdTaskContext *ctx);
/// Called during Prepare to indicate that OIT buffers are needed.
HDX_API
void RequestOitBuffers();
/// Called during Excecute before writing to OIT buffers.
HDX_API
void InitializeOitBuffersIfNecessary();
/// Called during Execute to add necessary OIT buffer shader bindings.
///
/// Returns false if the OIT buffers were not allocated.
HDX_API
bool AddOitBufferBindings(const HdStRenderPassShaderSharedPtr &);
private:
HdBufferArrayRangeSharedPtr const &_GetBar(const TfToken &);
HdTaskContext * const _ctx;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+81
View File
@@ -0,0 +1,81 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_OIT_RENDER_TASK_H
#define PXR_IMAGING_HDX_OIT_RENDER_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hdx/renderTask.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
using HdStRenderPassShaderSharedPtr = std::shared_ptr<HdStRenderPassShader>;
/// \class HdxOitRenderTask
///
/// A task for rendering transparent geometry into OIT buffers.
/// Its companion task, OITResolveTask, will blend the buffers to screen.
///
class HdxOitRenderTask : public HdxRenderTask
{
public:
HDX_API
HdxOitRenderTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxOitRenderTask() override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
HdxOitRenderTask() = delete;
HdxOitRenderTask(const HdxOitRenderTask &) = delete;
HdxOitRenderTask &operator =(const HdxOitRenderTask &) = delete;
HdStRenderPassShaderSharedPtr _oitTranslucentRenderPassShader;
HdStRenderPassShaderSharedPtr _oitOpaqueRenderPassShader;
const bool _isOitEnabled;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_OIT_RENDER_TASK_H
+113
View File
@@ -0,0 +1,113 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_OIT_RESOLVE_TASK_H
#define PXR_IMAGING_HDX_OIT_RESOLVE_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/task.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HdSceneDelegate;
using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
using HdStRenderPassShaderSharedPtr =
std::shared_ptr<class HdStRenderPassShader>;
/// \class HdxOitResolveTask
///
/// A task for resolving previous passes to pixels.
///
/// It is also responsible for allocating the OIT buffers, but it
/// leaves the clearing of the OIT buffers to the OIT render tasks.
/// OIT render tasks coordinate with the resolve task through
/// HdxOitResolveTask::OitBufferAccessor.
///
class HdxOitResolveTask : public HdTask
{
public:
HDX_API
static bool IsOitEnabled();
HDX_API
HdxOitResolveTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxOitResolveTask() override;
/// Sync the resolve pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the tasks resources
///
/// Allocates OIT buffers if requested by OIT render task
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
///
/// Resolves OIT buffers
HDX_API
void Execute(HdTaskContext* ctx) override;
private:
HdxOitResolveTask() = delete;
HdxOitResolveTask(const HdxOitResolveTask &) = delete;
HdxOitResolveTask &operator =(const HdxOitResolveTask &) = delete;
void _PrepareOitBuffers(
HdTaskContext* ctx,
HdRenderIndex* renderIndex,
GfVec2i const& screenSize);
void _PrepareAovBindings(
HdTaskContext* ctx,
HdRenderIndex* renderIndex);
HdRenderPassSharedPtr _renderPass;
HdStRenderPassStateSharedPtr _renderPassState;
HdStRenderPassShaderSharedPtr _renderPassShader;
GfVec2i _screenSize;
HdBufferArrayRangeSharedPtr _counterBar;
HdBufferArrayRangeSharedPtr _dataBar;
HdBufferArrayRangeSharedPtr _depthBar;
HdBufferArrayRangeSharedPtr _indexBar;
HdBufferArrayRangeSharedPtr _uniformBar;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,78 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_OIT_VOLUME_RENDER_TASK_H
#define PXR_IMAGING_HDX_OIT_VOLUME_RENDER_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hdx/renderTask.h"
#include "pxr/imaging/hdSt/renderPassState.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxOitVolumeRenderTask
///
/// A task for rendering transparent geometry into OIT buffers.
/// Its companion task, OITResolveTask, will blend the buffers to screen.
///
class HdxOitVolumeRenderTask : public HdxRenderTask
{
public:
HDX_API
HdxOitVolumeRenderTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxOitVolumeRenderTask() override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
HdxOitVolumeRenderTask() = delete;
HdxOitVolumeRenderTask(const HdxOitVolumeRenderTask &) = delete;
HdxOitVolumeRenderTask &operator =(const HdxOitVolumeRenderTask &) = delete;
HdStRenderPassShaderSharedPtr _oitVolumeRenderPassShader;
const bool _isOitEnabled;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_OIT_VOLUME_RENDER_TASK_H
+54
View File
@@ -0,0 +1,54 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_PACKAGE_H
#define PXR_IMAGING_HDX_PACKAGE_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/base/tf/token.h"
PXR_NAMESPACE_OPEN_SCOPE
TfToken HdxPackageFullscreenShader();
TfToken HdxPackageRenderPassColorShader();
TfToken HdxPackageRenderPassColorAndSelectionShader();
TfToken HdxPackageRenderPassColorWithOccludedSelectionShader();
TfToken HdxPackageRenderPassIdShader();
TfToken HdxPackageRenderPassPickingShader();
TfToken HdxPackageRenderPassShadowShader();
TfToken HdxPackageColorChannelShader();
TfToken HdxPackageColorCorrectionShader();
TfToken HdxPackageVisualizeAovShader();
TfToken HdxPackageRenderPassOitShader();
TfToken HdxPackageRenderPassOitOpaqueShader();
TfToken HdxPackageRenderPassOitVolumeShader();
TfToken HdxPackageOitResolveImageShader();
TfToken HdxPackageOutlineShader();
TfToken HdxPackageDefaultDomeLightTexture();
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,143 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_PICK_FROM_RENDER_BUFFER_TASK_H
#define PXR_IMAGING_HDX_PICK_FROM_RENDER_BUFFER_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hd/camera.h"
#include "pxr/imaging/hd/renderBuffer.h"
#include "pxr/imaging/hdx/pickTask.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Pick task params. This is augmented by HdxPickTaskContextParams, which is
/// passed in on the task context.
struct HdxPickFromRenderBufferTaskParams
{
HdxPickFromRenderBufferTaskParams()
: primIdBufferPath()
, instanceIdBufferPath()
, elementIdBufferPath()
, normalBufferPath()
, depthBufferPath()
, cameraId()
, overrideWindowPolicy{false, CameraUtilFit}
, viewport()
{}
SdfPath primIdBufferPath;
SdfPath instanceIdBufferPath;
SdfPath elementIdBufferPath;
SdfPath normalBufferPath;
SdfPath depthBufferPath;
// The id of the camera used to generate the id buffers.
SdfPath cameraId;
// The framing specifying how the camera frustum in mapped into the
// render buffers.
CameraUtilFraming framing;
// Is application overriding the window policy of the camera.
std::pair<bool, CameraUtilConformWindowPolicy> overrideWindowPolicy;
// The viewport of the camera used to generate the id buffers.
// Only used if framing is invalid - for legacy clients.
GfVec4d viewport;
};
/// \class HdxPickFromRenderBufferTask
///
/// A task for running picking queries against pre-existing id buffers.
/// This task remaps the "pick frustum", provided by HdxPickTaskContextParams,
/// to the camera frustum used to generate the ID buffers. It then runs the
/// pick query against the subset of the ID buffers contained by the pick
/// frustum.
class HdxPickFromRenderBufferTask : public HdxTask
{
public:
HDX_API
HdxPickFromRenderBufferTask(HdSceneDelegate *delegate, SdfPath const& id);
HDX_API
~HdxPickFromRenderBufferTask() override;
/// Hooks for progressive rendering.
bool IsConverged() const override;
/// Prepare the pick task
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute the pick task
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
GfMatrix4d _ComputeProjectionMatrix() const;
HdxPickFromRenderBufferTaskParams _params;
HdxPickTaskContextParams _contextParams;
// We need to cache a pointer to the render index so Execute() can
// map prim ID to paths.
HdRenderIndex *_index;
HdRenderBuffer *_primId;
HdRenderBuffer *_instanceId;
HdRenderBuffer *_elementId;
HdRenderBuffer *_normal;
HdRenderBuffer *_depth;
const HdCamera *_camera;
bool _converged;
HdxPickFromRenderBufferTask() = delete;
HdxPickFromRenderBufferTask(const HdxPickFromRenderBufferTask &) = delete;
HdxPickFromRenderBufferTask &operator =(
const HdxPickFromRenderBufferTask &) = delete;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxPickFromRenderBufferTaskParams& pv);
HDX_API
bool operator==(const HdxPickFromRenderBufferTaskParams& lhs,
const HdxPickFromRenderBufferTaskParams& rhs);
HDX_API
bool operator!=(const HdxPickFromRenderBufferTaskParams& lhs,
const HdxPickFromRenderBufferTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_PICK_FROM_RENDER_BUFFER_TASK_H
+395
View File
@@ -0,0 +1,395 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_PICK_TASK_H
#define PXR_IMAGING_HDX_PICK_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hd/enums.h"
#include "pxr/imaging/hd/renderPass.h"
#include "pxr/imaging/hd/renderPassState.h"
#include "pxr/imaging/hd/rprimCollection.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/base/tf/declarePtrs.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/vec2i.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/vec4i.h"
#include "pxr/base/gf/vec4d.h"
#include "pxr/usd/sdf/path.h"
#include <vector>
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
#define HDX_PICK_TOKENS \
/* Task context */ \
(pickParams) \
\
/* Pick target */ \
(pickPrimsAndInstances) \
(pickFaces) \
(pickEdges) \
(pickPoints) \
\
/* Resolve mode */ \
(resolveNearestToCamera) \
(resolveNearestToCenter) \
(resolveUnique) \
(resolveAll)
TF_DECLARE_PUBLIC_TOKENS(HdxPickTokens, HDX_API, HDX_PICK_TOKENS);
TF_DECLARE_WEAK_AND_REF_PTRS(GlfDrawTarget);
class HdStRenderPassState;
using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
/// Pick task params. This contains render-style state (for example), but is
/// augmented by HdxPickTaskContextParams, which is passed in on the task
/// context.
struct HdxPickTaskParams
{
HdxPickTaskParams()
: cullStyle(HdCullStyleNothing)
, enableSceneMaterials(true)
{}
HdCullStyle cullStyle;
bool enableSceneMaterials;
};
/// Picking hit structure. This is output by the pick task as a record of
/// what objects the picking query found.
struct HdxPickHit {
SdfPath delegateId;
SdfPath objectId;
SdfPath instancerId;
int instanceIndex;
int elementIndex;
int edgeIndex;
int pointIndex;
GfVec3f worldSpaceHitPoint;
GfVec3f worldSpaceHitNormal;
// normalizedDepth is in the range [0,1].
float normalizedDepth;
inline bool IsValid() const {
return !objectId.IsEmpty();
}
HDX_API
size_t GetHash() const;
};
using HdxPickHitVector = std::vector<HdxPickHit>;
/// Pick task context params. This contains task params that can't come from
/// the scene delegate (like resolution mode and pick location, that might
/// be resolved late), as well as the picking collection and the output
/// hit vector.
/// 'pickTarget': The target of the pick operation, which may influence the
/// data filled in the HdxPickHit(s).
/// The available options are:
/// HdxPickTokens->pickPrimsAndInstances
/// HdxPickTokens->pickFaces
/// HdxPickTokens->pickEdges
/// HdxPickTokens->pickPoints
///
/// 'resolveMode': Dictates the resolution of which hit(s) are returned in
/// 'outHits'.
/// The available options are:
/// 1. HdxPickTokens->resolveNearestToCamera : Returns the hit whose
/// position is nearest to the camera
/// 2. HdxPickTokens->resolveNearestToCenter : Returns the hit whose
/// position is nearest to center of the pick location/region.
/// 3. HdxPickTokens->resolveUnique : Returns the unique hits, by hashing
/// the relevant member fields of HdxPickHit. The 'pickTarget'
/// influences this operation. For e.g., the subprim indices are ignored
/// when the pickTarget is pickPrimsAndInstances.
/// 4. HdxPickTokens->resolveAll: Returns all the hits for the pick location
/// or region. The number of hits returned depends on the resolution
/// used and may have duplicates.
///
struct HdxPickTaskContextParams
{
using DepthMaskCallback = std::function<void(void)>;
HdxPickTaskContextParams()
: resolution(128, 128)
, pickTarget(HdxPickTokens->pickPrimsAndInstances)
, resolveMode(HdxPickTokens->resolveNearestToCamera)
, doUnpickablesOcclude(false)
, viewMatrix(1)
, projectionMatrix(1)
, clipPlanes()
, depthMaskCallback(nullptr)
, collection()
, outHits(nullptr)
{}
GfVec2i resolution;
TfToken pickTarget;
TfToken resolveMode;
bool doUnpickablesOcclude;
GfMatrix4d viewMatrix;
GfMatrix4d projectionMatrix;
std::vector<GfVec4d> clipPlanes;
DepthMaskCallback depthMaskCallback;
HdRprimCollection collection;
HdxPickHitVector *outHits;
};
/// \class HdxPickTask
///
/// A task for running picking queries against the current scene.
/// This task generates an id buffer for a "pick frustum" (normally the
/// camera frustum with the near plane narrowed to an (x,y) location and a
/// pick radius); then it resolves that id buffer into a series of prim paths.
/// The "Hit" output also contains subprim picking results (e.g. picked face,
/// edge, point, instance) and the intersection point in scene worldspace.
///
/// HdxPickTask takes an HdxPickTaskParams through the scene delegate, and
/// HdxPickTaskContextParams through the task context as "pickParams".
/// It produces a hit vector, in the task context as "pickHits".
class HdxPickTask : public HdTask
{
public:
HDX_API
HdxPickTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxPickTask() override;
/// Sync the render pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the pick task
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute the pick task
HDX_API
void Execute(HdTaskContext* ctx) override;
HDX_API
const TfTokenVector &GetRenderTags() const override;
/// Utility: Given a UNorm8Vec4 pixel, unpack it into an int32 ID.
static inline int DecodeIDRenderColor(unsigned char const idColor[4]) {
return (int32_t(idColor[0] & 0xff) << 0) |
(int32_t(idColor[1] & 0xff) << 8) |
(int32_t(idColor[2] & 0xff) << 16) |
(int32_t(idColor[3] & 0xff) << 24);
}
private:
HdxPickTaskParams _params;
HdxPickTaskContextParams _contextParams;
TfTokenVector _renderTags;
// We need to cache a pointer to the render index so Execute() can
// map prim ID to paths.
HdRenderIndex *_index;
void _InitIfNeeded(GfVec2i const& widthHeight);
void _ConditionStencilWithGLCallback(
HdxPickTaskContextParams::DepthMaskCallback maskCallback);
bool _UseOcclusionPass() const;
// Create a shared render pass each for pickables and unpickables
HdRenderPassSharedPtr _pickableRenderPass;
HdRenderPassSharedPtr _occluderRenderPass;
// Having separate render pass states allows us to use different
// shader mixins if we choose to (we don't currently).
HdRenderPassStateSharedPtr _pickableRenderPassState;
HdRenderPassStateSharedPtr _occluderRenderPassState;
// A single draw target is shared for all contexts. Since the FBO cannot
// be shared, we clone the attachments on each request.
GlfDrawTargetRefPtr _drawTarget;
HdxPickTask() = delete;
HdxPickTask(const HdxPickTask &) = delete;
HdxPickTask &operator =(const HdxPickTask &) = delete;
};
/// A utility class for resolving ID buffers into hits.
class HdxPickResult {
public:
// Pick result takes a tuple of ID buffers:
// - (primId, instanceId, elementId, edgeId, pointId)
// along with some geometric buffers:
// - (depth, Neye)
// ... and resolves them into a series of hits, using one of the
// algorithms specified below.
//
// index is used to fill in the HdxPickHit structure;
// pickTarget is used to determine what a valid hit is;
// viewMatrix, projectionMatrix, depthRange are used for unprojection
// to calculate the worldSpaceHitPosition and worldSpaceHitNormal.
// bufferSize is the size of the ID buffers, and subRect is the sub-region
// of the id buffers to iterate over in the resolution algorithm.
//
// All buffers need to be the same size, if passed in. It's legal for
// only the depth and primId buffers to be provided; everything else is
// optional but provides a richer picking result.
HDX_API
HdxPickResult(int const* primIds,
int const* instanceIds,
int const* elementIds,
int const* edgeIds,
int const* pointIds,
int const* neyes,
float const* depths,
HdRenderIndex const *index,
TfToken const& pickTarget,
GfMatrix4d const& viewMatrix,
GfMatrix4d const& projectionMatrix,
GfVec2f const& depthRange,
GfVec2i const& bufferSize,
GfVec4i const& subRect);
HDX_API
~HdxPickResult();
HDX_API
HdxPickResult(HdxPickResult &&);
HDX_API
HdxPickResult& operator=(HdxPickResult &&);
/// Return whether the result was given well-formed parameters.
HDX_API
bool IsValid() const;
/// Return the nearest single hit point. Note that this method may be
/// considerably more efficient, as it only needs to construct a single
/// Hit object.
HDX_API
void ResolveNearestToCamera(HdxPickHitVector* allHits) const;
/// Return the nearest single hit point from the center of the viewport.
/// Note that this method may be considerably more efficient, as it only
/// needs to construct a single Hit object.
HDX_API
void ResolveNearestToCenter(HdxPickHitVector* allHits) const;
/// Return all hit points. Note that this may contain redundant objects,
/// however it allows access to all depth values for a given object.
HDX_API
void ResolveAll(HdxPickHitVector* allHits) const;
/// Return the set of unique hit points, keeping only the nearest depth
/// value.
HDX_API
void ResolveUnique(HdxPickHitVector* allHits) const;
private:
bool _ResolveHit(int index, int x, int y, float z, HdxPickHit* hit) const;
size_t _GetHash(int index) const;
bool _IsValidHit(int index) const;
// Provide accessors for all of the ID buffers. Since all but _primIds
// are optional, if the buffer doesn't exist just return -1 (== no hit).
int _GetPrimId(int index) const {
return _primIds ? _primIds[index] : -1;
}
int _GetInstanceId(int index) const {
return _instanceIds ? _instanceIds[index] : -1;
}
int _GetElementId(int index) const {
return _elementIds ? _elementIds[index] : -1;
}
int _GetEdgeId(int index) const {
return _edgeIds ? _edgeIds[index] : -1;
}
int _GetPointId(int index) const {
return _pointIds ? _pointIds[index] : -1;
}
// Provide an accessor for the normal buffer. If the normal buffer is
// provided, this function will unpack the normal. The fallback is
// GfVec3f(0.0f).
GfVec3f _GetNormal(int index) const;
int const* _primIds;
int const* _instanceIds;
int const* _elementIds;
int const* _edgeIds;
int const* _pointIds;
int const* _neyes;
float const* _depths;
HdRenderIndex const *_index;
TfToken _pickTarget;
GfMatrix4d _ndcToWorld;
GfMatrix4d _eyeToWorld;
GfVec2f _depthRange;
GfVec2i _bufferSize;
GfVec4i _subRect;
};
// For sorting, order hits by ndc depth.
HDX_API
bool operator<(HdxPickHit const& lhs, HdxPickHit const& rhs);
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxPickHit& h);
HDX_API
bool operator==(const HdxPickHit& lhs,
const HdxPickHit& rhs);
HDX_API
bool operator!=(const HdxPickHit& lhs,
const HdxPickHit& rhs);
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxPickTaskParams& pv);
HDX_API
bool operator==(const HdxPickTaskParams& lhs,
const HdxPickTaskParams& rhs);
HDX_API
bool operator!=(const HdxPickTaskParams& lhs,
const HdxPickTaskParams& rhs);
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxPickTaskContextParams& pv);
HDX_API
bool operator==(const HdxPickTaskContextParams& lhs,
const HdxPickTaskContextParams& rhs);
HDX_API
bool operator!=(const HdxPickTaskContextParams& lhs,
const HdxPickTaskContextParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_PICK_TASK_H
+130
View File
@@ -0,0 +1,130 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_PRESENT_TASK_H
#define PXR_IMAGING_HDX_PRESENT_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hgi/tokens.h"
#include "pxr/imaging/hgi/types.h"
#include "pxr/imaging/hgiInterop/hgiInterop.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxPresentTaskParams
///
/// PresentTask parameters.
///
struct HdxPresentTaskParams
{
HdxPresentTaskParams()
: dstApi(HgiTokens->OpenGL)
, dstRegion(0)
, enabled(true)
{}
// The graphics lib that is used by the application / viewer.
// (The 'interopSrc' is determined by checking Hgi->GetAPIName)
TfToken dstApi;
/// The framebuffer that the AOVs are presented into. This is a
/// VtValue that encoding a framebuffer in a dstApi specific
/// way.
///
/// E.g., a uint32_t (aka GLuint) for framebuffer object for dstApi==OpenGL.
/// For backwards compatibility, the currently bound framebuffer is used
/// when the VtValue is empty.
VtValue dstFramebuffer;
// Subrectangular region of the framebuffer over which to composite aov
// contents. Coordinates are (left, BOTTOM, width, height).
GfVec4i dstRegion;
// When not enabled, present task does not execute, but still calls
// Hgi::EndFrame.
bool enabled;
};
/// \class HdxPresentTask
///
/// A task for taking the final result of the aovs and compositing it over the
/// currently bound framebuffer.
/// This task uses the 'color' and optionally 'depth' aov's in the task
/// context. The 'color' aov is expected to use non-integer
/// (i.e., float or norm) types to keep the interop step simple.
///
class HdxPresentTask : public HdxTask
{
public:
// Returns true if the format is supported for presentation. This is useful
// for upstream tasks to prepare the AOV data accordingly, and keeps the
// interop step simple.
HDX_API
static bool IsFormatSupported(HgiFormat aovFormat);
HDX_API
HdxPresentTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxPresentTask() override;
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
HdxPresentTaskParams _params;
HgiInterop _interop;
HdxPresentTask() = delete;
HdxPresentTask(const HdxPresentTask &) = delete;
HdxPresentTask &operator =(const HdxPresentTask &) = delete;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxPresentTaskParams& pv);
HDX_API
bool operator==(const HdxPresentTaskParams& lhs,
const HdxPresentTaskParams& rhs);
HDX_API
bool operator!=(const HdxPresentTaskParams& lhs,
const HdxPresentTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+272
View File
@@ -0,0 +1,272 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_RENDER_SETUP_TASK_H
#define PXR_IMAGING_HDX_RENDER_SETUP_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/imaging/hd/tokens.h"
#include "pxr/imaging/hd/enums.h"
#include "pxr/imaging/hd/renderPassState.h"
#include "pxr/imaging/cameraUtil/framing.h"
#include "pxr/base/gf/vec2f.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/vec4d.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
using HdxRenderSetupTaskSharedPtr =
std::shared_ptr<class HdxRenderSetupTask>;
using HdStRenderPassShaderSharedPtr =
std::shared_ptr<class HdStRenderPassShader>;
using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
struct HdxRenderTaskParams;
class HdStRenderPassState;
/// \class HdxRenderSetupTask
///
/// A task for setting up render pass state (camera, renderpass shader, GL
/// states).
///
/// HdxRenderTask depends on the output of this task. Applications can choose
/// to create a render setup task, and pass it the HdxRenderTaskParams; or they
/// can pass the HdxRenderTaskParams directly to the render task, which will
/// create a render setup task internally. See the HdxRenderTask documentation
/// for details.
///
class HdxRenderSetupTask : public HdTask
{
public:
HDX_API
HdxRenderSetupTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxRenderSetupTask() override;
// APIs used from HdxRenderTask to manage the sync/prepare process.
HDX_API
void SyncParams(HdSceneDelegate* delegate,
HdxRenderTaskParams const &params);
HDX_API
void PrepareCamera(HdRenderIndex* renderIndex);
HdRenderPassStateSharedPtr const &GetRenderPassState() const {
return _renderPassState;
}
/// Sync the render pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
private:
HdRenderPassStateSharedPtr _renderPassState;
HdStRenderPassShaderSharedPtr _colorRenderPassShader;
HdStRenderPassShaderSharedPtr _idRenderPassShader;
SdfPath _cameraId;
CameraUtilFraming _framing;
std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
// Used when client did not specify the camera framing (more expressive
// and preferred).
GfVec4d _viewport;
HdRenderPassAovBindingVector _aovBindings;
void _SetRenderpassShadersForStorm(
HdxRenderTaskParams const& params,
HdStRenderPassState *renderPassState);
HdRenderPassStateSharedPtr &_GetRenderPassState(HdRenderIndex* renderIndex);
void _PrepareAovBindings(HdTaskContext* ctx, HdRenderIndex* renderIndex);
HdxRenderSetupTask() = delete;
HdxRenderSetupTask(const HdxRenderSetupTask &) = delete;
HdxRenderSetupTask &operator =(const HdxRenderSetupTask &) = delete;
};
/// \class HdxRenderTaskParams
///
/// RenderTask parameters (renderpass state).
///
struct HdxRenderTaskParams
{
HdxRenderTaskParams()
// Global Params
: overrideColor(0.0)
, wireframeColor(0.0)
, pointColor(GfVec4f(0,0,0,1))
, pointSize(3.0)
, enableLighting(false)
, enableIdRender(false)
, alphaThreshold(0.0)
, enableSceneMaterials(true)
, enableSceneLights(true)
// Selection/Masking params
, maskColor(1.0f, 0.0f, 0.0f, 1.0f)
, indicatorColor(0.0f, 1.0f, 0.0f, 1.0f)
, pointSelectedSize(3.0)
// Storm render pipeline state
, depthBiasUseDefault(true)
, depthBiasEnable(false)
, depthBiasConstantFactor(0.0f)
, depthBiasSlopeFactor(1.0f)
, depthFunc(HdCmpFuncLEqual)
, depthMaskEnable(true)
, stencilFunc(HdCmpFuncAlways)
, stencilRef(0)
, stencilMask(~0)
, stencilFailOp(HdStencilOpKeep)
, stencilZFailOp(HdStencilOpKeep)
, stencilZPassOp(HdStencilOpKeep)
, stencilEnable(false)
, blendColorOp(HdBlendOpAdd)
, blendColorSrcFactor(HdBlendFactorOne)
, blendColorDstFactor(HdBlendFactorZero)
, blendAlphaOp(HdBlendOpAdd)
, blendAlphaSrcFactor(HdBlendFactorOne)
, blendAlphaDstFactor(HdBlendFactorZero)
, blendConstantColor(0.0f, 0.0f, 0.0f, 0.0f)
, blendEnable(false)
, enableAlphaToCoverage(true)
, useAovMultiSample(true)
, resolveAovMultiSample(true)
// Camera framing and viewer state
, viewport(0.0)
, cullStyle(HdCullStyleBackUnlessDoubleSided)
, overrideWindowPolicy{false, CameraUtilFit}
{}
// ---------------------------------------------------------------------- //
// Application rendering state
// XXX: Several of the parameters below are specific to (or work only with)
// Storm and stem from its integration in Presto and usdview.
// ---------------------------------------------------------------------- //
// "Global" parameters while rendering.
GfVec4f overrideColor;
GfVec4f wireframeColor;
GfVec4f pointColor;
float pointSize;
bool enableLighting;
bool enableIdRender;
float alphaThreshold;
bool enableSceneMaterials;
bool enableSceneLights;
// Selection/Masking params
GfVec4f maskColor;
GfVec4f indicatorColor;
float pointSelectedSize;
// AOVs to render to
// XXX: As a transitional API, if this is empty it indicates the renderer
// should write color and depth to the GL framebuffer.
HdRenderPassAovBindingVector aovBindings;
// ---------------------------------------------------------------------- //
// Render pipeline state for rasterizers.
// XXX: These are relevant only for Storm.
// ---------------------------------------------------------------------- //
bool depthBiasUseDefault; // inherit application GL state
bool depthBiasEnable;
float depthBiasConstantFactor;
float depthBiasSlopeFactor;
HdCompareFunction depthFunc;
bool depthMaskEnable;
// Stencil
HdCompareFunction stencilFunc;
int stencilRef;
int stencilMask;
HdStencilOp stencilFailOp;
HdStencilOp stencilZFailOp;
HdStencilOp stencilZPassOp;
bool stencilEnable;
// Blending
HdBlendOp blendColorOp;
HdBlendFactor blendColorSrcFactor;
HdBlendFactor blendColorDstFactor;
HdBlendOp blendAlphaOp;
HdBlendFactor blendAlphaSrcFactor;
HdBlendFactor blendAlphaDstFactor;
GfVec4f blendConstantColor;
bool blendEnable;
// AlphaToCoverage
bool enableAlphaToCoverage;
// If true (default), render into the multi-sampled AOVs (rather than
// the resolved AOVs).
bool useAovMultiSample;
// If true (default), multi-sampled AOVs will be resolved at the end of a
// render pass.
bool resolveAovMultiSample;
// ---------------------------------------------------------------------- //
// Viewer & Camera Framing state
// ---------------------------------------------------------------------- //
SdfPath camera;
CameraUtilFraming framing;
// Only used if framing is invalid.
GfVec4d viewport;
HdCullStyle cullStyle;
std::pair<bool, CameraUtilConformWindowPolicy> overrideWindowPolicy;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxRenderTaskParams& pv);
HDX_API
bool operator==(const HdxRenderTaskParams& lhs, const HdxRenderTaskParams& rhs);
HDX_API
bool operator!=(const HdxRenderTaskParams& lhs, const HdxRenderTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_RENDER_SETUP_TASK_H
+136
View File
@@ -0,0 +1,136 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_RENDER_TASK_H
#define PXR_IMAGING_HDX_RENDER_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hdx/renderSetupTask.h" // for short-term compatibility.
#include "pxr/imaging/hdSt/renderPassState.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HdSceneDelegate;
using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
using HdxRenderSetupTaskSharedPtr = std::shared_ptr<class HdxRenderSetupTask>;
/// \class HdxRenderTask
///
/// A task for rendering geometry to pixels.
///
/// Rendering state management can be handled two ways:
/// 1.) An application can create an HdxRenderTask and pass it the
/// HdxRenderTaskParams struct as "params".
/// 2.) An application can create an HdxRenderSetupTask and an
/// HdxRenderTask, and pass params to the setup task. In this case
/// the setup task must run first.
///
/// Parameter unpacking is handled by HdxRenderSetupTask; in case #1,
/// HdxRenderTask creates a dummy setup task internally to manage the sync
/// process.
///
/// Case #2 introduces complexity; the benefit is that by changing which
/// setup task you run before the render task, you can change the render
/// parameters without incurring a hydra sync or rebuilding any resources.
///
class HdxRenderTask : public HdxTask
{
public:
HDX_API
HdxRenderTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxRenderTask() override;
/// Hooks for progressive rendering (delegated to renderpasses).
HDX_API
bool IsConverged() const override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
/// Collect Render Tags used by the task.
HDX_API
const TfTokenVector &GetRenderTags() const override;
protected:
/// Sync the render pass resources
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
HDX_API
HdRenderPassStateSharedPtr _GetRenderPassState(HdTaskContext *ctx) const;
// XXX: Storm specific API
// While HdDrawItem is currently a core-Hydra concept, it'll be moved
// to Storm. Until then, allow querying the render pass to know if there's
// draw submission work.
// Returns whether the render pass has any draw items to submit.
// For non-Storm backends, this returns true.
// When using with Storm tasks, make sure to call it after
// HdxRenderTask::Prepare().
HDX_API
bool _HasDrawItems() const;
private:
HdRenderPassSharedPtr _pass;
TfTokenVector _renderTags;
// Optional internal render setup task, for params unpacking.
HdxRenderSetupTaskSharedPtr _setupTask;
// XXX: Storm specific API
// Setup additional state that HdStRenderPassState requires.
void _SetHdStRenderPassState(HdTaskContext *ctx,
HdStRenderPassState *renderPassState);
// Inspect the AOV bindings to determine if any of them need to be cleared.
bool _NeedToClearAovs(HdRenderPassStateSharedPtr const &renderPassState)
const;
HdxRenderTask() = delete;
HdxRenderTask(const HdxRenderTask &) = delete;
HdxRenderTask &operator =(const HdxRenderTask &) = delete;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_RENDER_TASK_H
+115
View File
@@ -0,0 +1,115 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_SELECTION_TASK_H
#define PXR_IMAGING_HDX_SELECTION_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/base/gf/vec4f.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HdRenderIndex;
class HdSceneDelegate;
struct HdxSelectionTaskParams
{
bool enableSelection;
float occludedSelectionOpacity; // lerp factor when blending
// occluded selection
GfVec4f selectionColor; // "active" selection color
GfVec4f locateColor; // "rollover" selection color
};
using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
/// \class HdxSelectionTask
///
/// The SelectionTask is responsible for setting up render pass global buffers
/// for selection and depositing those buffers into the task context for down
/// stream consumption. Any render pass which wants to display selection may
/// extract those buffers and bind them into the current render pass shader to
/// enable selection highlighting.
///
class HdxSelectionTask : public HdTask
{
public:
HDX_API
HdxSelectionTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxSelectionTask() override;
/// Sync the render pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
private:
int _lastVersion;
bool _hasSelection;
HdxSelectionTaskParams _params;
HdBufferArrayRangeSharedPtr _selOffsetBar;
HdBufferArrayRangeSharedPtr _selUniformBar;
HdBufferArrayRangeSharedPtr _selPointColorsBar;
HdxSelectionTask() = delete;
HdxSelectionTask(const HdxSelectionTask &) = delete;
HdxSelectionTask &operator =(const HdxSelectionTask &) = delete;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out,
const HdxSelectionTaskParams& pv);
HDX_API
bool operator==(const HdxSelectionTaskParams& lhs,
const HdxSelectionTaskParams& rhs);
HDX_API
bool operator!=(const HdxSelectionTaskParams& lhs,
const HdxSelectionTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_SELECTION_TASK_H
+167
View File
@@ -0,0 +1,167 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_SELECTION_TRACKER_H
#define PXR_IMAGING_HDX_SELECTION_TRACKER_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/selection.h"
#include "pxr/base/vt/array.h"
#include <vector>
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HdRenderIndex;
using HdxSelectionTrackerSharedPtr =
std::shared_ptr<class HdxSelectionTracker>;
/// ----------------------------------------------------------------------------
/// Selection highlighting in Hydra:
///
/// Hydra Stream (*) supports selection highlighting of:
/// (a) a set of rprims, wherein each rprim is entirely highlighted
/// (b) a set of instances of an rprim, wherein each instance is highlighted
/// (c) a set of subprimitives of an rprim, wherein each subprim is highlighted.
/// Subprimitives support is limited to elements (faces of meshes, or
/// individual curves of basis curves), edges of meshes/curves,
/// and points of meshes.
///
/// * While the goal is have an architecture that is extensible by rendering
/// backends, the current implementation is heavily influenced by the Stream(GL)
/// backend.
///
/// Background:
/// The current selection implementation is, in a sense, global in nature.
/// If there are no selected objects, we do not bind any selection-related
/// resources, nor does the shader execute any selection-related operations.
///
/// If there are one or more selected objects, we *don't* choose to have them
/// in a separate 'selection' collection.
/// Instead, we stick by AZDO principles and avoid command buffer changes as
/// a result of selection updates (which would involve removal of draw items
/// corresponding to the selected objects from each render pass' command buffer
/// and building the selection pass' command buffer).
/// We build an integer buffer encoding of the selected items, for use in the
/// fragment shader, that allows us to perform a small number of lookups to
/// quickly tell us if a fragment needs to be highlighted.
///
/// Conceptually, the implementation is split into:
/// (a) HdSelection : Client facing API that builds a collection of selected
/// items. This is agnostic of the rendering backend.
/// (b) HdxSelectionTracker: Base class that observes (a) and encodes it as
/// needed by (c). This may be specialized to be backend specific.
/// (c) HdxSelectionTask : A scene task that, currently, only syncs resources
/// related to selection highlighting. Currently, this is tied to Stream.
/// (d) HdxRenderSetupTask : A scene task that sets up the render pass shader
/// to use the selection highlighting mixin in the render pass(es) of
/// HdxRenderTask. This is relevant only to Stream.
///
/// ----------------------------------------------------------------------------
/// \class HdxSelectionTracker
///
/// HdxSelectionTracker takes HdSelection and generates a GPU buffer to be used
/// \class HdxSelectionTracker
///
/// HdxSelectionTracker is a base class for observing selection state and
/// providing selection highlighting details to interested clients.
///
/// Applications may use HdxSelectionTracker as-is, or extend it as needed.
///
/// HdxSelectionTask takes HdxSelectionTracker as a task parameter, and uploads
/// the selection buffer encoding to the GPU.
///
class HdxSelectionTracker
{
public:
HDX_API
HdxSelectionTracker();
virtual ~HdxSelectionTracker();
/// Optional override to update the HdSelection during
/// HdxSelectionTask::Sync.
HDX_API
virtual void UpdateSelection(HdRenderIndex *index);
/// Encodes the selection state (HdxSelection) as an integer array. This is
/// uploaded to the GPU and decoded in the fragment shader to provide
/// selection highlighting behavior. See HdxSelectionTask.
/// Returns true if offsets has anything selected.
/// \p enableSelection is a global on/off switch for selection; if it's
/// false, nothing will be encoded.
HDX_API
virtual bool GetSelectionOffsetBuffer(HdRenderIndex const *index,
bool enableSelection,
VtIntArray *offsets) const;
HDX_API
virtual VtVec4fArray GetSelectedPointColors() const;
/// Returns a monotonically increasing version number, which increments
/// whenever the result of GetBuffers has changed. Note that this number may
/// overflow and become negative, thus clients should use a not-equal
/// comparison.
HDX_API
int GetVersion() const;
/// The collection of selected objects is expected to be created externally
/// and set via SetSelection.
HDX_API
void SetSelection(HdSelectionSharedPtr const &selection) {
_selection = selection;
_IncrementVersion();
}
/// XXX: Rename to GetSelection
HDX_API
HdSelectionSharedPtr const &GetSelectionMap() const {
return _selection;
}
protected:
/// Increments the internal selection state version, used for invalidation
/// via GetVersion().
HDX_API
void _IncrementVersion();
HDX_API
virtual bool _GetSelectionOffsets(HdSelection::HighlightMode const& mode,
HdRenderIndex const* index,
size_t modeOffset,
std::vector<int>* offsets) const;
private:
int _version;
HdSelectionSharedPtr _selection;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_SELECTION_TRACKER_H
@@ -0,0 +1,60 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_SHADOW_MATRIX_COMPUTATION_H
#define PXR_IMAGING_HDX_SHADOW_MATRIX_COMPUTATION_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/cameraUtil/conformWindow.h"
#include "pxr/base/gf/matrix4d.h"
PXR_NAMESPACE_OPEN_SCOPE
class CameraUtilFraming;
// Interface class for computing the shadow matrix
// for a given viewport.
class HdxShadowMatrixComputation
{
public:
// For legacy clients using viewport, will be removed eventually.
virtual std::vector<GfMatrix4d> Compute(const GfVec4f &viewport, CameraUtilConformWindowPolicy policy) = 0;
// For modern clients using camera framing API.
virtual std::vector<GfMatrix4d> Compute(const CameraUtilFraming &framing, CameraUtilConformWindowPolicy policy) = 0;
protected:
HdxShadowMatrixComputation() = default;
virtual ~HdxShadowMatrixComputation() = default;
private:
HdxShadowMatrixComputation(const HdxShadowMatrixComputation &) = delete;
HdxShadowMatrixComputation &operator =(const HdxShadowMatrixComputation &) = delete;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_SHADOW_MATRIX_COMPUTATION_H
+148
View File
@@ -0,0 +1,148 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_SHADOW_TASK_H
#define PXR_IMAGING_HDX_SHADOW_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/enums.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/base/gf/vec4f.h"
#include "pxr/base/gf/vec4d.h"
#include "pxr/base/tf/declarePtrs.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class GlfSimpleLight;
class HdRenderIndex;
class HdSceneDelegate;
class HdStRenderPassState;
using HdStRenderPassShaderSharedPtr =
std::shared_ptr<class HdStRenderPassShader>;
using HdStShaderCodeSharedPtr =
std::shared_ptr<class HdStShaderCode>;
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
using HdRenderPassSharedPtrVector = std::vector<HdRenderPassSharedPtr>;
using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
using HdStRenderPassStateSharedPtrVector =
std::vector<HdStRenderPassStateSharedPtr>;
TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleShadowArray);
struct HdxShadowTaskParams
{
HdxShadowTaskParams()
: overrideColor(0.0)
, wireframeColor(0.0)
, enableLighting(false)
, enableIdRender(false)
, enableSceneMaterials(true)
, alphaThreshold(0.0)
, depthBiasEnable(false)
, depthBiasConstantFactor(0.0f)
, depthBiasSlopeFactor(1.0f)
, depthFunc(HdCmpFuncLEqual)
, cullStyle(HdCullStyleBackUnlessDoubleSided)
{}
// RenderPassState
GfVec4f overrideColor;
GfVec4f wireframeColor;
bool enableLighting;
bool enableIdRender;
bool enableSceneMaterials;
float alphaThreshold;
bool depthBiasEnable;
float depthBiasConstantFactor;
float depthBiasSlopeFactor;
HdCompareFunction depthFunc;
HdCullStyle cullStyle;
};
/// \class HdxShadowTask
///
/// A task for generating shadow maps.
///
class HdxShadowTask : public HdTask
{
public:
HDX_API
HdxShadowTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxShadowTask() override;
/// Sync the render pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
/// Collect Render Tags used by the task.
HDX_API
const TfTokenVector &GetRenderTags() const override;
private:
void _UpdateDirtyParams(HdStRenderPassStateSharedPtr &renderPassState,
HdxShadowTaskParams const &params);
HdRenderPassSharedPtrVector _passes;
HdStRenderPassStateSharedPtrVector _renderPassStates;
HdxShadowTaskParams _params;
TfTokenVector _renderTags;
HdxShadowTask() = delete;
HdxShadowTask(const HdxShadowTask &) = delete;
HdxShadowTask &operator =(const HdxShadowTask &) = delete;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxShadowTaskParams& pv);
HDX_API
bool operator==(const HdxShadowTaskParams& lhs, const HdxShadowTaskParams& rhs);
HDX_API
bool operator!=(const HdxShadowTaskParams& lhs, const HdxShadowTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_SHADOW_TASK_H
+185
View File
@@ -0,0 +1,185 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_SIMPLE_LIGHT_TASK_H
#define PXR_IMAGING_HDX_SIMPLE_LIGHT_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/imaging/glf/simpleLight.h"
#include "pxr/imaging/glf/simpleMaterial.h"
#include "pxr/imaging/cameraUtil/framing.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/tf/declarePtrs.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class HdRenderIndex;
class HdSceneDelegate;
class HdCamera;
using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
using HdStSimpleLightingShaderSharedPtr =
std::shared_ptr<class HdStSimpleLightingShader>;
using HdxShadowMatrixComputationSharedPtr =
std::shared_ptr<class HdxShadowMatrixComputation>;
TF_DECLARE_REF_PTRS(GlfSimpleShadowArray);
class HdxSimpleLightTask : public HdTask
{
public:
HDX_API
HdxSimpleLightTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxSimpleLightTask() override;
/// Sync the render pass resources
HDX_API
void Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
/// Prepare the tasks resources
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
/// Execute render pass task
HDX_API
void Execute(HdTaskContext* ctx) override;
private:
std::vector<GfMatrix4d> _ComputeShadowMatrices(
const HdCamera * camera,
HdxShadowMatrixComputationSharedPtr const &computation) const;
SdfPath _cameraId;
std::map<TfToken, SdfPathVector> _lightIds;
SdfPathVector _lightIncludePaths;
SdfPathVector _lightExcludePaths;
size_t _numLights;
// Should be weak ptrs
HdStSimpleLightingShaderSharedPtr _lightingShader;
bool _enableShadows;
GfVec4f _viewport;
CameraUtilFraming _framing;
std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
// XXX: compatibility hack for passing some unit tests until we have
// more formal material plumbing.
GlfSimpleMaterial _material;
GfVec4f _sceneAmbient;
// For now these are only valid for the lifetime of a single pass of
// the render graph. Maybe long-term these could be change-tracked.
GlfSimpleLightVector _glfSimpleLights;
size_t _AppendLightsOfType(HdRenderIndex &renderIndex,
std::vector<TfToken> const &lightTypes,
SdfPathVector const &lightIncludePaths,
SdfPathVector const &lightExcludePaths,
std::map<TfToken, SdfPathVector> *lights);
HdxSimpleLightTask() = delete;
HdxSimpleLightTask(const HdxSimpleLightTask &) = delete;
HdxSimpleLightTask &operator =(const HdxSimpleLightTask &) = delete;
};
struct HdxSimpleLightTaskParams {
HdxSimpleLightTaskParams()
: cameraPath()
, lightIncludePaths(1, SdfPath::AbsoluteRootPath())
, lightExcludePaths()
, enableShadows(false)
, viewport(0.0f)
, overrideWindowPolicy{false, CameraUtilFit}
, material()
, sceneAmbient(0)
{}
SdfPath cameraPath;
SdfPathVector lightIncludePaths;
SdfPathVector lightExcludePaths;
bool enableShadows;
GfVec4f viewport;
CameraUtilFraming framing;
std::pair<bool, CameraUtilConformWindowPolicy> overrideWindowPolicy;
// XXX: compatibility hack for passing some unit tests until we have
// more formal material plumbing.
GlfSimpleMaterial material;
GfVec4f sceneAmbient;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxSimpleLightTaskParams& pv);
HDX_API
bool operator==(
const HdxSimpleLightTaskParams& lhs,
const HdxSimpleLightTaskParams& rhs);
HDX_API
bool operator!=(
const HdxSimpleLightTaskParams& lhs,
const HdxSimpleLightTaskParams& rhs);
struct HdxShadowParams {
HdxShadowParams()
: shadowMatrix()
, bias(0.0)
, blur(0.0)
, resolution(0)
, enabled(false)
{}
HdxShadowMatrixComputationSharedPtr shadowMatrix;
double bias;
double blur;
int resolution;
bool enabled;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxShadowParams& pv);
HDX_API
bool operator==(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
HDX_API
bool operator!=(const HdxShadowParams& lhs, const HdxShadowParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_SIMPLE_LIGHT_TASK_H
+97
View File
@@ -0,0 +1,97 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_TASK_H
#define PXR_IMAGING_HDX_TASK_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hd/task.h"
PXR_NAMESPACE_OPEN_SCOPE
class Hgi;
/// \class HdxTask
///
/// Base class for (some) tasks in Hdx that provides common progressive
/// rendering and Hgi functionality.
///
/// Tasks that require neither progressive rendering nor Hgi can continue to
/// derive directly from HdTask.
///
class HdxTask : public HdTask
{
public:
HDX_API
HdxTask(SdfPath const& id);
HDX_API
~HdxTask() override;
/// This function returns true when a (progressive) task considers its
/// execution results converged. Usually this means that a progressive
/// render delegate is finished rendering into the HdRenderBuffers used by
/// this task.
/// Returns true by default which is a good default for rasterizers.
///
/// Applications with data-driven task lists can determine their convergence
/// state by determining which tasks are HdxTasks and then querying
/// specifically those tasks for IsConverged.
HDX_API
virtual bool IsConverged() const;
/// We override HdTask::Sync, but make it 'final' to make sure derived
/// classes can't override it and instead override _Sync.
/// This 'non-virtual interface'-like pattern allows us to ensure we always
/// initialized Hgi during the Sync task so derived classes don't have to.
void Sync(
HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) final;
protected:
// This is called during the hydra Sync Phase via HdxTask::Sync.
// Please see HdTask::Sync for Sync Phase documentation.
virtual void _Sync(
HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) = 0;
// Swaps the color target and colorIntermediate target.
// This is used when a task wishes to read from the color and also write
// to it. We use two color targets and ping-pong between them.
void _ToggleRenderTarget(HdTaskContext* ctx);
// Return pointer to Hydra Graphics Interface.
HDX_API
Hgi* _GetHgi() const;
Hgi* _hgi;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+404
View File
@@ -0,0 +1,404 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_TASK_CONTROLLER_H
#define PXR_IMAGING_HDX_TASK_CONTROLLER_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/selectionTracker.h"
#include "pxr/imaging/hdx/renderSetupTask.h"
#include "pxr/imaging/hdx/shadowTask.h"
#include "pxr/imaging/hdx/colorCorrectionTask.h"
#include "pxr/imaging/hd/aov.h"
#include "pxr/imaging/hd/renderIndex.h"
#include "pxr/imaging/hd/sceneDelegate.h"
#include "pxr/imaging/hd/task.h"
#include "pxr/imaging/cameraUtil/framing.h"
#include "pxr/imaging/glf/simpleLightingContext.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/base/gf/matrix4d.h"
PXR_NAMESPACE_OPEN_SCOPE
// XXX: This API is transitional. At the least, render/picking/selection
// APIs should be decoupled.
class HdRenderBuffer;
class HdxTaskController final
{
public:
HDX_API
HdxTaskController(HdRenderIndex *renderIndex,
SdfPath const& controllerId);
HDX_API
~HdxTaskController();
/// Return the render index this controller is bound to.
HdRenderIndex* GetRenderIndex() { return _index; }
HdRenderIndex const* GetRenderIndex() const { return _index; }
/// Return the controller's scene-graph id (prefixed to any
/// scene graph objects it creates).
SdfPath const& GetControllerId() const { return _controllerId; }
/// -------------------------------------------------------
/// Execution API
/// Obtain the set of tasks managed by the task controller,
/// for image generation. The tasks returned will be different
/// based on current renderer state.
HDX_API
HdTaskSharedPtrVector const GetRenderingTasks() const;
/// Obtain the set of tasks managed by the task controller,
/// for picking.
HDX_API
HdTaskSharedPtrVector const GetPickingTasks() const;
/// -------------------------------------------------------
/// Rendering API
/// Set the collection to be rendered.
HDX_API
void SetCollection(HdRprimCollection const& collection);
/// Set the render params. Note: params.viewport will
/// be overwritten, since it comes from SetRenderViewport.
/// XXX: For GL renders, HdxTaskController relies on the caller to
/// correctly set GL_SAMPLE_ALPHA_TO_COVERAGE.
HDX_API
void SetRenderParams(HdxRenderTaskParams const& params);
/// Set the "view" opinion of the scenes render tags.
/// The opinion is the base opinion for the entire scene.
/// Individual tasks (such as the shadow task) may
/// have a stronger opinion and override this opinion
HDX_API
void SetRenderTags(TfTokenVector const& renderTags);
/// -------------------------------------------------------
/// AOV API
/// Set the list of outputs to be rendered. If outputs.size() == 1,
/// this will send that output to the viewport via a colorizer task.
/// Note: names should come from HdAovTokens.
HDX_API
void SetRenderOutputs(TfTokenVector const& names);
/// Set which output should be rendered to the viewport. The empty token
/// disables viewport rendering.
HDX_API
void SetViewportRenderOutput(TfToken const& name);
/// Get the buffer for a rendered output. Note: the caller should call
/// Resolve(), as HdxTaskController doesn't guarantee the buffer will
/// be resolved.
HDX_API
HdRenderBuffer* GetRenderOutput(TfToken const& name);
/// Set custom parameters for an AOV.
HDX_API
void SetRenderOutputSettings(TfToken const& name,
HdAovDescriptor const& desc);
/// Get parameters for an AOV.
HDX_API
HdAovDescriptor GetRenderOutputSettings(TfToken const& name) const;
/// The destination API (e.g., OpenGL, see hgiInterop for details) and
/// framebuffer that the AOVs are presented into. The framebuffer
/// is a VtValue that encoding a framebuffer in a destination API
/// specific way.
/// E.g., a uint32_t (aka GLuint) for framebuffer object for OpenGL.
HDX_API
void SetPresentationOutput(TfToken const &api, VtValue const &framebuffer);
/// -------------------------------------------------------
/// Lighting API
/// Set the lighting state for the scene. HdxTaskController maintains
/// a set of light sprims with data set from the lights in "src".
/// @param src Lighting state to implement.
HDX_API
void SetLightingState(GlfSimpleLightingContextPtr const& src);
/// -------------------------------------------------------
/// Camera and Framing API
/// Set the size of the render buffers baking the AOVs.
/// GUI applications should set this to the size of the window.
///
HDX_API
void SetRenderBufferSize(const GfVec2i &size);
/// Determines how the filmback of the camera is mapped into
/// the pixels of the render buffer and what pixels of the render
/// buffer will be rendered into.
HDX_API
void SetFraming(const CameraUtilFraming &framing);
/// Specifies whether to force a window policy when conforming
/// the frustum of the camera to match the display window of
/// the camera framing.
///
/// If set to {false, ...}, the window policy of the specified camera
/// will be used.
///
/// Note: std::pair<bool, ...> is used instead of std::optional<...>
/// because the latter is only available in C++17 or later.
HDX_API
void SetOverrideWindowPolicy(
const std::pair<bool, CameraUtilConformWindowPolicy> &policy);
/// -- Scene camera --
/// Set the camera param on tasks to a USD camera path.
HDX_API
void SetCameraPath(SdfPath const& id);
/// Set the viewport param on tasks.
///
/// \deprecated Use SetFraming and SetRenderBufferSize instead.
HDX_API
void SetRenderViewport(GfVec4d const& viewport);
/// -- Free camera --
/// Set the view and projection matrices for the free camera.
/// Note: The projection matrix must be pre-adjusted for the window policy.
HDX_API
void SetFreeCameraMatrices(GfMatrix4d const& viewMatrix,
GfMatrix4d const& projectionMatrix);
/// Set the free camera clip planes.
/// (Note: Scene cameras use clipping planes authored on the camera prim)
HDX_API
void SetFreeCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
/// -------------------------------------------------------
/// Selection API
/// Turns the selection task on or off.
HDX_API
void SetEnableSelection(bool enable);
/// Set the selection color.
HDX_API
void SetSelectionColor(GfVec4f const& color);
/// Set if the selection highlight should be rendered as an outline around
/// the selected objects or as a solid color overlaid on top of them.
HDX_API
void SetSelectionEnableOutline(bool enableOutline);
/// Set the selection outline radius (thickness) in pixels. This is only
/// relevant if the highlight is meant to be rendered as an outline (if
/// SetSelectionRenderOutline(true) is called).
HDX_API
void SetSelectionOutlineRadius(unsigned int radius);
/// -------------------------------------------------------
/// Shadow API
/// Turns the shadow task on or off.
HDX_API
void SetEnableShadows(bool enable);
/// Set the shadow params. Note: params.camera will
/// be overwritten, since it comes from SetCameraPath/SetCameraState.
HDX_API
void SetShadowParams(HdxShadowTaskParams const& params);
/// -------------------------------------------------------
/// Progressive Image Generation
/// Return whether the image has converged.
HDX_API
bool IsConverged() const;
/// -------------------------------------------------------
/// Color Correction API
/// Configure color correction by settings params.
HDX_API
void SetColorCorrectionParams(HdxColorCorrectionTaskParams const& params);
/// -------------------------------------------------------
/// Present API
/// Enable / disable presenting the render to bound framebuffer.
/// An application may choose to manage the AOVs that are rendered into
/// itself and skip the task controller's presentation.
HDX_API
void SetEnablePresentation(bool enabled);
private:
///
/// This class is not intended to be copied.
///
HdxTaskController(HdxTaskController const&) = delete;
HdxTaskController &operator=(HdxTaskController const&) = delete;
HdRenderIndex *_index;
SdfPath const _controllerId;
// Create taskController objects. Since the camera is a parameter
// to the tasks, _CreateCamera() should be called first.
void _CreateRenderGraph();
void _CreateLightingTask();
void _CreateShadowTask();
SdfPath _CreateRenderTask(TfToken const& materialTag);
void _CreateOitResolveTask();
void _CreateSelectionTask();
void _CreateColorizeSelectionTask();
void _CreateColorCorrectionTask();
void _CreateVisualizeAovTask();
void _CreatePickTask();
void _CreatePickFromRenderBufferTask();
void _CreateAovInputTask();
void _CreatePresentTask();
void _SetCameraParamForTasks(SdfPath const& id);
void _SetCameraFramingForTasks();
void _UpdateAovDimensions(GfVec2i const& dimensions);
void _SetBlendStateForMaterialTag(TfToken const& materialTag,
HdxRenderTaskParams *renderParams) const;
// Render graph topology control.
bool _ShadowsEnabled() const;
bool _SelectionEnabled() const;
bool _ColorizeSelectionEnabled() const;
bool _ColorCorrectionEnabled() const;
bool _VisualizeAovEnabled() const;
bool _ColorizeQuantizationEnabled() const;
bool _AovsSupported() const;
bool _UsingAovs() const;
// Helper function for renderbuffer management.
SdfPath _GetRenderTaskPath(TfToken const& materialTag) const;
SdfPath _GetAovPath(TfToken const& aov) const;
SdfPathVector _GetAovEnabledTasks() const;
// Helper function to set the parameters of a light, get a particular light
// in the scene, replace and remove Sprims from the scene
void _SetParameters(SdfPath const& pathName, GlfSimpleLight const& light);
GlfSimpleLight _GetLightAtId(size_t const& pathIdx);
void _RemoveLightSprim(size_t const& pathIdx);
void _ReplaceLightSprim(size_t const& pathIdx, GlfSimpleLight const& light,
SdfPath const& pathName);
// A private scene delegate member variable backs the tasks and the free cam
// this controller generates. To keep _Delegate simple, the containing class
// is responsible for marking things dirty.
class _Delegate : public HdSceneDelegate
{
public:
_Delegate(HdRenderIndex *parentIndex,
SdfPath const& delegateID)
: HdSceneDelegate(parentIndex, delegateID)
{}
~_Delegate() override = default;
// HdxTaskController set/get interface
template <typename T>
void SetParameter(SdfPath const& id, TfToken const& key,
T const& value) {
_valueCacheMap[id][key] = value;
}
template <typename T>
T GetParameter(SdfPath const& id, TfToken const& key) const {
VtValue vParams;
_ValueCache vCache;
TF_VERIFY(
TfMapLookup(_valueCacheMap, id, &vCache) &&
TfMapLookup(vCache, key, &vParams) &&
vParams.IsHolding<T>());
return vParams.Get<T>();
}
bool HasParameter(SdfPath const& id, TfToken const& key) const {
_ValueCache vCache;
if (TfMapLookup(_valueCacheMap, id, &vCache) &&
vCache.count(key) > 0) {
return true;
}
return false;
}
// HdSceneDelegate interface
VtValue Get(SdfPath const& id, TfToken const& key) override;
GfMatrix4d GetTransform(SdfPath const& id) override;
VtValue GetLightParamValue(SdfPath const& id,
TfToken const& paramName) override;
bool IsEnabled(TfToken const& option) const override;
HdRenderBufferDescriptor
GetRenderBufferDescriptor(SdfPath const& id) override;
TfTokenVector GetTaskRenderTags(SdfPath const& taskId) override;
private:
using _ValueCache = TfHashMap<TfToken, VtValue, TfToken::HashFunctor>;
using _ValueCacheMap = TfHashMap<SdfPath, _ValueCache, SdfPath::Hash>;
_ValueCacheMap _valueCacheMap;
};
_Delegate _delegate;
std::unique_ptr<class HdxFreeCameraSceneDelegate> _freeCameraSceneDelegate;
// Generated tasks.
SdfPath _simpleLightTaskId;
SdfPath _shadowTaskId;
SdfPathVector _renderTaskIds;
SdfPath _aovInputTaskId;
SdfPath _oitResolveTaskId;
SdfPath _selectionTaskId;
SdfPath _colorizeSelectionTaskId;
SdfPath _colorCorrectionTaskId;
SdfPath _visualizeAovTaskId;
SdfPath _pickTaskId;
SdfPath _pickFromRenderBufferTaskId;
SdfPath _presentTaskId;
// Current active camera
SdfPath _activeCameraId;
// Built-in lights
SdfPathVector _lightIds;
// Generated renderbuffers
SdfPathVector _aovBufferIds;
TfTokenVector _aovOutputs;
TfToken _viewportAov;
GfVec2i _renderBufferSize;
CameraUtilFraming _framing;
std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
GfVec4d _viewport;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_IMAGING_HDX_TASK_CONTROLLER_H
+150
View File
@@ -0,0 +1,150 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_TOKENS_H
#define PXR_IMAGING_HDX_TOKENS_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/base/tf/staticTokens.h"
PXR_NAMESPACE_OPEN_SCOPE
#define HDX_TOKENS \
(hdxOitCounterBuffer) \
(hdxOitDataBuffer) \
(hdxOitDepthBuffer) \
(hdxOitIndexBuffer) \
(hdxSelectionBuffer) \
(imagerVersion) \
(lightingContext) \
(lightingShader) \
(occludedSelectionOpacity) \
(oitCounter) \
(oitData) \
(oitDepth) \
(oitIndices) \
(oitUniforms) \
(oitCounterBufferBar) \
(oitDataBufferBar) \
(oitDepthBufferBar) \
(oitIndexBufferBar) \
(oitUniformBar) \
(oitRenderPassState) \
(oitScreenSize) \
(oitRequestFlag) \
(oitClearedFlag) \
(renderPassState) \
(renderIndexVersion) \
(selection) \
(selectionState) \
(selectionOffsets) \
(selectionUniforms) \
(selColor) \
(selLocateColor) \
(selectionPointColors) \
(drawTargetRenderPasses) \
(aovBindings)
TF_DECLARE_PUBLIC_TOKENS(HdxTokens, HDX_API, HDX_TOKENS);
#define HDX_PRIMITIVE_TOKENS \
(lightTypePositional) \
(lightTypeDirectional) \
(lightTypeSpot) \
\
(aovInputTask) \
(drawTargetTask) \
(drawTargetResolveTask) \
(colorizeSelectionTask) \
(oitRenderTask) \
(oitResolveTask) \
(oitVolumeRenderTask) \
(pickTask) \
(pickFromRenderBufferTask) \
(presentTask) \
(renderTask) \
(renderSetupTask) \
(simpleLightTask) \
(shadowTask)
TF_DECLARE_PUBLIC_TOKENS(HdxPrimitiveTokens, HDX_API, HDX_PRIMITIVE_TOKENS);
// inCameraGuide is for guides for a camera that only show up when looking
// through that camera.
#define HDX_RENDERTAG_TOKENS \
(renderingGuide) \
(label) \
(cameraGuide) \
(inCameraGuide) \
(streamline) \
(interactiveOnlyGeom) \
(path)
TF_DECLARE_PUBLIC_TOKENS(HdxRenderTagTokens, HDX_API, HDX_RENDERTAG_TOKENS);
// XXX Deprecated Use: HdStMaterialTagTokens
#define HDX_MATERIALTAG_TOKENS \
(additive) \
(translucent)
TF_DECLARE_PUBLIC_TOKENS(HdxMaterialTagTokens, HDX_API, HDX_MATERIALTAG_TOKENS);
#define HDX_COLOR_CORRECTION_TOKENS \
(disabled) \
(sRGB) \
(openColorIO) \
(channelsOnly)
TF_DECLARE_PUBLIC_TOKENS(HdxColorCorrectionTokens, HDX_API,
HDX_COLOR_CORRECTION_TOKENS);
// Color channels
#define HDX_COLOR_CHANNEL_TOKENS \
(color) \
(red) \
(green) \
(blue) \
(alpha) \
(luminance)
TF_DECLARE_PUBLIC_TOKENS(HdxColorChannelTokens, HDX_API,
HDX_COLOR_CHANNEL_TOKENS);
// Color channels
#define HDX_AOV_TOKENS \
/* colorIntermediate->colorIntermediate is used to ping-pong
* between two color targets when a task wishes to
* read from the color target and also write into it.
*/ \
(colorIntermediate) \
TF_DECLARE_PUBLIC_TOKENS(HdxAovTokens, HDX_API,
HDX_AOV_TOKENS);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_TOKENS_H
+60
View File
@@ -0,0 +1,60 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_TYPES_H
#define PXR_IMAGING_HDX_TYPES_H
#include "pxr/pxr.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/version.h"
#include "pxr/imaging/hgi/types.h"
#include "pxr/imaging/hio/types.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/vt/dictionary.h"
PXR_NAMESPACE_OPEN_SCOPE
// Struct used to send shader inputs from Presto and send them to Hydra
struct HdxShaderInputs {
VtDictionary parameters;
VtDictionary textures;
VtDictionary textureFallbackValues;
TfTokenVector attributes;
VtDictionary metaData;
};
HDX_API
bool operator==(const HdxShaderInputs& lhs, const HdxShaderInputs& rhs);
HDX_API
bool operator!=(const HdxShaderInputs& lhs, const HdxShaderInputs& rhs);
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxShaderInputs& pv);
/// Returns the HioFormat for the given HgiFormat
HDX_API
HioFormat HdxGetHioFormat(HgiFormat hgiFormat);
PXR_NAMESPACE_CLOSE_SCOPE
#endif //PXR_IMAGING_HDX_TYPES_H
+36
View File
@@ -0,0 +1,36 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_IMAGING_HDX_VERSION_H
#define PXR_IMAGING_HDX_VERSION_H
// 1 -> 2 : split HdxRenderSetupTask out of HdxRenderTask
// 2 -> 3 : move simpleLightingShader to Hdx.
// 3 -> 4 : move camera and light to Hdx.
// 4 -> 5 : move drawTarget to Hdx.
// 5 -> 6 : change HdxShadowMatrixComputation signature.
// 6 -> 7 : make HdxShadowMatrixComputationSharedPtr std::shared_ptr instead of boost::shared_ptr
// 7 -> 8 : added another HdxShadowMatrixComputation signature.
#define HDX_API_VERSION 8
#endif // PXR_IMAGING_HDX_VERSION_H
+186
View File
@@ -0,0 +1,186 @@
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef HDX_VISUALIZE_AOV_TASK_H
#define HDX_VISUALIZE_AOV_TASK_H
#include "pxr/pxr.h"
#include "pxr/base/gf/vec3i.h"
#include "pxr/imaging/hdx/api.h"
#include "pxr/imaging/hdx/task.h"
#include "pxr/imaging/hdx/tokens.h"
#include "pxr/imaging/hgi/attachmentDesc.h"
#include "pxr/imaging/hgi/buffer.h"
#include "pxr/imaging/hgi/graphicsPipeline.h"
#include "pxr/imaging/hgi/resourceBindings.h"
#include "pxr/imaging/hgi/shaderProgram.h"
#include "pxr/imaging/hgi/texture.h"
#include "pxr/usd/sdf/path.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class HdxVisualizeAovTask
///
/// A task for visualizing non-color AOVs such as depth, normals, primId.
///
/// Different kernels are used depending on the AOV:
/// Depth: Renormalized from the range [0.0, 1.0] to [min, max] depth
/// to provide better contrast.
/// Normals: Transform each component from [-1.0, 1.0] tp [0.0, 1.0] so that
/// negative components don't appear black.
/// Ids: Integer ids are colorized by multiplying by a large prime and
/// shuffling resulting bits so that neighboring ids are easily
/// distinguishable.
/// Other Aovs: A fallback kernel that transfers the AOV contents into a
/// float texture is used.
///
/// This task updates the 'color' entry of the task context with the colorized
/// texture contents.
///
class HdxVisualizeAovTask : public HdxTask
{
public:
HDX_API
HdxVisualizeAovTask(HdSceneDelegate* delegate, SdfPath const& id);
HDX_API
~HdxVisualizeAovTask() override;
HDX_API
void Prepare(HdTaskContext* ctx,
HdRenderIndex* renderIndex) override;
HDX_API
void Execute(HdTaskContext* ctx) override;
protected:
HDX_API
void _Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
HdDirtyBits* dirtyBits) override;
private:
// Enumeration of visualization kernels
enum VizKernel {
VizKernelDepth = 0,
VizKernelId,
VizKernelNormal,
VizKernelFallback,
VizKernelNone
};
HdxVisualizeAovTask() = delete;
HdxVisualizeAovTask(const HdxVisualizeAovTask &) = delete;
HdxVisualizeAovTask &operator =(const HdxVisualizeAovTask &) = delete;
// Returns true if the enum member was updated, indicating that the kernel
// to be used has changed.
bool _UpdateVizKernel(TfToken const &aovName);
// Returns a token used in sampling the texture based on the kernel used.
TfToken const& _GetTextureIdentifierForShader() const;
// Returns the fragment shader mixin based on the kernel used.
TfToken const& _GetFragmentMixin() const;
// ------------- Hgi resource creation/deletion utilities ------------------
// Utility function to create the GL program for color correction
bool _CreateShaderResources(HgiTextureDesc const& inputAovTextureDesc);
// Utility function to create buffer resources.
bool _CreateBufferResources();
// Utility to create resource bindings
bool _CreateResourceBindings(HgiTextureHandle const& inputAovTexture);
// Utility to create a pipeline
bool _CreatePipeline(HgiTextureDesc const& outputTextureDesc);
// Utility to create a texture sampler
bool _CreateSampler();
// Create texture to write the colorized results into.
bool _CreateOutputTexture(GfVec3i const &dimensions);
// Destroy shader program and the shader functions it holds.
void _DestroyShaderProgram();
// Print shader compile errors.
void _PrintCompileErrors();
// -------------------------------------------------------------------------
// Readback the depth AOV on the CPU to update min, max values.
void _UpdateMinMaxDepth(HgiTextureHandle const &inputAovTexture);
// Execute the appropriate kernel and update the task context 'color' entry.
void _ApplyVisualizationKernel(HgiTextureHandle const& outputTexture);
// Kernel dependent resources
HgiTextureHandle _outputTexture;
GfVec3i _outputTextureDimensions;
HgiAttachmentDesc _outputAttachmentDesc;
HgiShaderProgramHandle _shaderProgram;
HgiResourceBindingsHandle _resourceBindings;
HgiGraphicsPipelineHandle _pipeline;
// Kernel independent resources
HgiBufferHandle _indexBuffer;
HgiBufferHandle _vertexBuffer;
HgiSamplerHandle _sampler;
float _screenSize[2];
float _minMaxDepth[2];
VizKernel _vizKernel;
};
/// \class HdxVisualizeAovTaskParams
///
/// `aovName`: The name of the aov to visualize.
///
/// The Hgi texture resource backing the AOV is retreived from the task context
/// instead of fetching the render buffer prim via its render index path.
/// HdxAovInputTask is responsible for updating the task context entry for
/// the active AOV.
///
struct HdxVisualizeAovTaskParams
{
HDX_API
HdxVisualizeAovTaskParams();
TfToken aovName;
};
// VtValue requirements
HDX_API
std::ostream& operator<<(std::ostream& out, const HdxVisualizeAovTaskParams& pv);
HDX_API
bool operator==(const HdxVisualizeAovTaskParams& lhs,
const HdxVisualizeAovTaskParams& rhs);
HDX_API
bool operator!=(const HdxVisualizeAovTaskParams& lhs,
const HdxVisualizeAovTaskParams& rhs);
PXR_NAMESPACE_CLOSE_SCOPE
#endif