Skip to content

Commit

Permalink
[usdImaging] Turn off invisible lights.
Browse files Browse the repository at this point in the history
- return 0 intensity when light is invisible
- add check for varying visibility
- add test for changes in light visibility; both manually editing the visibility and time varying visibility
Note:
- when lights have time varying visibility Prman treats the lights as invisible the entire time

Fixes #1277

(Internal change: 2092259)
  • Loading branch information
klucknav authored and pixar-oss committed Aug 21, 2020
1 parent 3a85c99 commit 16a59ef
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#usda 1.0

def Xform "Implicits" (
add variantSets = "shapeVariant"
)
{
variantSet "shapeVariant" = {
"Sphere" {
def Sphere "Ball"
{
}
}
}
}

def Sphere "frontSphere" {
double3 xformOp:translate = (2, 2, 2)
uniform token[] xformOpOrder = ["xformOp:translate"]
}

def Sphere "backSphere" {
double3 xformOp:translate = (-2, 2, 2)
uniform token[] xformOpOrder = ["xformOp:translate"]
rel material:binding = </Looks/Material_0>
}

def Scope "Looks"
{
def Material "Material_0"
{
token outputs:surface.connect = </Looks/Material_0/PbrPreview.outputs:surface>

def Shader "PbrPreview"
{
uniform token info:id = "UsdPreviewSurface"
color3f inputs:diffuseColor = (1,1,1)
float inputs:roughness = 0
color3f inputs:specularColor = (0.5, 0.5, 0.5)
int inputs:useSpecularWorkflow = 1
token outputs:surface
}
}
}

def Xform "lights"
{
def SphereLight "light1"
{
color3f color = (0, 0.5, 0)
float diffuse = 1
bool enableColorTemperature = 0
float exposure = 4
float intensity = 0.35
bool normalize = 0
float radius = 0.5
float specular = 1
bool treatAsPoint = 0
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (-3, 0, 2, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}
def SphereLight "light2"
{
color3f color = (0, 0, 0.5)
float diffuse = 1
bool enableColorTemperature = 0
float exposure = 4
float intensity = 0.35
bool normalize = 0
float radius = 0.5
float specular = 1
bool treatAsPoint = 0
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (3, 0, 2, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/pxrpythonsubst
#
# 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.
#


from __future__ import print_function
import sys
from pxr.Usdviewq.qt import QtWidgets


# Remove any unwanted visuals from the view.
def _modifySettings(appController):
appController._dataModel.viewSettings.showBBoxes = False
appController._dataModel.viewSettings.showHUD = False

# Turn off the Camera and Dome light.
def _turnLightsOff(appController):
appController._ui.actionAmbient_Only.setChecked(False)
appController._ambientOnlyClicked(False)

appController._ui.actionDomeLight.setChecked(False)
appController._onDomeLightClicked(False)

appController._stageView.updateGL()

# Take a shot of the viewport and save it to a file.
def _takeShot(appController, fileName):

QtWidgets.QApplication.processEvents()
appController._mainWindow.update()
viewportShot = appController.GrabViewportShot()
viewportShot.save(fileName, "PNG")

# Select one or more prim paths, then set visible state of those prims.
def _selectAndSetVisible(appController, visible, paths):
selection = appController._dataModel.selection
with selection.batchPrimChanges:
selection.clearPrims()
for path in paths:
selection.addPrimPath(path)

if visible:
appController.visSelectedPrims()
# We must processEvents after every call to activateSelectedPrims() so the
# activated PrimViewItems can repopulate. (See _primViewUpdateTimer in
# appController.py)
QtWidgets.QApplication.processEvents()
else:
appController.invisSelectedPrims()

# Test making a single light invisible then make it visible.
def _testSingleVisible(appController):
_selectAndSetVisible(appController, False, ["/lights/light1"])
_takeShot(appController, "singleInvisible1.png")
_selectAndSetVisible(appController, True, ["/lights/light1"])

_selectAndSetVisible(appController, False, ["/lights/light2"])
_takeShot(appController, "singleInvisible2.png")
_selectAndSetVisible(appController, True, ["/lights/light2"])

# Test all lights visible/invisible.
def _testAllVisible(appController):
_selectAndSetVisible(appController, False, ["/lights/light1"])
_selectAndSetVisible(appController, False, ["/lights/light2"])

_takeShot(appController, "allInvisible.png")

_selectAndSetVisible(appController, True, ["/lights/light1"])
_selectAndSetVisible(appController, True, ["/lights/light2"])

_takeShot(appController, "allVisible.png")


# Test that the complexity setting works properly in usdview.
def testUsdviewInputFunction(appController):
_modifySettings(appController)
_turnLightsOff(appController)
_testSingleVisible(appController)
_testAllVisible(appController)
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/pxrpythonsubst
#
# 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.
#


from __future__ import print_function
import sys
from pxr.Usdviewq.qt import QtWidgets


# Remove any unwanted visuals from the view.
def _modifySettings(appController):
appController._dataModel.viewSettings.showBBoxes = False
appController._dataModel.viewSettings.showHUD = False

# Turn off the Camera and Dome light.
def _turnLightsOff(appController):
appController._ui.actionAmbient_Only.setChecked(False)
appController._ambientOnlyClicked(False)

appController._ui.actionDomeLight.setChecked(False)
appController._onDomeLightClicked(False)

appController._stageView.updateGL()

# Take a shot of the viewport and save it to a file.
def _takeShot(appController, fileName):

QtWidgets.QApplication.processEvents()
appController._mainWindow.update()
viewportShot = appController.GrabViewportShot()
viewportShot.save(fileName, "PNG")

# Test light visibility varying over time.
def _testVaryingVisibility(appController):

appController.setFrame(0)
_takeShot(appController, "visible.png")
appController.setFrame(5)
_takeShot(appController, "invisible.png")


# Test that the complexity setting works properly in usdview.
def testUsdviewInputFunction(appController):
_modifySettings(appController)
_turnLightsOff(appController)

_testVaryingVisibility(appController)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#usda 1.0
(
defaultPrim = "Scene"
endTimeCode = 10
startTimeCode = 1
upAxis = "Y"
)
def Xform "Geom"
{
def Mesh "Plane"
{
float3[] extent = [(-2, -2, -2), (2, 2, 2)]
int[] faceVertexCounts = [4]
int[] faceVertexIndices = [0, 1, 2, 3]
point3f[] points = [(-2, -2, -2), (2, -2, -2), (2, 2, -2), (-2, 2, -2)]
color3f[] primvars:displayColor = [(0, 0.25, 0.5)]
float2[] primvars:st = [(0, 0), (1, 0), (1, 1), (0, 1)] (
interpolation = "vertex"
)
}
}

def Xform "lights"
{
def SphereLight "light"
{
color3f color = (0.5, 0.5, 0.75)
float diffuse = 1
bool enableColorTemperature = 0
float exposure = 4
float intensity = 0.35
bool normalize = 0
float radius = 0.5
float specular = 1
bool treatAsPoint = 0

token visibility = "inherited"
token visibility.timeSamples = {
0: "inherited",
5: "invisible",
}

matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 2, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}

}
13 changes: 11 additions & 2 deletions pxr/usdImaging/usdImaging/delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2765,9 +2765,18 @@ UsdImagingDelegate::GetLightParamValue(SdfPath const &id,
} else if (paramName == HdTokens->shadowLink) {
UsdCollectionAPI shadowLink = light.GetShadowLinkCollectionAPI();
return VtValue(_collectionCache.GetIdForCollection(shadowLink));
} else if (paramName == HdLightTokens->intensity && !_sceneLightsEnabled ) {
} else if (paramName == HdLightTokens->intensity) {
// return 0.0 intensity if scene lights are not enabled
return VtValue(0.0f);
if (!_sceneLightsEnabled) {
return VtValue(0.0f);
}
// return 0.0 intensity if the scene lights are not visible
_HdPrimInfo *primInfo = _GetHdPrimInfo(cachePath);
if (TF_VERIFY(primInfo)) {
if (!primInfo->adapter->GetVisible(primInfo->usdPrim, _time)){
return VtValue(0.0f);
}
}
}

// Fallback to USD attributes.
Expand Down
13 changes: 11 additions & 2 deletions pxr/usdImaging/usdImaging/lightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,22 @@ UsdImagingLightAdapter::TrackVariability(UsdPrim const& prim,
SdfPath const& cachePath,
HdDirtyBits* timeVaryingBits,
UsdImagingInstancerContext const*
instancerContext) const
instancerContext) const
{
// Discover time-varying transforms.
_IsTransformVarying(prim,
HdLight::DirtyBits::DirtyTransform,
UsdImagingTokens->usdVaryingXform,
timeVaryingBits);

// Discover time-varying visibility.
_IsVarying(prim,
UsdGeomTokens->visibility,
HdLight::DirtyBits::DirtyParams,
UsdImagingTokens->usdVaryingVisibility,
timeVaryingBits,
true);

// If any of the light attributes is time varying
// we will assume all light params are time-varying.
const std::vector<UsdAttribute> &attrs = prim.GetAttributes();
Expand Down Expand Up @@ -170,7 +178,8 @@ UsdImagingLightAdapter::MarkVisibilityDirty(UsdPrim const& prim,
SdfPath const& cachePath,
UsdImagingIndexProxy* index)
{
// TBD
static const HdDirtyBits paramsDirty = HdLight::DirtyParams;
index->MarkSprimDirty(cachePath, paramsDirty);
}

void
Expand Down

0 comments on commit 16a59ef

Please sign in to comment.