diff --git a/pxr/imaging/hdx/shadowMatrixComputation.h b/pxr/imaging/hdx/shadowMatrixComputation.h index 63aa28c4f4..ac1c23e9d8 100644 --- a/pxr/imaging/hdx/shadowMatrixComputation.h +++ b/pxr/imaging/hdx/shadowMatrixComputation.h @@ -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 Compute(const GfVec4f &viewport, CameraUtilConformWindowPolicy policy) = 0; + // For modern clients using camera framing API. + virtual std::vector Compute(const CameraUtilFraming &framing, CameraUtilConformWindowPolicy policy) = 0; + protected: HdxShadowMatrixComputation() = default; virtual ~HdxShadowMatrixComputation() = default; diff --git a/pxr/imaging/hdx/simpleLightTask.cpp b/pxr/imaging/hdx/simpleLightTask.cpp index 9c800e6ce4..e5fca9e9e6 100644 --- a/pxr/imaging/hdx/simpleLightTask.cpp +++ b/pxr/imaging/hdx/simpleLightTask.cpp @@ -58,6 +58,7 @@ HdxSimpleLightTask::HdxSimpleLightTask( , _lightingShader(std::make_shared()) , _enableShadows(false) , _viewport(0.0f, 0.0f, 0.0f, 0.0f) + , _overrideWindowPolicy{false, CameraUtilFit} , _material() , _sceneAmbient() , _glfSimpleLights() @@ -66,6 +67,24 @@ HdxSimpleLightTask::HdxSimpleLightTask( HdxSimpleLightTask::~HdxSimpleLightTask() = default; +std::vector +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, @@ -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; @@ -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; @@ -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()); @@ -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()); @@ -225,11 +244,11 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate, continue; } - std::vector shadowMatrices = - lightShadowParams.shadowMatrix->Compute(_viewport, - windowPolicy); + const std::vector shadowMatrices = + _ComputeShadowMatrices( + camera, lightShadowParams.shadowMatrix); - if (shadowMatrices.size() == 0) { + if (shadowMatrices.empty()) { glfl.SetHasShadow(false); continue; } diff --git a/pxr/imaging/hdx/simpleLightTask.h b/pxr/imaging/hdx/simpleLightTask.h index 7e015d49cb..7f115937d2 100644 --- a/pxr/imaging/hdx/simpleLightTask.h +++ b/pxr/imaging/hdx/simpleLightTask.h @@ -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" @@ -42,6 +44,7 @@ PXR_NAMESPACE_OPEN_SCOPE class HdRenderIndex; class HdSceneDelegate; +class HdCamera; using HdRenderPassSharedPtr = std::shared_ptr; using HdStSimpleLightingShaderSharedPtr = @@ -77,6 +80,10 @@ class HdxSimpleLightTask : public HdTask void Execute(HdTaskContext* ctx) override; private: + std::vector _ComputeShadowMatrices( + const HdCamera * camera, + HdxShadowMatrixComputationSharedPtr const &computation) const; + SdfPath _cameraId; std::map _lightIds; SdfPathVector _lightIncludePaths; @@ -87,6 +94,8 @@ class HdxSimpleLightTask : public HdTask HdStSimpleLightingShaderSharedPtr _lightingShader; bool _enableShadows; GfVec4f _viewport; + CameraUtilFraming _framing; + std::pair _overrideWindowPolicy; // XXX: compatibility hack for passing some unit tests until we have // more formal material plumbing. @@ -115,6 +124,7 @@ struct HdxSimpleLightTaskParams { , lightExcludePaths() , enableShadows(false) , viewport(0.0f) + , overrideWindowPolicy{false, CameraUtilFit} , material() , sceneAmbient(0) {} @@ -124,6 +134,8 @@ struct HdxSimpleLightTaskParams { SdfPathVector lightExcludePaths; bool enableShadows; GfVec4f viewport; + CameraUtilFraming framing; + std::pair overrideWindowPolicy; // XXX: compatibility hack for passing some unit tests until we have // more formal material plumbing. diff --git a/pxr/imaging/hdx/unitTestDelegate.cpp b/pxr/imaging/hdx/unitTestDelegate.cpp index e3a5f405cb..0c495d9436 100644 --- a/pxr/imaging/hdx/unitTestDelegate.cpp +++ b/pxr/imaging/hdx/unitTestDelegate.cpp @@ -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]))); @@ -93,10 +93,18 @@ class ShadowMatrix : public HdxShadowMatrixComputation frustum.ComputeViewMatrix() * frustum.ComputeProjectionMatrix(); } - virtual std::vector Compute( - const GfVec4f &viewport, CameraUtilConformWindowPolicy policy) { - return std::vector(1, _shadowMatrix); + std::vector Compute( + const GfVec4f &viewport, + CameraUtilConformWindowPolicy policy) override { + return { _shadowMatrix }; } + + std::vector Compute( + const CameraUtilFraming &framing, + CameraUtilConformWindowPolicy policy) override { + return { _shadowMatrix }; + } + private: GfMatrix4d _shadowMatrix; }; diff --git a/pxr/imaging/hdx/version.h b/pxr/imaging/hdx/version.h index 062e23810d..d3e25d7e9c 100644 --- a/pxr/imaging/hdx/version.h +++ b/pxr/imaging/hdx/version.h @@ -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