Skip to content

Commit

Permalink
Improve authoring of quad and mesh lights (Autodesk#1957)
Browse files Browse the repository at this point in the history
* Improve authoring of quad & mesh lights Autodesk#1955

* Add changelog

* Update tests with Mesh light improvements
  • Loading branch information
sebastienblor authored Jul 8, 2024
1 parent bd7ee1a commit 0be2118
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [usd#1939](https://github.com/Autodesk/arnold-usd/issues/1939) - Support primvars as user data on lights
- [usd#1950](https://github.com/Autodesk/arnold-usd/issues/1950) - Avoid creating a render delegate in batch mode when ARNOLD_FORCE_ARBORT_ON_LICENSE_FAIL is set and the license isn't found.
- [usd#1918](https://github.com/Autodesk/arnold-usd/issues/1918) - Use batch render sessions for husk renders
- [usd#1955](https://github.com/Autodesk/arnold-usd/issues/1955) - Improve USD authoring of quad and mesh lights in the writer

### Bug fixes
- [usd#1861](https://github.com/Autodesk/arnold-usd/issues/1861) - Fix BasisCurves disappearing on interactive updates
Expand Down
3 changes: 3 additions & 0 deletions libs/common/constant_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ ASTR2(primvars_arnold, "primvars:arnold");
ASTR2(primvars_arnold_light, "primvars:arnold:light");
ASTR2(log_file, "log:file");
ASTR2(log_verbosity, "log:verbosity");
ASTR2(outputs_color, "outputs:color");
ASTR2(primvars_arnold_light_shaders, "primvars:arnold:light:shaders");
ASTR2(primvars_arnold_shaders, "primvars:arnold:shaders");
ASTR2(primvars_arnold_smoothing, "primvars:arnold:smoothing");
ASTR2(primvars_arnold_subdiv_iterations, "primvars:arnold:subdiv_iterations");
ASTR2(primvars_arnold_subdiv_type, "primvars:arnold:subdiv_type");
Expand Down
101 changes: 67 additions & 34 deletions libs/translator/writer/write_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ PXR_NAMESPACE_USING_DIRECTIVE

namespace {

bool writeArnoldLightShader(const AtNode* node, UsdPrim& prim,
UsdArnoldPrimWriter &primWriter, UsdArnoldWriter &writer, const TfToken& lightShaderAttr)
{
AtNode *linkedColor = AiNodeGetLink(node, str::color);
if (!linkedColor)
return false;
std::string nodeGraphName = prim.GetPath().GetString() + "/light_shader";
SdfPath nodeGraphPath(nodeGraphName);
UsdStageRefPtr stage = writer.GetUsdStage();
UsdPrim nodeGraphPrim = stage->DefinePrim(nodeGraphPath, str::t_ArnoldNodeGraph);

UsdAttribute arnoldShaderAttr =
prim.CreateAttribute(lightShaderAttr,
SdfValueTypeNames->String, false);
arnoldShaderAttr.Set(nodeGraphPrim.GetPath().GetString());

primWriter.WriteAttribute(node, "color", nodeGraphPrim,
nodeGraphPrim.CreateAttribute(str::t_outputs_color,
SdfValueTypeNames->Token, false), writer);
return true;
}

void writeLightCommon(const AtNode *node, UsdPrim &prim, UsdArnoldPrimWriter &primWriter, UsdArnoldWriter &writer)
{
#if PXR_VERSION >= 2111
Expand Down Expand Up @@ -88,17 +110,20 @@ void UsdArnoldWriteDomeLight::Write(const AtNode *node, UsdArnoldWriter &writer)
writeLightCommon(node, prim, *this, writer);
_WriteMatrix(light, node, writer);

AtNode *linkedTexture = AiNodeGetLink(node, "color");
static AtString imageStr("image");
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
// a texture is connected to the color attribute, so we want to export it to
// the Dome's TextureFile attribute
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
SdfAssetPath assetPath(filename.c_str());
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
light.GetColorAttr().ClearConnections();
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
if (writeArnoldLightShader(node, prim, *this, writer, str::t_primvars_arnold_shaders)) {
_exportedAttrs.insert("color");

AtNode *linkedTexture = AiNodeGetLink(node, "color");
static AtString imageStr("image");
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
// a texture is connected to the color attribute, so we want to export it to
// the Dome's TextureFile attribute
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
SdfAssetPath assetPath(filename.c_str());
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
light.GetColorAttr().ClearConnections();
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
}
}
AtString textureFormat = AiNodeGetStr(node, AtString("format"));
static AtString latlongStr("latlong");
Expand Down Expand Up @@ -174,17 +199,20 @@ void UsdArnoldWriteRectLight::Write(const AtNode *node, UsdArnoldWriter &writer)
_WriteMatrix(light, node, writer);
WriteAttribute(node, "normalize", prim, light.GetNormalizeAttr(), writer);

AtNode *linkedTexture = AiNodeGetLink(node, AtString("color"));
static AtString imageStr("image");
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
// a texture is connected to the color attribute, so we want to export it to
// the Dome's TextureFile attribute
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
SdfAssetPath assetPath(filename.c_str());
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
light.GetColorAttr().ClearConnections();
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
if (writeArnoldLightShader(node, prim, *this, writer, str::t_primvars_arnold_shaders)) {
_exportedAttrs.insert("color");

AtNode *linkedTexture = AiNodeGetLink(node, AtString("color"));
static AtString imageStr("image");
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
// a texture is connected to the color attribute, so we want to export it to
// the Dome's TextureFile attribute
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
SdfAssetPath assetPath(filename.c_str());
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
light.GetColorAttr().ClearConnections();
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
}
}

float width = 1.f;
Expand Down Expand Up @@ -240,21 +268,26 @@ void UsdArnoldWriteGeometryLight::Write(const AtNode *node, UsdArnoldWriter &wri
{
std::string nodeName = GetArnoldNodeName(node, writer);
UsdStageRefPtr stage = writer.GetUsdStage(); // Get the USD stage defined in the writer
SdfPath objPath(nodeName);
writer.CreateHierarchy(objPath);
UsdLuxGeometryLight light = UsdLuxGeometryLight::Define(stage, objPath);
UsdPrim prim = light.GetPrim();

writeLightCommon(node, prim, *this, writer);
WriteAttribute(node, "normalize", prim, light.GetNormalizeAttr(), writer);
AtNode *meshNode = (AtNode *)AiNodeGetPtr(node, AtString("mesh"));
if (!meshNode)
return;

writer.WritePrimitive(meshNode);
std::string meshName = GetArnoldNodeName(meshNode, writer);
SdfPath meshPath(meshName);
UsdPrim mesh = stage->GetPrimAtPath(meshPath);

UsdAttribute lightAttr = mesh.CreateAttribute(str::t_primvars_arnold_light,
SdfValueTypeNames->Bool, false);
lightAttr.Set(true);

_exportedAttrs.insert("mesh");
// We're not authoring the light matrix, so that it's consistent with the mesh
_exportedAttrs.insert("matrix");
AtNode *mesh = (AtNode *)AiNodeGetPtr(node, AtString("mesh"));
if (mesh) {
writer.WritePrimitive(mesh);
std::string meshName = GetArnoldNodeName(mesh, writer);
light.CreateGeometryRel().AddTarget(SdfPath(meshName));
}
_exportedAttrs.insert("mesh");
_WriteArnoldParameters(node, writer, prim, "primvars:arnold");

if (writeArnoldLightShader(node, mesh, *this, writer, str::t_primvars_arnold_light_shaders))
_exportedAttrs.insert("color");

_WriteArnoldParameters(node, writer, mesh, "primvars:arnold:light");
}
2 changes: 1 addition & 1 deletion testsuite/groups
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ darwin:
#######################
# Tests that can be run in hydra mode

hydra: test_0000 test_0001 test_0002 test_0003 test_0004 test_0005 test_0006 test_0007 test_0008 test_0009 test_0010 test_0011 test_0012 test_0014 test_0016 test_0017 test_0018 test_0019 test_0020 test_0021 test_0022 test_0023 test_0024 test_0025 test_0026 test_0027 test_0028 test_0029 test_0030 test_0031 test_0032 test_0033 test_0034 test_0037 test_0038 test_0041 test_0046 test_0048 test_0049 test_0050 test_0051 test_0052 test_0055 test_0056 test_0057 test_0058 test_0059 test_0060 test_0062 test_0064 test_0066 test_0067 test_0068 test_0071 test_0072 test_0073 test_0074 test_0077 test_0080 test_0081 test_0082 test_0083 test_0084 test_0086 test_0087 test_0088 test_0091 test_0093 test_0094 test_0097 test_0099 test_0104 test_0105 test_0107 test_0108 test_0110 test_0112 test_0113 test_0114 test_0115 test_0117 test_0120 test_0121 test_0122 test_0123 test_0125 test_0126 test_0127 test_0128 test_0129 test_0130 test_0132 test_0133 test_0135 test_0139 test_0140 test_0141 test_0142 test_0143 test_0144 test_0145 test_0148 test_0149 test_0150 test_0151 test_0158 test_0159 test_0160 test_0161 test_0162 test_0163 test_0164 test_0165 test_0166 test_0168 test_0169 test_0170 test_0171 test_0172 test_0173 test_0174 test_0175 test_0177 test_0178 test_0180 test_0183 test_0184 test_0186 test_0187 test_0188 test_0189 test_0191 test_0194 test_0195 test_0196 test_0197 test_0198 test_0200 test_0201 test_0202 test_0204 test_0205 test_0206 test_0207 test_0215 test_0216 test_0217 test_0219 test_0220 test_0221 test_0222 test_0223 test_0225 test_0227 test_0228 test_0229 test_0230 test_0231 test_0232 test_0233 test_0234 test_0238 test_0239 test_0240 test_0242 test_0243 test_0244 test_0245 test_0299 test_0316 test_0317 test_0739 test_1181 test_1204 test_1209 test_1223 test_1225 test_1238 test_1245 test_1262 test_1294 test_1309 test_1311 test_1313 test_1329 test_1333 test_1334 test_1346 test_1354 test_1416 test_1420 test_1426 test_1427.1 test_1427.2 test_1427.3 test_1430 test_1433 test_1435 test_1438 test_1442 test_1457 test_1486 test_1499 test_1524 test_1525 test_1530 test_1535 test_1538 test_1546 test_1547.1 test_1547.2 test_1550 test_1567 test_1588 test_1590 test_1593 test_1607 test_1613 test_1625 test_1632 test_1635 test_1654 test_1657 test_1678 test_1705 test_1718 test_1726 test_1730 test_1735 test_1769 test_1772 test_1776 test_1814 test_1868 test_1873 test_1878 test_1881 test_1894 test_1906 test_1923 test_1939 test_1940 test_14028
hydra: test_0000 test_0001 test_0002 test_0003 test_0004 test_0005 test_0006 test_0007 test_0008 test_0009 test_0010 test_0011 test_0012 test_0014 test_0016 test_0017 test_0018 test_0019 test_0020 test_0021 test_0022 test_0023 test_0024 test_0025 test_0026 test_0027 test_0028 test_0029 test_0030 test_0031 test_0032 test_0033 test_0034 test_0037 test_0038 test_0041 test_0046 test_0048 test_0049 test_0050 test_0051 test_0052 test_0053 test_0055 test_0056 test_0057 test_0058 test_0059 test_0060 test_0062 test_0064 test_0066 test_0067 test_0068 test_0071 test_0072 test_0073 test_0074 test_0076 test_0077 test_0080 test_0081 test_0082 test_0083 test_0084 test_0086 test_0087 test_0088 test_0091 test_0093 test_0094 test_0097 test_0099 test_0104 test_0105 test_0107 test_0108 test_0110 test_0111 test_0112 test_0113 test_0114 test_0115 test_0117 test_0120 test_0121 test_0122 test_0123 test_0125 test_0126 test_0127 test_0128 test_0129 test_0130 test_0132 test_0133 test_0135 test_0139 test_0140 test_0141 test_0142 test_0143 test_0144 test_0145 test_0148 test_0149 test_0150 test_0151 test_0158 test_0159 test_0160 test_0161 test_0162 test_0163 test_0164 test_0165 test_0166 test_0168 test_0169 test_0170 test_0171 test_0172 test_0173 test_0174 test_0175 test_0177 test_0178 test_0180 test_0183 test_0184 test_0186 test_0187 test_0188 test_0189 test_0191 test_0194 test_0195 test_0196 test_0197 test_0198 test_0200 test_0201 test_0202 test_0204 test_0205 test_0206 test_0207 test_0209 test_0215 test_0216 test_0217 test_0219 test_0220 test_0221 test_0222 test_0223 test_0225 test_0227 test_0228 test_0229 test_0230 test_0231 test_0232 test_0233 test_0234 test_0238 test_0239 test_0240 test_0242 test_0243 test_0244 test_0245 test_0299 test_0316 test_0317 test_0739 test_1181 test_1204 test_1209 test_1223 test_1225 test_1238 test_1245 test_1262 test_1294 test_1309 test_1311 test_1313 test_1329 test_1333 test_1334 test_1346 test_1354 test_1416 test_1420 test_1426 test_1427.1 test_1427.2 test_1427.3 test_1430 test_1433 test_1435 test_1438 test_1442 test_1457 test_1486 test_1499 test_1524 test_1525 test_1530 test_1535 test_1538 test_1546 test_1547.1 test_1547.2 test_1550 test_1567 test_1588 test_1590 test_1593 test_1607 test_1613 test_1625 test_1632 test_1635 test_1654 test_1657 test_1678 test_1705 test_1718 test_1726 test_1730 test_1735 test_1769 test_1772 test_1776 test_1814 test_1868 test_1873 test_1878 test_1881 test_1894 test_1906 test_1923 test_1939 test_1940 test_14028

# Tests in this group will never be executed (you can use it to temporarily disable some tests and/or groups)
ignore:
Expand Down
2 changes: 1 addition & 1 deletion testsuite/test_0115/README
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Motion range in mesh lights

author: sebastien ortega

PARAMS: {'resaved':'usda'}
PARAMS: {'resaved':'usda', 'diff_hardfail': 0.05}
2 changes: 1 addition & 1 deletion testsuite/test_0209/README
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Geometry Lights

author: sebastien.ortega

PARAMS: {'scene':'test.usda', 'diff_hardfail':0.03}
PARAMS: {'scene':'test.usda', 'diff_hardfail':0.04}
21 changes: 10 additions & 11 deletions testsuite/test_0209/data/test.usda
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,9 @@ def Xform "pCylinder1"
{
def Xform "light_pCylinder1"
{
def GeometryLight "light_pCylinder1Shape"
def "light_pCylinder1Shape"
{
prepend rel geometry = </pCylinder1/light_pCylinder1/light_pCylinder1Shape/mesh>
color3f inputs:color = (1, 1, 1)
float inputs:diffuse = 1
float inputs:exposure = 5
float inputs:intensity = 5.5755396
bool inputs:normalize = 1
float inputs:specular = 1

uniform token[] xformOpOrder = ["xformOp:transform"]


def Mesh "mesh"
{
uniform bool doubleSided = 1
Expand All @@ -92,6 +83,14 @@ def Xform "pCylinder1"
uniform token subdivisionScheme = "none"
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 0.24575498700141907, -3.9600954055786133, 0), (0, 0.9980799555778503, 0.06193869188427925, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]

bool primvars:arnold:light = 1
color3f primvars:arnold:light:color = (1, 1, 1)
float primvars:arnold:light:diffuse = 1
float primvars:arnold:light:exposure = 5
float primvars:arnold:light:intensity = 5.5755396
bool primvars:arnold:light:normalize = 1
float primvars:arnold:light:specular = 1
}


Expand Down

0 comments on commit 0be2118

Please sign in to comment.