Skip to content

Commit

Permalink
Hdx shadows: adding CameraUtilFraming (that replaces the viewport) to…
Browse files Browse the repository at this point in the history
… HdxSimpleLightTaskParams and adding corresponding signature to HdxShadowMatrixComputation.

(Internal change: 2149173)
  • Loading branch information
unhyperbolic authored and pixar-oss committed Feb 19, 2021
1 parent e6ae4f9 commit 0eac446
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
5 changes: 5 additions & 0 deletions pxr/imaging/hdx/shadowMatrixComputation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@

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;
Expand Down
37 changes: 28 additions & 9 deletions pxr/imaging/hdx/simpleLightTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ HdxSimpleLightTask::HdxSimpleLightTask(
, _lightingShader(std::make_shared<HdStSimpleLightingShader>())
, _enableShadows(false)
, _viewport(0.0f, 0.0f, 0.0f, 0.0f)
, _overrideWindowPolicy{false, CameraUtilFit}
, _material()
, _sceneAmbient()
, _glfSimpleLights()
Expand All @@ -66,6 +67,24 @@ HdxSimpleLightTask::HdxSimpleLightTask(

HdxSimpleLightTask::~HdxSimpleLightTask() = default;

std::vector<GfMatrix4d>
HdxSimpleLightTask::_ComputeShadowMatrices(
const HdCamera * const camera,
HdxShadowMatrixComputationSharedPtr const &computation) const
{
const CameraUtilConformWindowPolicy camPolicy = camera->GetWindowPolicy();

if (_framing.IsValid()) {
CameraUtilConformWindowPolicy const policy =
_overrideWindowPolicy.first
? _overrideWindowPolicy.second
: camPolicy;
return computation->Compute(_framing, policy);
} else {
return computation->Compute(_viewport, camPolicy);
}
}

void
HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,
HdTaskContext* ctx,
Expand Down Expand Up @@ -93,6 +112,8 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,
_cameraId = params.cameraPath;
_enableShadows = params.enableShadows;
_viewport = params.viewport;
_framing = params.framing;
_overrideWindowPolicy = params.overrideWindowPolicy;
// XXX: compatibility hack for passing some unit tests until we have
// more formal material plumbing.
_material = params.material;
Expand Down Expand Up @@ -127,8 +148,6 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,
GfMatrix4d const& projectionMatrix = camera->GetProjectionMatrix();
// Extract the camera window policy to adjust the frustum correctly for
// lights that have shadows.
CameraUtilConformWindowPolicy const& windowPolicy =
camera->GetWindowPolicy();

// Unique identifier for lights with shadows
int shadowIndex = -1;
Expand Down Expand Up @@ -175,7 +194,7 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,

// Take a copy of the simple light into our temporary array and
// update it with viewer-dependant values.
VtValue vtLightParams = light->Get(HdLightTokens->params);
const VtValue vtLightParams = light->Get(HdLightTokens->params);
GlfSimpleLight glfl =
vtLightParams.GetWithDefault<GlfSimpleLight>(GlfSimpleLight());

Expand Down Expand Up @@ -203,9 +222,9 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,
glfl.SetIsCameraSpaceLight(false);
}

VtValue vLightShadowParams =
const VtValue vLightShadowParams =
light->Get(HdLightTokens->shadowParams);
HdxShadowParams lightShadowParams =
const HdxShadowParams lightShadowParams =
vLightShadowParams.GetWithDefault<HdxShadowParams>
(HdxShadowParams());

Expand All @@ -225,11 +244,11 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,
continue;
}

std::vector<GfMatrix4d> shadowMatrices =
lightShadowParams.shadowMatrix->Compute(_viewport,
windowPolicy);
const std::vector<GfMatrix4d> shadowMatrices =
_ComputeShadowMatrices(
camera, lightShadowParams.shadowMatrix);

if (shadowMatrices.size() == 0) {
if (shadowMatrices.empty()) {
glfl.SetHasShadow(false);
continue;
}
Expand Down
12 changes: 12 additions & 0 deletions pxr/imaging/hdx/simpleLightTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#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"

Expand All @@ -42,6 +44,7 @@ PXR_NAMESPACE_OPEN_SCOPE

class HdRenderIndex;
class HdSceneDelegate;
class HdCamera;

using HdRenderPassSharedPtr = std::shared_ptr<class HdRenderPass>;
using HdStSimpleLightingShaderSharedPtr =
Expand Down Expand Up @@ -77,6 +80,10 @@ class HdxSimpleLightTask : public HdTask
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;
Expand All @@ -87,6 +94,8 @@ class HdxSimpleLightTask : public HdTask
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.
Expand Down Expand Up @@ -115,6 +124,7 @@ struct HdxSimpleLightTaskParams {
, lightExcludePaths()
, enableShadows(false)
, viewport(0.0f)
, overrideWindowPolicy{false, CameraUtilFit}
, material()
, sceneAmbient(0)
{}
Expand All @@ -124,6 +134,8 @@ struct HdxSimpleLightTaskParams {
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.
Expand Down
16 changes: 12 additions & 4 deletions pxr/imaging/hdx/unitTestDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ShadowMatrix : public HdxShadowMatrixComputation
frustum.SetProjectionType(GfFrustum::Orthographic);
frustum.SetWindow(GfRange2d(GfVec2d(-10, -10), GfVec2d(10, 10)));
frustum.SetNearFar(GfRange1d(0, 100));
GfVec4d pos = light.GetPosition();
const GfVec4d pos = light.GetPosition();
frustum.SetPosition(GfVec3d(0, 0, 10));
frustum.SetRotation(GfRotation(GfVec3d(0, 0, 1),
GfVec3d(pos[0], pos[1], pos[2])));
Expand All @@ -93,10 +93,18 @@ class ShadowMatrix : public HdxShadowMatrixComputation
frustum.ComputeViewMatrix() * frustum.ComputeProjectionMatrix();
}

virtual std::vector<GfMatrix4d> Compute(
const GfVec4f &viewport, CameraUtilConformWindowPolicy policy) {
return std::vector<GfMatrix4d>(1, _shadowMatrix);
std::vector<GfMatrix4d> Compute(
const GfVec4f &viewport,
CameraUtilConformWindowPolicy policy) override {
return { _shadowMatrix };
}

std::vector<GfMatrix4d> Compute(
const CameraUtilFraming &framing,
CameraUtilConformWindowPolicy policy) override {
return { _shadowMatrix };
}

private:
GfMatrix4d _shadowMatrix;
};
Expand Down
3 changes: 2 additions & 1 deletion pxr/imaging/hdx/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// 4 -> 5 : move drawTarget to Hdx.
// 5 -> 6 : change HdxShadowMatrixComputation signature.
// 6 -> 7 : make HdxShadowMatrixComputationSharedPtr std::shared_ptr instead of boost::shared_ptr
#define HDX_API_VERSION 7
// 7 -> 8 : added another HdxShadowMatrixComputation signature.
#define HDX_API_VERSION 8

#endif // PXR_IMAGING_HDX_VERSION_H

0 comments on commit 0eac446

Please sign in to comment.