Skip to content

Commit 99cbc04

Browse files
authored
Add enableDirectLight option to MaterialX Viewer (#2773)
This PR adds a command-line flag to disable direct lighting, so scenes can be rendered purely with image-based lighting. This makes it easier to compare to other environments where direct lighting from environment maps is not available.
1 parent d9975a1 commit 99cbc04

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

source/MaterialXView/Main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const std::string options =
3030
" --envSampleCount [INTEGER] Specify the environment sample count (defaults to 16)\n"
3131
" --envLightIntensity [FLOAT] Specify the environment light intensity (defaults to 1)\n"
3232
" --lightRotation [FLOAT] Specify the rotation in degrees of the lighting environment about the Y axis (defaults to 0)\n"
33+
" --enableDirectLight [BOOLEAN] Specify whether direct lighting is enabled (defaults to true)\n"
3334
" --shadowMap [BOOLEAN] Specify whether shadow mapping is enabled (defaults to true)\n"
3435
" --path [FILEPATH] Specify an additional data search path location (e.g. '/projects/MaterialX'). This absolute path will be queried when locating data libraries, XInclude references, and referenced images.\n"
3536
" --library [FILEPATH] Specify an additional data library folder (e.g. 'vendorlib', 'studiolib'). This relative path will be appended to each location in the data search path when loading data libraries.\n"
@@ -91,6 +92,7 @@ int main(int argc, char* const argv[])
9192
int envSampleCount = mx::DEFAULT_ENV_SAMPLE_COUNT;
9293
float envLightIntensity = 1.0f;
9394
float lightRotation = 0.0f;
95+
bool enableDirectLight = true;
9496
bool shadowMap = true;
9597
DocumentModifiers modifiers;
9698
int screenWidth = 1280;
@@ -172,6 +174,10 @@ int main(int argc, char* const argv[])
172174
{
173175
parseToken(nextToken, "float", lightRotation);
174176
}
177+
else if (token == "--enableDirectLight")
178+
{
179+
parseToken(nextToken, "boolean", enableDirectLight);
180+
}
175181
else if (token == "--shadowMap")
176182
{
177183
parseToken(nextToken, "boolean", shadowMap);
@@ -296,6 +302,7 @@ int main(int argc, char* const argv[])
296302
viewer->setEnvSampleCount(envSampleCount);
297303
viewer->setEnvLightIntensity(envLightIntensity);
298304
viewer->setLightRotation(lightRotation);
305+
viewer->setDirectLightEnable(enableDirectLight);
299306
viewer->setShadowMapEnable(shadowMap);
300307
viewer->setDrawEnvironment(drawEnvironment);
301308
viewer->setDocumentModifiers(modifiers);

source/MaterialXView/Viewer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class Viewer : public ng::Screen
126126
_genContext.getOptions().hwShadowMap = enable;
127127
}
128128

129+
// Enable or disable direct lighting.
130+
void setDirectLightEnable(bool enable)
131+
{
132+
_lightHandler->setDirectLighting(enable);
133+
}
134+
129135
// Enable or disable drawing environment as the background.
130136
void setDrawEnvironment(bool enable)
131137
{

0 commit comments

Comments
 (0)