--- /dev/null
+#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"
+ }
+ }
+}
+
--- /dev/null
+#!/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)
HdPrman_CameraContext::HdPrman_CameraContext()
: _policy(CameraUtilFit)
+ , _disableDepthOfField(false)
, _shutterOpenTime(0.0f)
, _shutterCloseTime(1.0f)
, _shutteropeningPoints{ // matches RenderMan default
}
}
+void
+HdPrman_CameraContext::SetDisableDepthOfField(bool disableDepthOfField)
+{
+ if (_disableDepthOfField != disableDepthOfField) {
+ _disableDepthOfField = disableDepthOfField;
+ _invalid = true;
+ }
+}
+
bool
HdPrman_CameraContext::IsInvalid() const
{
// 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;
}
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
// 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
riley::ShadingNode::Type::k_Projection,
_ComputeProjectionShader(camera->GetProjection()),
s_projectionNodeName,
- _ComputeNodeParams(camera)
+ _ComputeNodeParams(camera, _disableDepthOfField)
};
const RtParamList params = _ComputeCameraParams(screenWindow, camera);
///
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; }
SdfPath _cameraPath;
CameraUtilFraming _framing;
CameraUtilConformWindowPolicy _policy;
+ bool _disableDepthOfField;
float _shutterOpenTime;
float _shutterCloseTime;
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
}
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.
// 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
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