Skip to content

Commit 0be2118

Browse files
Improve authoring of quad and mesh lights (Autodesk#1957)
* Improve authoring of quad & mesh lights Autodesk#1955 * Add changelog * Update tests with Mesh light improvements
1 parent bd7ee1a commit 0be2118

File tree

7 files changed

+84
-48
lines changed

7 files changed

+84
-48
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [usd#1939](https://github.com/Autodesk/arnold-usd/issues/1939) - Support primvars as user data on lights
99
- [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.
1010
- [usd#1918](https://github.com/Autodesk/arnold-usd/issues/1918) - Use batch render sessions for husk renders
11+
- [usd#1955](https://github.com/Autodesk/arnold-usd/issues/1955) - Improve USD authoring of quad and mesh lights in the writer
1112

1213
### Bug fixes
1314
- [usd#1861](https://github.com/Autodesk/arnold-usd/issues/1861) - Fix BasisCurves disappearing on interactive updates

libs/common/constant_strings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ ASTR2(primvars_arnold, "primvars:arnold");
8383
ASTR2(primvars_arnold_light, "primvars:arnold:light");
8484
ASTR2(log_file, "log:file");
8585
ASTR2(log_verbosity, "log:verbosity");
86+
ASTR2(outputs_color, "outputs:color");
87+
ASTR2(primvars_arnold_light_shaders, "primvars:arnold:light:shaders");
88+
ASTR2(primvars_arnold_shaders, "primvars:arnold:shaders");
8689
ASTR2(primvars_arnold_smoothing, "primvars:arnold:smoothing");
8790
ASTR2(primvars_arnold_subdiv_iterations, "primvars:arnold:subdiv_iterations");
8891
ASTR2(primvars_arnold_subdiv_type, "primvars:arnold:subdiv_type");

libs/translator/writer/write_light.cpp

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ PXR_NAMESPACE_USING_DIRECTIVE
4040

4141
namespace {
4242

43+
bool writeArnoldLightShader(const AtNode* node, UsdPrim& prim,
44+
UsdArnoldPrimWriter &primWriter, UsdArnoldWriter &writer, const TfToken& lightShaderAttr)
45+
{
46+
AtNode *linkedColor = AiNodeGetLink(node, str::color);
47+
if (!linkedColor)
48+
return false;
49+
std::string nodeGraphName = prim.GetPath().GetString() + "/light_shader";
50+
SdfPath nodeGraphPath(nodeGraphName);
51+
UsdStageRefPtr stage = writer.GetUsdStage();
52+
UsdPrim nodeGraphPrim = stage->DefinePrim(nodeGraphPath, str::t_ArnoldNodeGraph);
53+
54+
UsdAttribute arnoldShaderAttr =
55+
prim.CreateAttribute(lightShaderAttr,
56+
SdfValueTypeNames->String, false);
57+
arnoldShaderAttr.Set(nodeGraphPrim.GetPath().GetString());
58+
59+
primWriter.WriteAttribute(node, "color", nodeGraphPrim,
60+
nodeGraphPrim.CreateAttribute(str::t_outputs_color,
61+
SdfValueTypeNames->Token, false), writer);
62+
return true;
63+
}
64+
4365
void writeLightCommon(const AtNode *node, UsdPrim &prim, UsdArnoldPrimWriter &primWriter, UsdArnoldWriter &writer)
4466
{
4567
#if PXR_VERSION >= 2111
@@ -88,17 +110,20 @@ void UsdArnoldWriteDomeLight::Write(const AtNode *node, UsdArnoldWriter &writer)
88110
writeLightCommon(node, prim, *this, writer);
89111
_WriteMatrix(light, node, writer);
90112

91-
AtNode *linkedTexture = AiNodeGetLink(node, "color");
92-
static AtString imageStr("image");
93-
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
94-
// a texture is connected to the color attribute, so we want to export it to
95-
// the Dome's TextureFile attribute
96-
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
97-
SdfAssetPath assetPath(filename.c_str());
98-
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
99-
light.GetColorAttr().ClearConnections();
100-
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
113+
if (writeArnoldLightShader(node, prim, *this, writer, str::t_primvars_arnold_shaders)) {
101114
_exportedAttrs.insert("color");
115+
116+
AtNode *linkedTexture = AiNodeGetLink(node, "color");
117+
static AtString imageStr("image");
118+
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
119+
// a texture is connected to the color attribute, so we want to export it to
120+
// the Dome's TextureFile attribute
121+
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
122+
SdfAssetPath assetPath(filename.c_str());
123+
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
124+
light.GetColorAttr().ClearConnections();
125+
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
126+
}
102127
}
103128
AtString textureFormat = AiNodeGetStr(node, AtString("format"));
104129
static AtString latlongStr("latlong");
@@ -174,17 +199,20 @@ void UsdArnoldWriteRectLight::Write(const AtNode *node, UsdArnoldWriter &writer)
174199
_WriteMatrix(light, node, writer);
175200
WriteAttribute(node, "normalize", prim, light.GetNormalizeAttr(), writer);
176201

177-
AtNode *linkedTexture = AiNodeGetLink(node, AtString("color"));
178-
static AtString imageStr("image");
179-
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
180-
// a texture is connected to the color attribute, so we want to export it to
181-
// the Dome's TextureFile attribute
182-
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
183-
SdfAssetPath assetPath(filename.c_str());
184-
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
185-
light.GetColorAttr().ClearConnections();
186-
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
202+
if (writeArnoldLightShader(node, prim, *this, writer, str::t_primvars_arnold_shaders)) {
187203
_exportedAttrs.insert("color");
204+
205+
AtNode *linkedTexture = AiNodeGetLink(node, AtString("color"));
206+
static AtString imageStr("image");
207+
if (linkedTexture && AiNodeIs(linkedTexture, imageStr)) {
208+
// a texture is connected to the color attribute, so we want to export it to
209+
// the Dome's TextureFile attribute
210+
AtString filename = AiNodeGetStr(linkedTexture, AtString("filename"));
211+
SdfAssetPath assetPath(filename.c_str());
212+
writer.SetAttribute(light.GetTextureFileAttr(), assetPath);
213+
light.GetColorAttr().ClearConnections();
214+
writer.SetAttribute(light.GetColorAttr(), GfVec3f(1.f, 1.f, 1.f));
215+
}
188216
}
189217

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

248-
writeLightCommon(node, prim, *this, writer);
249-
WriteAttribute(node, "normalize", prim, light.GetNormalizeAttr(), writer);
272+
AtNode *meshNode = (AtNode *)AiNodeGetPtr(node, AtString("mesh"));
273+
if (!meshNode)
274+
return;
275+
276+
writer.WritePrimitive(meshNode);
277+
std::string meshName = GetArnoldNodeName(meshNode, writer);
278+
SdfPath meshPath(meshName);
279+
UsdPrim mesh = stage->GetPrimAtPath(meshPath);
280+
281+
UsdAttribute lightAttr = mesh.CreateAttribute(str::t_primvars_arnold_light,
282+
SdfValueTypeNames->Bool, false);
283+
lightAttr.Set(true);
284+
285+
_exportedAttrs.insert("mesh");
250286
// We're not authoring the light matrix, so that it's consistent with the mesh
251287
_exportedAttrs.insert("matrix");
252-
AtNode *mesh = (AtNode *)AiNodeGetPtr(node, AtString("mesh"));
253-
if (mesh) {
254-
writer.WritePrimitive(mesh);
255-
std::string meshName = GetArnoldNodeName(mesh, writer);
256-
light.CreateGeometryRel().AddTarget(SdfPath(meshName));
257-
}
258-
_exportedAttrs.insert("mesh");
259-
_WriteArnoldParameters(node, writer, prim, "primvars:arnold");
288+
289+
if (writeArnoldLightShader(node, mesh, *this, writer, str::t_primvars_arnold_light_shaders))
290+
_exportedAttrs.insert("color");
291+
292+
_WriteArnoldParameters(node, writer, mesh, "primvars:arnold:light");
260293
}

testsuite/groups

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ darwin:
4141
#######################
4242
# Tests that can be run in hydra mode
4343

44-
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
44+
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
4545

4646
# Tests in this group will never be executed (you can use it to temporarily disable some tests and/or groups)
4747
ignore:

testsuite/test_0115/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Motion range in mesh lights
22

33
author: sebastien ortega
44

5-
PARAMS: {'resaved':'usda'}
5+
PARAMS: {'resaved':'usda', 'diff_hardfail': 0.05}

testsuite/test_0209/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Geometry Lights
22

33
author: sebastien.ortega
44

5-
PARAMS: {'scene':'test.usda', 'diff_hardfail':0.03}
5+
PARAMS: {'scene':'test.usda', 'diff_hardfail':0.04}

testsuite/test_0209/data/test.usda

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,9 @@ def Xform "pCylinder1"
6161
{
6262
def Xform "light_pCylinder1"
6363
{
64-
def GeometryLight "light_pCylinder1Shape"
64+
def "light_pCylinder1Shape"
6565
{
66-
prepend rel geometry = </pCylinder1/light_pCylinder1/light_pCylinder1Shape/mesh>
67-
color3f inputs:color = (1, 1, 1)
68-
float inputs:diffuse = 1
69-
float inputs:exposure = 5
70-
float inputs:intensity = 5.5755396
71-
bool inputs:normalize = 1
72-
float inputs:specular = 1
73-
74-
uniform token[] xformOpOrder = ["xformOp:transform"]
75-
66+
7667
def Mesh "mesh"
7768
{
7869
uniform bool doubleSided = 1
@@ -92,6 +83,14 @@ def Xform "pCylinder1"
9283
uniform token subdivisionScheme = "none"
9384
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 0.24575498700141907, -3.9600954055786133, 0), (0, 0.9980799555778503, 0.06193869188427925, 0), (0, 0, 0, 1) )
9485
uniform token[] xformOpOrder = ["xformOp:transform"]
86+
87+
bool primvars:arnold:light = 1
88+
color3f primvars:arnold:light:color = (1, 1, 1)
89+
float primvars:arnold:light:diffuse = 1
90+
float primvars:arnold:light:exposure = 5
91+
float primvars:arnold:light:intensity = 5.5755396
92+
bool primvars:arnold:light:normalize = 1
93+
float primvars:arnold:light:specular = 1
9594
}
9695

9796

0 commit comments

Comments
 (0)