[hdPrman] Use the recently added 'disableDepthOfField' RenderSettings option in HdPrman.
authorklucknav <klucknav@users.noreply.github.com>
Sat, 3 Feb 2024 03:25:46 +0000 (19:25 -0800)
committerpixar-oss <pixar-oss@users.noreply.github.com>
Sat, 3 Feb 2024 03:57:08 +0000 (19:57 -0800)
(Internal change: 2313517)

pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofDisabled.png [new file with mode: 0644]
pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofEnabled.png [new file with mode: 0644]
pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/grid_t [new file with mode: 0644]
pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/test.usda [new file with mode: 0644]
pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/testUsdviewRenderSettingsEdits.py [new file with mode: 0644]
third_party/renderman-25/plugin/hdPrman/cameraContext.cpp
third_party/renderman-25/plugin/hdPrman/cameraContext.h
third_party/renderman-25/plugin/hdPrman/renderSettings.cpp

diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofDisabled.png b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofDisabled.png
new file mode 100644 (file)
index 0000000..47eb30a
Binary files /dev/null and b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofDisabled.png differ
diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofEnabled.png b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofEnabled.png
new file mode 100644 (file)
index 0000000..42242d3
Binary files /dev/null and b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/basline/DofEnabled.png differ
diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/grid_t b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/grid_t
new file mode 100644 (file)
index 0000000..86ec1c8
Binary files /dev/null and b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/grid_t differ
diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/test.usda b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/test.usda
new file mode 100644 (file)
index 0000000..94dc750
--- /dev/null
@@ -0,0 +1,178 @@
+#usda 1.0
+(
+    upAxis = "Y"
+)
+
+def Scope "World"
+{
+    float xyz = 123
+
+    def Cube "GroundPlane" (
+        prepend apiSchemas = ["MaterialBindingAPI"]
+    )
+    {
+        float3 xformOp:scale = (5, 0.05, 5)
+        double xformOp:rotateY = -90
+        token[] xformOpOrder = ["xformOp:scale", "xformOp:rotateY"]
+        rel material:binding = </Material/Grid>
+    }
+
+    def Cube "Cube1" (
+        prepend apiSchemas = ["MaterialBindingAPI"]
+    )
+    {
+        double size = 1.2
+        double3 xformOp:translate = (3.85, 0.65, 3.85)
+        token[] xformOpOrder = ["xformOp:translate"]
+        color3f[] primvars:displayColor = [(0.8763, 0.2168, 0.2168)]
+        rel material:binding = </Material/Red>
+    }
+
+    def Cube "Cube2" (
+        prepend apiSchemas = ["MaterialBindingAPI"]
+    )
+    {
+        double size = 1.2
+        double3 xformOp:translate = (-3.85, 0.65, 3.85)
+        token[] xformOpOrder = ["xformOp:translate"]
+        token axis = "Y"
+        color3f[] primvars:displayColor = [(0.0436, 0.1311, 0.3634)]
+        rel material:binding = </Material/Blue>
+    }
+
+    def Cube "LargeCube" (
+        prepend apiSchemas = ["MaterialBindingAPI"]
+    )
+    {
+        double size = 2.5
+        double3 xformOp:translate = (0, 1.25, 0)
+        token[] xformOpOrder = ["xformOp:translate"]
+        rel material:binding = </Material/White>
+    }
+
+    def Scope "Lights" {
+
+        def RectLight "Light"
+        {
+            float inputs:intensity = 1
+            float inputs:exposure = 3
+            float inputs:width = 9.0
+            float inputs:height = 2.0
+            float inputs:focus = 1
+            double3 xformOp:translate = (3.6, 11.4, 6.0)
+            double3 xformOp:rotateXYZ = (-60, 31.5, 0)
+            token[] xformOpOrder = [
+                "xformOp:translate",
+                "xformOp:rotateXYZ",
+            ]
+        }
+    }
+}
+
+def Camera "main_cam"
+{
+    double3 xformOp:translate = (-1, 0, 20)
+    double3 xformOp:rotateXYZ = (-18, 45, 0.0)
+    token[] xformOpOrder = [
+        "xformOp:rotateXYZ",
+        "xformOp:translate",
+    ]
+    float2 clippingRange = (0.1, 10000)
+    float fStop = 1.5
+    float focalLength = 25.0
+    float focusDistance = 15
+}
+
+
+def Scope "Material"
+{
+    def Material "Grid"
+    {
+        token outputs:surface.connect = </Material/Grid/Surface.outputs:out>
+        def Shader "Surface"
+        {
+            config token info:id = "PxrSurface"
+            color3f inputs:diffuseColor.connect = </Material/Grid/Texture.outputs:resultRGB>
+            token outputs:out
+        }
+
+        def Shader "Texture"
+        {
+            config token info:id = "PxrTexture"
+            token inputs:filename = "grid_t"
+            color3f outputs:resultRGB
+        }
+    }
+
+    def Material "White"
+    {
+        token outputs:surface.connect = </Material/White/Surface.outputs:out>
+        def Shader "Surface"
+        {
+            config token info:id = "PxrSurface"
+            color3f inputs:diffuseColor = (1.0, 1.0, 1.0)
+            float inputs:diffuseGain = 0.5
+            token outputs:out
+        }
+    }
+    def Material "Red"
+    {
+        token outputs:surface.connect = </Material/Red/Surface.outputs:out>
+        def Shader "Surface"
+        {
+            config token info:id = "PxrSurface"
+            color3f inputs:diffuseColor = (0.8763, 0.2168, 0.2168)
+            token outputs:out
+        }
+    }
+    def Material "Blue"
+    {
+        token outputs:surface.connect = </Material/Blue/Surface.outputs:out>
+        def Shader "Surface"
+        {
+            config token info:id = "PxrSurface"
+            color3f inputs:diffuseColor = (0.0436, 0.1311, 0.3634)
+            token outputs:out
+        }
+    }
+}
+
+def Scope "Render"
+{
+    def RenderSettings "Settings"
+    {
+        rel camera = </main_cam>
+        rel products = [
+            </Render/Product>,
+        ]
+        int2 resolution = (512, 512)
+        int ri:hider:maxsamples = 4
+        int ri:hider:minsamples = 4
+        float ri:Ri:PixelVariance = 0.01
+        int ri:trace:maxdepth = 1
+    }
+
+    def RenderProduct "Product"
+    {
+        rel orderedVars = [
+            </Render/Vars/Ci>,
+            </Render/Vars/a>,
+        ]
+        token productName = "primary.exr"
+        bool disableDepthOfField = false
+    }
+    def Scope "Vars"
+    {
+        def RenderVar "Ci"
+        {
+            string sourceName = "Ci"
+        }
+
+        def RenderVar "a"
+        {
+            token dataType = "float"
+            string sourceName = "a"
+        }
+    }
+}
+
diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/testUsdviewRenderSettingsEdits.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewRenderSettingsEdits/testUsdviewRenderSettingsEdits.py
new file mode 100644 (file)
index 0000000..8aed292
--- /dev/null
@@ -0,0 +1,54 @@
+#!/pxrpythonsubst
+#
+# Copyright 2023 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.
+#
+from pxr import UsdShade
+
+# Remove any unwanted visuals from the view, and enable autoClip
+def _modifySettings(appController):
+    appController._dataModel.viewSettings.showBBoxes = False
+    appController._dataModel.viewSettings.showHUD = False
+    appController._dataModel.viewSettings.autoComputeClippingPlanes = True
+
+# Enable/Disable the Depth of Field attribute on the given RenderProduct
+def _updateAttribute(appController, productPath, attrName, attrValue):
+    stage = appController._dataModel.stage
+    layer = stage.GetSessionLayer()
+    stage.SetEditTarget(layer)
+
+    product = stage.GetPrimAtPath(productPath)
+    attr = product.GetAttribute(attrName)
+    attr.Set(attrValue)
+
+
+# Test changing the connected SampleFilter.
+def testUsdviewInputFunction(appController):
+    _modifySettings(appController)
+
+    productPath = '/Render/Product'
+
+    appController._takeShot("DofEnabled.png", waitForConvergence=True)
+
+    # Disable Depth of Field attribute
+    _updateAttribute(appController, productPath, 'disableDepthOfField', True)
+    appController._takeShot("DofDisabled.png", waitForConvergence=True)
index dd0ba76373cf91f05a19c48a0ee8bce67e6ed616..2a2d1d0f991de17fb6369c648bac58a26067fe70 100644 (file)
@@ -41,6 +41,7 @@ static const RtUString s_projectionNodeName("cam_projection");
 
 HdPrman_CameraContext::HdPrman_CameraContext()
   : _policy(CameraUtilFit)
+  , _disableDepthOfField(false)
   , _shutterOpenTime(0.0f)
   , _shutterCloseTime(1.0f)
   , _shutteropeningPoints{ // matches RenderMan default
@@ -136,6 +137,15 @@ HdPrman_CameraContext::SetFallbackShutterCurve(bool isInteractive)
     }
 }
 
+void
+HdPrman_CameraContext::SetDisableDepthOfField(bool disableDepthOfField)
+{
+    if (_disableDepthOfField != disableDepthOfField) {
+        _disableDepthOfField = disableDepthOfField;
+        _invalid = true;
+    }
+}
+
 bool
 HdPrman_CameraContext::IsInvalid() const
 {
@@ -286,7 +296,8 @@ _ComputeProjectionShader(const HdCamera::Projection projection)
 
 // Compute parameters for the camera riley::ShadingNode for perspective camera
 RtParamList
-_ComputePerspectiveNodeParams(const HdPrmanCamera * const camera)
+_ComputePerspectiveNodeParams(
+    const HdPrmanCamera * const camera, bool disableDepthOfField)
 {
     RtParamList result;
 
@@ -321,12 +332,13 @@ _ComputePerspectiveNodeParams(const HdPrmanCamera * const camera)
     }
 
     const float fStop = camera->GetFStop();
-    if (fStop > 0.0f && focusDistance > 0.0f) {
-        result.SetFloat(RixStr.k_fStop, fStop);
-    } else {
-        // If values are bogus, disable depth of field by setting
-        // ininie f-Stop and a sane value for focalDistance.
+    if (disableDepthOfField || fStop <= 0.0f || focusDistance <= 0.0f) {
+        // If depth of field is disabled or the values are bogus, 
+        // disable depth of field by setting f-Stop to infinity, 
+        // and a sane value for focalDistance. 
         result.SetFloat(RixStr.k_fStop, RI_INFINITY);
+    } else {
+        result.SetFloat(RixStr.k_fStop, fStop);
     }
 
     // Not setting fov frame begin/end - thus we do not support motion blur
@@ -377,17 +389,17 @@ _ComputeOrthographicNodeParams(const HdPrmanCamera * const camera)
 // Compute parameters for the camera riley::ShadingNode
 static
 RtParamList
-_ComputeNodeParams(const HdPrmanCamera * const camera)
+_ComputeNodeParams(const HdPrmanCamera * const camera, bool disableDepthOfField)
 {
     switch(camera->GetProjection()) {
     case HdCamera::Perspective:
-        return _ComputePerspectiveNodeParams(camera);
+        return _ComputePerspectiveNodeParams(camera, disableDepthOfField);
     case HdCamera::Orthographic:
         return _ComputeOrthographicNodeParams(camera);
     }
 
     // Make compiler happy
-    return _ComputePerspectiveNodeParams(camera);
+    return _ComputePerspectiveNodeParams(camera, disableDepthOfField);
 }
 
 // Compute params given to Riley::ModifyCamera
@@ -561,7 +573,7 @@ HdPrman_CameraContext::_UpdateRileyCamera(
         riley::ShadingNode::Type::k_Projection,
         _ComputeProjectionShader(camera->GetProjection()),
         s_projectionNodeName,
-        _ComputeNodeParams(camera)
+        _ComputeNodeParams(camera, _disableDepthOfField)
     };
 
     const RtParamList params = _ComputeCameraParams(screenWindow, camera);
index 87c6fbde99260e84f0a8aa038e30485c2720013e..2c01324d390b25d6afb02da0db82a9e391832e3d 100644 (file)
@@ -146,6 +146,9 @@ public:
     ///
     void SetFallbackShutterCurve(bool isInteractive);
 
+    /// When depth of field is disabled the fstop is set to infinity.
+    void SetDisableDepthOfField(bool disableDepthOfField);
+
     /// Path of current camera in render index.
     const SdfPath &GetCameraPath() const { return _cameraPath; }
 
@@ -186,6 +189,7 @@ private:
     SdfPath _cameraPath;
     CameraUtilFraming _framing;
     CameraUtilConformWindowPolicy _policy;
+    bool _disableDepthOfField;
 
     float _shutterOpenTime;
     float _shutterCloseTime;
index 8db5f1772df73998445d7672f84933e58e10729e..17dafa3d53df6eec5db1509d298b22d3ae01e813 100644 (file)
@@ -167,6 +167,9 @@ _UpdateCameraContextFromProduct(
             displayWindow, dataWindow, product.pixelAspectRatio));
     cameraContext->SetWindowPolicy(
         HdUtils::ToConformWindowPolicy(product.aspectRatioConformPolicy));
+#if HD_API_VERSION >= 64
+    cameraContext->SetDisableDepthOfField(product.disableDepthOfField);
+#endif
 }
 
 // Update the riley camera params using state on the camera Sprim and the
@@ -564,11 +567,11 @@ HdPrman_RenderSettings::_ProcessRenderTerminals(
 }
 
 void
-HdPrman_RenderSettings::_ProcessRenderProducts(
-    HdPrman_RenderParam *param)
+HdPrman_RenderSettings::_ProcessRenderProducts(HdPrman_RenderParam *param)
 {
-    const bool hasRenderProducts = !GetRenderProducts().empty();
-
+    if (GetRenderProducts().empty()) {
+        return;
+    }
     // Fallback path for apps using an older version of Hydra wherein 
     // the computed "unioned shutter interval" on the render settings 
     // prim via HdsiRenderSettingsFilteringSceneIndex is not available.
@@ -577,7 +580,7 @@ HdPrman_RenderSettings::_ProcessRenderProducts(
     // during HdPrmanCamera::Sync. The riley shutter interval needs to
     // be set before any time-sampled primvars are synced.
     // 
-    if (GetShutterInterval().IsEmpty() && hasRenderProducts) {
+    if (GetShutterInterval().IsEmpty()) {
         // Set the camera path here so that HdPrmanCamera::Sync can detect
         // whether it is syncing the current camera to set the riley shutter
         // interval. See SetRileyShutterIntervalFromCameraContextCameraPath
@@ -585,6 +588,11 @@ HdPrman_RenderSettings::_ProcessRenderProducts(
         const SdfPath &cameraPath = GetRenderProducts().at(0).cameraPath;
         param->GetCameraContext().SetCameraPath(cameraPath);
     }
+
+    // This will override the f-stop value on the camera
+    param->GetCameraContext().SetDisableDepthOfField(
+        GetRenderProducts().at(0).disableDepthOfField);
+    
 }
 
 PXR_NAMESPACE_CLOSE_SCOPE