Skip to content

Commit

Permalink
Dev 1.39 (#53)
Browse files Browse the repository at this point in the history
* Use framework linkage for OpenGL on macOS (AcademySoftwareFoundation#1741)

This commit fixes the output of the MaterialXTargets.cmake to have proper system linkage for OpenGL in the cmake config.
Without this change, downstream projects on a Mac like USD cannot build against MaterialX properly.

* Static analysis fixes

This changelist addresses a handful of static analysis warnings flagged by Cppcheck and MSVC.

* Move dynamic analysis tests to MacOS (AcademySoftwareFoundation#1743)

This changelist moves dynamic analysis tests to MacOS in GitHub Actions, allowing them to take advantage of more recent compiler environments and hardware.

* Add environment light intensity in GLSL (AcademySoftwareFoundation#1737)

Introduce a new uniform (u_envLightIntensity) that allows applications to control the light intensity directly in generated shaders. The uniform is a linear multiplier on environment lights. Applications can control the value of the uniform as needed.

* Remove 'baked' suffix from TextureBaker names (AcademySoftwareFoundation#1744)

The texturebaker appended a "_baked" token suffix to the generated material names that changed material name. Some pipelines get impacted by this rename, since the original material name is lost. Removing the suffix to retain original material name.

* Update development build to 1.38.10

* Move prefilter functions to referencing GLSL files

This changelist moves environment prefilter functions into the GLSL files that reference them, addressing shader compilation errors when GenOptions::hwDirectionalAlbedoMethod is set to DIRECTIONAL_ALBEDO_TABLE or DIRECTIONAL_ALBEDO_MONTE_CARLO by the client.

* Move light uniforms into referencing GLSL files (AcademySoftwareFoundation#1750)

This change moves the new environment light intensity uniforms into their referencing GLSL files, addressing shader compilation errors when GenOptions::hwDirectionalAlbedoMethod is set to DIRECTIONAL_ALBEDO_TABLE or DIRECTIONAL_ALBEDO_MONTE_CARLO by the client.

Additionally, the change moves the environment light intensity option from the UI to the command line of the viewer, since isolated adjustments of the indirect lighting term are an unintuitive rendering control for most users.

---------

Co-authored-by: Dhruv Govil <dgovil2@apple.com>
Co-authored-by: Jonathan Stone <jstone@lucasfilm.com>
Co-authored-by: Ashwin Bhat <1727158+ashwinbhat@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 26, 2024
1 parent c0e640e commit 6a8824d
Show file tree
Hide file tree
Showing 23 changed files with 112 additions and 40 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Expand Up @@ -63,14 +63,6 @@ jobs:
test_render: ON
clang_format: ON

- name: Linux_Clang_DynamicAnalysis
os: ubuntu-20.04
compiler: clang
compiler_version: "10"
python: None
cmake_config: -DMATERIALX_DYNAMIC_ANALYSIS=ON
dynamic_analysis: ON

- name: MacOS_Xcode_13_Python37
os: macos-12
compiler: xcode
Expand All @@ -91,6 +83,14 @@ jobs:
python: 3.12
test_shaders: ON

- name: MacOS_Xcode_DynamicAnalysis
os: macos-14
compiler: xcode
compiler_version: "15.0"
python: None
dynamic_analysis: ON
cmake_config: -DMATERIALX_DYNAMIC_ANALYSIS=ON

- name: iOS_Xcode_15
os: macos-14
compiler: xcode
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -244,7 +244,7 @@ else()
add_link_options(--coverage)
endif()
if(MATERIALX_DYNAMIC_ANALYSIS)
set(DYNAMIC_ANALYSIS_OPTIONS -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize-recover=all)
set(DYNAMIC_ANALYSIS_OPTIONS -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all)
add_compile_options(${DYNAMIC_ANALYSIS_OPTIONS})
add_link_options(${DYNAMIC_ANALYSIS_OPTIONS})
endif()
Expand Down
5 changes: 3 additions & 2 deletions libraries/pbrlib/genglsl/lib/mx_environment_fis.glsl
Expand Up @@ -59,10 +59,11 @@ vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distributio
radiance /= G1V * float(envRadianceSamples);

// Return the final radiance.
return radiance;
return radiance * $envLightIntensity;
}

vec3 mx_environment_irradiance(vec3 N)
{
return mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance);
vec3 Li = mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance);
return Li * $envLightIntensity;
}
12 changes: 10 additions & 2 deletions libraries/pbrlib/genglsl/lib/mx_environment_prefilter.glsl
@@ -1,5 +1,12 @@
#include "mx_microfacet_specular.glsl"

// Return the mip level associated with the given alpha in a prefiltered environment.
float mx_latlong_alpha_to_lod(float alpha)
{
float lodBias = (alpha < 0.25) ? sqrt(alpha) : 0.5 * alpha + 0.375;
return lodBias * float($envRadianceMips - 1);
}

vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distribution, FresnelData fd)
{
N = mx_forward_facing_normal(N, V);
Expand All @@ -13,10 +20,11 @@ vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distributio
vec3 FG = fd.refraction ? vec3(1.0) - (F * G) : F * G;

vec3 Li = mx_latlong_map_lookup(L, $envMatrix, mx_latlong_alpha_to_lod(avgAlpha), $envRadiance);
return Li * FG;
return Li * FG * $envLightIntensity;
}

vec3 mx_environment_irradiance(vec3 N)
{
return mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance);
vec3 Li = mx_latlong_map_lookup(N, $envMatrix, 0.0, $envIrradiance);
return Li * $envLightIntensity;
}
7 changes: 7 additions & 0 deletions libraries/pbrlib/genglsl/lib/mx_generate_prefilter_env.glsl
Expand Up @@ -12,6 +12,13 @@ mat3 mx_orthonormal_basis(vec3 N)
return mat3(X, Y, N);
}

// Return the alpha associated with the given mip level in a prefiltered environment.
float mx_latlong_lod_to_alpha(float lod)
{
float lodBias = lod / float($envRadianceMips - 1);
return (lodBias < 0.5) ? mx_square(lodBias) : 2.0 * (lodBias - 0.375);
}

// The inverse of mx_latlong_projection.
vec3 mx_latlong_map_projection_inverse(vec2 uv)
{
Expand Down
14 changes: 0 additions & 14 deletions libraries/pbrlib/genglsl/lib/mx_microfacet_specular.glsl
Expand Up @@ -508,17 +508,3 @@ float mx_latlong_compute_lod(vec3 dir, float pdf, float maxMipLevel, int envSamp
float distortion = sqrt(1.0 - mx_square(dir.y));
return max(effectiveMaxMipLevel - 0.5 * log2(float(envSamples) * pdf * distortion), 0.0);
}

// Return the mip level associated with the given alpha in a prefiltered environment.
float mx_latlong_alpha_to_lod(float alpha)
{
float lodBias = (alpha < 0.25) ? sqrt(alpha) : 0.5 * alpha + 0.375;
return lodBias * float($envRadianceMips - 1);
}

// Return the alpha associated with the given mip level in a prefiltered environment.
float mx_latlong_lod_to_alpha(float lod)
{
float lodBias = lod / float($envRadianceMips - 1);
return (lodBias < 0.5) ? mx_square(lodBias) : 2.0 * (lodBias - 0.375);
}
7 changes: 6 additions & 1 deletion resources/Lights/environment_map.mtlx
Expand Up @@ -46,7 +46,12 @@
<input name="filtertype" type="string" value="linear" />
</image>

<multiply name="envImageAdjusted" type="color3">
<input name="in1" type="color3" nodename="envImage" />
<input name="in2" type="float" value="1.0" />
</multiply>

<!-- Return the resulting color -->
<output name="out" type="color3" nodename="envImage" />
<output name="out" type="color3" nodename="envImageAdjusted" />
</nodegraph>
</materialx>
5 changes: 5 additions & 0 deletions source/MaterialXGenShader/HwShaderGenerator.cpp
Expand Up @@ -77,6 +77,7 @@ const string T_ENV_RADIANCE = "$envRadiance";
const string T_ENV_RADIANCE_MIPS = "$envRadianceMips";
const string T_ENV_RADIANCE_SAMPLES = "$envRadianceSamples";
const string T_ENV_IRRADIANCE = "$envIrradiance";
const string T_ENV_LIGHT_INTENSITY = "$envLightIntensity";
const string T_ENV_PREFILTER_MIP = "$envPrefilterMip";
const string T_REFRACTION_TWO_SIDED = "$refractionTwoSided";
const string T_ALBEDO_TABLE = "$albedoTable";
Expand Down Expand Up @@ -132,6 +133,7 @@ const string ENV_RADIANCE = "u_envRadiance";
const string ENV_RADIANCE_MIPS = "u_envRadianceMips";
const string ENV_RADIANCE_SAMPLES = "u_envRadianceSamples";
const string ENV_IRRADIANCE = "u_envIrradiance";
const string ENV_LIGHT_INTENSITY = "u_envLightIntensity";
const string ENV_PREFILTER_MIP = "u_envPrefilterMip";
const string REFRACTION_TWO_SIDED = "u_refractionTwoSided";
const string ALBEDO_TABLE = "u_albedoTable";
Expand Down Expand Up @@ -233,6 +235,7 @@ HwShaderGenerator::HwShaderGenerator(SyntaxPtr syntax) :
_tokenSubstitutions[HW::T_ENV_RADIANCE_MIPS] = HW::ENV_RADIANCE_MIPS;
_tokenSubstitutions[HW::T_ENV_RADIANCE_SAMPLES] = HW::ENV_RADIANCE_SAMPLES;
_tokenSubstitutions[HW::T_ENV_IRRADIANCE] = HW::ENV_IRRADIANCE;
_tokenSubstitutions[HW::T_ENV_LIGHT_INTENSITY] = HW::ENV_LIGHT_INTENSITY;
_tokenSubstitutions[HW::T_REFRACTION_TWO_SIDED] = HW::REFRACTION_TWO_SIDED;
_tokenSubstitutions[HW::T_ALBEDO_TABLE] = HW::ALBEDO_TABLE;
_tokenSubstitutions[HW::T_ALBEDO_TABLE_SIZE] = HW::ALBEDO_TABLE_SIZE;
Expand Down Expand Up @@ -366,6 +369,7 @@ ShaderPtr HwShaderGenerator::createShader(const string& name, ElementPtr element
const Matrix44 yRotationPI = Matrix44::createScale(Vector3(-1, 1, -1));
psPrivateUniforms->add(Type::MATRIX44, HW::T_ENV_MATRIX, Value::createValue(yRotationPI));
psPrivateUniforms->add(Type::FILENAME, HW::T_ENV_RADIANCE);
psPrivateUniforms->add(Type::FLOAT, HW::T_ENV_LIGHT_INTENSITY, Value::createValue(1.0f));
psPrivateUniforms->add(Type::INTEGER, HW::T_ENV_RADIANCE_MIPS, Value::createValue<int>(1));
psPrivateUniforms->add(Type::INTEGER, HW::T_ENV_RADIANCE_SAMPLES, Value::createValue<int>(16));
psPrivateUniforms->add(Type::FILENAME, HW::T_ENV_IRRADIANCE);
Expand All @@ -384,6 +388,7 @@ ShaderPtr HwShaderGenerator::createShader(const string& name, ElementPtr element
if (context.getOptions().hwWriteEnvPrefilter)
{
psPrivateUniforms->add(Type::FILENAME, HW::T_ENV_RADIANCE);
psPrivateUniforms->add(Type::FLOAT, HW::T_ENV_LIGHT_INTENSITY, Value::createValue(1.0f));
psPrivateUniforms->add(Type::INTEGER, HW::T_ENV_PREFILTER_MIP, Value::createValue<int>(1));
const Matrix44 yRotationPI = Matrix44::createScale(Vector3(-1, 1, -1));
psPrivateUniforms->add(Type::MATRIX44, HW::T_ENV_MATRIX, Value::createValue(yRotationPI));
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXGenShader/HwShaderGenerator.h
Expand Up @@ -71,6 +71,7 @@ Uniform variables :
$envMatrix u_envMatrix mat4 Rotation matrix for the environment.
$envIrradiance u_envIrradiance sampler2D Sampler for the texture used for diffuse environment lighting.
$envRadiance u_envRadiance sampler2D Sampler for the texture used for specular environment lighting.
$envLightIntensity u_envLightIntensity float Linear multiplier for environment lighting
$envRadianceMips u_envRadianceMips int Number of mipmaps used on the specular environment texture.
$envRadianceSamples u_envRadianceSamples int Samples to use if Filtered Importance Sampling is used for specular environment lighting.
Expand Down Expand Up @@ -126,6 +127,7 @@ extern MX_GENSHADER_API const string T_ENV_RADIANCE;
extern MX_GENSHADER_API const string T_ENV_RADIANCE_MIPS;
extern MX_GENSHADER_API const string T_ENV_RADIANCE_SAMPLES;
extern MX_GENSHADER_API const string T_ENV_IRRADIANCE;
extern MX_GENSHADER_API const string T_ENV_LIGHT_INTENSITY;
extern MX_GENSHADER_API const string T_ENV_PREFILTER_MIP;
extern MX_GENSHADER_API const string T_REFRACTION_TWO_SIDED;
extern MX_GENSHADER_API const string T_ALBEDO_TABLE;
Expand Down Expand Up @@ -183,6 +185,7 @@ extern MX_GENSHADER_API const string ENV_RADIANCE;
extern MX_GENSHADER_API const string ENV_RADIANCE_MIPS;
extern MX_GENSHADER_API const string ENV_RADIANCE_SAMPLES;
extern MX_GENSHADER_API const string ENV_IRRADIANCE;
extern MX_GENSHADER_API const string ENV_LIGHT_INTENSITY;
extern MX_GENSHADER_API const string ENV_PREFILTER_MIP;
extern MX_GENSHADER_API const string REFRACTION_TWO_SIDED;
extern MX_GENSHADER_API const string ALBEDO_TABLE;
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXGenShader/Syntax.cpp
Expand Up @@ -151,7 +151,7 @@ string Syntax::getSwizzledVariable(const string& srcName, TypeDesc srcType, cons
else
{
const size_t channelIndex = it->second;
if (channelIndex < 0 || channelIndex >= srcMembers.size())
if (channelIndex >= srcMembers.size())
{
throw ExceptionShaderGenError("Given channel index: '" + string(1, ch) + "' in channels pattern is incorrect for type '" + srcType.getName() + "'.");
}
Expand Down Expand Up @@ -197,7 +197,7 @@ ValuePtr Syntax::getSwizzledValue(ValuePtr value, TypeDesc srcType, const string
else
{
const size_t channelIndex = it->second;
if (channelIndex < 0 || channelIndex >= srcMembers.size())
if (channelIndex >= srcMembers.size())
{
throw ExceptionShaderGenError("Given channel index: '" + string(1, ch) + "' in channels pattern is incorrect for type '" + srcType.getName() + "'.");
}
Expand Down
8 changes: 7 additions & 1 deletion source/MaterialXRender/GeometryHandler.cpp
Expand Up @@ -12,6 +12,13 @@

MATERIALX_NAMESPACE_BEGIN

namespace
{

const float MAX_FLOAT = std::numeric_limits<float>::max();

} // anonymous namespace

void GeometryHandler::addLoader(GeometryLoaderPtr loader)
{
const StringSet& extensions = loader->supportedExtensions();
Expand Down Expand Up @@ -63,7 +70,6 @@ void GeometryHandler::getGeometry(MeshList& meshes, const string& location)

void GeometryHandler::computeBounds()
{
const float MAX_FLOAT = std::numeric_limits<float>::max();
_minimumBounds = { MAX_FLOAT, MAX_FLOAT, MAX_FLOAT };
_maximumBounds = { -MAX_FLOAT, -MAX_FLOAT, -MAX_FLOAT };
for (const auto& mesh : _meshes)
Expand Down
14 changes: 14 additions & 0 deletions source/MaterialXRender/LightHandler.h
Expand Up @@ -38,6 +38,7 @@ class MX_RENDER_API LightHandler
_directLighting(true),
_indirectLighting(true),
_usePrefilteredMap(false),
_envLightIntensity(1.0f),
_envSampleCount(DEFAULT_ENV_SAMPLE_COUNT),
_refractionTwoSided(false)
{
Expand Down Expand Up @@ -150,6 +151,18 @@ class MX_RENDER_API LightHandler
return _envSampleCount;
}

/// Set the environment light intensity.
void setEnvLightIntensity(const float intensity)
{
_envLightIntensity = intensity;
}

/// Return the environment light intensity.
float getEnvLightIntensity()
{
return _envLightIntensity;
}

/// Set the two-sided refraction property.
void setRefractionTwoSided(bool enable)
{
Expand Down Expand Up @@ -246,6 +259,7 @@ class MX_RENDER_API LightHandler
ImagePtr _envRadianceMap;
ImagePtr _envPrefilteredMap;
ImagePtr _envIrradianceMap;
float _envLightIntensity;
int _envSampleCount;

bool _refractionTwoSided;
Expand Down
9 changes: 4 additions & 5 deletions source/MaterialXRender/TextureBaker.inl
Expand Up @@ -18,7 +18,6 @@ namespace

const string SRGB_TEXTURE = "srgb_texture";
const string LIN_REC709 = "lin_rec709";
const string BAKED_POSTFIX = "_baked";
const string SHADER_PREFIX = "SR_";
const string DEFAULT_UDIM_PREFIX = "_";

Expand Down Expand Up @@ -352,13 +351,13 @@ DocumentPtr TextureBaker<Renderer, ShaderGen>::generateNewDocumentFromShader(Nod
}

// Create a shader node.
NodePtr bakedShader = _bakedTextureDoc->addNode(shader->getCategory(), shader->getName() + BAKED_POSTFIX, shader->getType());
NodePtr bakedShader = _bakedTextureDoc->addNode(shader->getCategory(), shader->getName(), shader->getType());

// Optionally create a material node, connecting it to the new shader node.
if (_material)
{
string materialName = (_texTemplateOverrides.count("$MATERIAL")) ? _texTemplateOverrides["$MATERIAL"] : _material->getName();
NodePtr bakedMaterial = _bakedTextureDoc->addNode(_material->getCategory(), materialName + BAKED_POSTFIX, _material->getType());
NodePtr bakedMaterial = _bakedTextureDoc->addNode(_material->getCategory(), materialName, _material->getType());
for (auto sourceMaterialInput : _material->getInputs())
{
const string& sourceMaterialInputName = sourceMaterialInput->getName();
Expand Down Expand Up @@ -421,7 +420,7 @@ DocumentPtr TextureBaker<Renderer, ShaderGen>::generateNewDocumentFromShader(Nod
if (!_bakedImageMap.empty())
{
// Add the image node.
NodePtr bakedImage = bakedNodeGraph->addNode("image", sourceName + BAKED_POSTFIX, sourceType);
NodePtr bakedImage = bakedNodeGraph->addNode("image", sourceName, sourceType);
InputPtr input = bakedImage->addInput("file", "filename");
StringMap filenameTemplateMap = initializeFileTemplateMap(bakedInput, shader, udimSet.empty() ? EMPTY_STRING : UDIM_TOKEN);
input->setValueString(generateTextureFilename(filenameTemplateMap));
Expand All @@ -433,7 +432,7 @@ DocumentPtr TextureBaker<Renderer, ShaderGen>::generateNewDocumentFromShader(Nod
NodePtr origWorldSpaceNode = worldSpacePair->second;
if (origWorldSpaceNode)
{
NodePtr newWorldSpaceNode = bakedNodeGraph->addNode(origWorldSpaceNode->getCategory(), sourceName + BAKED_POSTFIX + "_map", sourceType);
NodePtr newWorldSpaceNode = bakedNodeGraph->addNode(origWorldSpaceNode->getCategory(), sourceName + "_map", sourceType);
newWorldSpaceNode->copyContentFrom(origWorldSpaceNode);
InputPtr mapInput = newWorldSpaceNode->getInput("in");
if (mapInput)
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXRenderGlsl/CMakeLists.txt
Expand Up @@ -70,7 +70,7 @@ if(WIN32)
elseif(APPLE)
target_link_libraries(
${MATERIALX_MODULE_NAME}
OpenGL::GL
"-framework OpenGL"
"-framework Foundation"
"-framework Cocoa"
"-framework Metal")
Expand Down
1 change: 1 addition & 0 deletions source/MaterialXRenderGlsl/GlslProgram.cpp
Expand Up @@ -578,6 +578,7 @@ void GlslProgram::bindLighting(LightHandlerPtr lightHandler, ImageHandlerPtr ima
Matrix44 envRotation = Matrix44::createRotationY(PI) * lightHandler->getLightTransform().getTranspose();
bindUniform(HW::ENV_MATRIX, Value::createValue(envRotation), false);
bindUniform(HW::ENV_RADIANCE_SAMPLES, Value::createValue(lightHandler->getEnvSampleCount()), false);
bindUniform(HW::ENV_LIGHT_INTENSITY, Value::createValue(lightHandler->getEnvLightIntensity()), false);
ImagePtr envRadiance = nullptr;
if (lightHandler->getIndirectLighting())
{
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXRenderHw/SimpleWindowWindows.cpp
Expand Up @@ -111,9 +111,9 @@ SimpleWindow::~SimpleWindow()
if (hWnd)
{
_windowWrapper->release();
DestroyWindow(hWnd);
}

DestroyWindow(hWnd);
UnregisterClass(_windowClassName, GetModuleHandle(NULL));
}

Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXRenderMsl/CMakeLists.txt
Expand Up @@ -57,7 +57,7 @@ elseif(APPLE)
target_link_libraries(
${MATERIALX_MODULE_NAME}
"-framework Cocoa"
OpenGL::GL)
"-framework OpenGL")
endif()
target_link_libraries(
${MATERIALX_MODULE_NAME}
Expand Down
1 change: 1 addition & 0 deletions source/MaterialXRenderMsl/MslPipelineStateObject.mm
Expand Up @@ -706,6 +706,7 @@ int GetStrideOfMetalType(MTLDataType type)
Matrix44 envRotation = Matrix44::createRotationY(PI) * lightHandler->getLightTransform().getTranspose();
bindUniform(HW::ENV_MATRIX, Value::createValue(envRotation), false);
bindUniform(HW::ENV_RADIANCE_SAMPLES, Value::createValue(lightHandler->getEnvSampleCount()), false);
bindUniform(HW::ENV_LIGHT_INTENSITY, Value::createValue(lightHandler->getEnvLightIntensity()), false);
ImageMap envLights =
{
{ HW::ENV_RADIANCE, lightHandler->getEnvRadianceMap() },
Expand Down
7 changes: 7 additions & 0 deletions source/MaterialXView/Main.cpp
Expand Up @@ -28,6 +28,7 @@ const std::string options =
" --envRad [FILENAME] Specify the filename of the environment light to display, stored as HDR environment radiance in the latitude-longitude format\n"
" --envMethod [INTEGER] Specify the environment lighting method (0 = filtered importance sampling, 1 = prefiltered environment maps, defaults to 0)\n"
" --envSampleCount [INTEGER] Specify the environment sample count (defaults to 16)\n"
" --envLightIntensity [FLOAT] Specify the environment light intensity (defaults to 1)\n"
" --lightRotation [FLOAT] Specify the rotation in degrees of the lighting environment about the Y axis (defaults to 0)\n"
" --shadowMap [BOOLEAN] Specify whether shadow mapping is enabled (defaults to true)\n"
" --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"
Expand Down Expand Up @@ -88,6 +89,7 @@ int main(int argc, char* const argv[])
float cameraZoom(DEFAULT_CAMERA_ZOOM);
mx::HwSpecularEnvironmentMethod specularEnvironmentMethod = mx::SPECULAR_ENVIRONMENT_FIS;
int envSampleCount = mx::DEFAULT_ENV_SAMPLE_COUNT;
float envLightIntensity = 1.0f;
float lightRotation = 0.0f;
bool shadowMap = true;
DocumentModifiers modifiers;
Expand Down Expand Up @@ -162,6 +164,10 @@ int main(int argc, char* const argv[])
{
parseToken(nextToken, "integer", envSampleCount);
}
else if (token == "--envLightIntensity")
{
parseToken(nextToken, "float", envLightIntensity);
}
else if (token == "--lightRotation")
{
parseToken(nextToken, "float", lightRotation);
Expand Down Expand Up @@ -288,6 +294,7 @@ int main(int argc, char* const argv[])
viewer->setCameraZoom(cameraZoom);
viewer->setSpecularEnvironmentMethod(specularEnvironmentMethod);
viewer->setEnvSampleCount(envSampleCount);
viewer->setEnvLightIntensity(envLightIntensity);
viewer->setLightRotation(lightRotation);
viewer->setShadowMapEnable(shadowMap);
viewer->setDrawEnvironment(drawEnvironment);
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXView/RenderPipelineGL.cpp
Expand Up @@ -370,6 +370,9 @@ void GLRenderPipeline::renderFrame(void*, int shadowMapSize, const char* dirLigh
float longitudeOffset = (lightRotation / 360.0f) + 0.5f;
envMaterial->modifyUniform("longitude/in2", mx::Value::createValue(longitudeOffset));

// Apply light intensity to the environment shader.
envMaterial->modifyUniform("envImageAdjusted/in2", mx::Value::createValue(lightHandler->getEnvLightIntensity()));

// Render the environment mesh.
glDepthMask(GL_FALSE);
envMaterial->bindShader();
Expand Down

0 comments on commit 6a8824d

Please sign in to comment.