Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodesk: Expose dome light textures max resolution #3383

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pxr/imaging/hdSt/domeLightComputations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ PXR_NAMESPACE_OPEN_SCOPE
HdSt_DomeLightComputationGPU::HdSt_DomeLightComputationGPU(
const TfToken &shaderToken,
HdStSimpleLightingShaderPtr const &lightingShader,
const unsigned int outputWidth,
const unsigned int outputHeight,
const unsigned int numLevels,
const unsigned int level,
const float roughness)
: _shaderToken(shaderToken),
_lightingShader(lightingShader),
_outputWidth(outputWidth),
_outputHeight(outputHeight),
_numLevels(numLevels),
_level(level),
_roughness(roughness)
Expand Down Expand Up @@ -167,10 +171,10 @@ HdSt_DomeLightComputationGPU::Execute(

// Size of texture to be created.
// Downsize larger textures
bool downsize = (srcDim[0] > 256 && srcDim[1] > 256);
int width = downsize ? srcDim[0] / 2 : srcDim[0];
int height = downsize ? srcDim[1] / 2 : srcDim[1];
bool downsize = (_outputWidth > 256 && _outputHeight > 256);
int width = downsize ? _outputWidth / 2 : _outputWidth;
int height = downsize ? _outputHeight / 2 : _outputHeight;

// Make sure dimensions align with the local size used in the Compute Shader
width = _MakeMultipleOf(width, localSize);
height = _MakeMultipleOf(height, localSize);
Expand Down
6 changes: 6 additions & 0 deletions pxr/imaging/hdSt/domeLightComputations.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class HdSt_DomeLightComputationGPU : public HdStComputation
const TfToken & shaderToken,
// Lighting shader that remembers the GL texture names
HdStSimpleLightingShaderPtr const &lightingShader,
// Width of output textures.
unsigned int outputWidth,
// Height of output textures.
unsigned int outputHeight,
// Number of mip levels.
unsigned int numLevels = 1,
// Level to be filled (0 means also to allocate texture)
Expand All @@ -67,6 +71,8 @@ class HdSt_DomeLightComputationGPU : public HdStComputation
private:
const TfToken _shaderToken;
HdStSimpleLightingShaderPtr const _lightingShader;
const unsigned int _outputWidth;
const unsigned int _outputHeight;
const unsigned int _numLevels;
const unsigned int _level;
const float _roughness;
Expand Down
7 changes: 7 additions & 0 deletions pxr/imaging/hdSt/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ TF_DEFINE_ENV_SETTING(HD_ENABLE_GPU_TINY_PRIM_CULLING, false,
TF_DEFINE_ENV_SETTING(HDST_MAX_LIGHTS, 16,
"Maximum number of lights to render with");

TF_DEFINE_ENV_SETTING(HDST_DOME_LIGHT_TEXTURES_MAX_RES, 8192,
"Maximum resolution of processed textures for dome light");

const TfTokenVector HdStRenderDelegate::SUPPORTED_RPRIM_TYPES =
{
HdPrimTypeTokens->mesh,
Expand Down Expand Up @@ -192,6 +195,10 @@ HdStRenderDelegate::HdStRenderDelegate(HdRenderSettingsMap const& settingsMap)
"Maximum number of lights",
HdStRenderSettingsTokens->maxLights,
VtValue(int(TfGetEnvSetting(HDST_MAX_LIGHTS))) },
HdRenderSettingDescriptor{
"Maximum resolution of processed textures for dome light",
HdStRenderSettingsTokens->domeLightTexturesMaxResolution,
VtValue(static_cast<int>(TfGetEnvSetting(HDST_DOME_LIGHT_TEXTURES_MAX_RES))) },
};

_PopulateDefaultSettings(_settingDescriptors);
Expand Down
57 changes: 46 additions & 11 deletions pxr/imaging/hdSt/simpleLightingShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ HdStSimpleLightingShader::HdStSimpleLightingShader()
: _lightingContext(GlfSimpleLightingContext::New())
, _useLighting(true)
, _glslfx(std::make_unique<HioGlslfx>(HdStPackageSimpleLightingShader()))
, _domeLightTexturesMaxResolution(8192)
, _renderParam(nullptr)
{
}
Expand Down Expand Up @@ -593,14 +594,6 @@ HdStSimpleLightingShader::AddResourcesFromTextures(ResourceContext &ctx) const
std::const_pointer_cast<HdStShaderCode, const HdStShaderCode>(
shared_from_this()));

// Irriadiance map computations.
ctx.AddComputation(
nullptr,
std::make_shared<HdSt_DomeLightComputationGPU>(
_tokens->domeLightIrradiance,
thisShader),
HdStComputeQueueZero);

// Calculate the number of mips for the prefilter texture
// Note that the size of the prefilter texture is half the size of the
// original Environment Map (srcTextureObject)
Expand All @@ -619,8 +612,36 @@ HdStSimpleLightingShader::AddResourcesFromTextures(ResourceContext &ctx) const
}
const GfVec3i srcDim = srcTexture->GetDescriptor().dimensions;

const unsigned int numPrefilterLevels =
std::max((unsigned int)(std::log2(std::max(srcDim[0], srcDim[1]))), 1u);
// Size of texture to be created.
unsigned int outputWidth = srcDim[0];
unsigned int outputHeight = srcDim[1];

// Check max resolution.
unsigned int maxDim = std::max(outputWidth, outputHeight);
if (maxDim > _domeLightTexturesMaxResolution) {
float ratio = outputWidth / outputHeight;
if (outputWidth >= outputHeight) {
outputWidth = _domeLightTexturesMaxResolution;
outputHeight = outputWidth / ratio;
}
else {
outputHeight = _domeLightTexturesMaxResolution;
outputWidth = outputHeight * ratio;
}
}

// Irriadiance map computations.
ctx.AddComputation(
nullptr,
std::make_shared<HdSt_DomeLightComputationGPU>(
_tokens->domeLightIrradiance,
thisShader,
outputWidth,
outputHeight),
HdStComputeQueueZero);

const unsigned int numPrefilterLevels =
std::max(static_cast<unsigned int>(std::log2(std::max(outputWidth, outputHeight))), 1u);

// Prefilter map computations. mipLevel = 0 allocates texture.
for (unsigned int mipLevel = 0; mipLevel < numPrefilterLevels; ++mipLevel) {
Expand All @@ -632,6 +653,8 @@ HdStSimpleLightingShader::AddResourcesFromTextures(ResourceContext &ctx) const
std::make_shared<HdSt_DomeLightComputationGPU>(
_tokens->domeLightPrefilter,
thisShader,
outputWidth,
outputHeight,
numPrefilterLevels,
mipLevel,
roughness),
Expand All @@ -643,7 +666,9 @@ HdStSimpleLightingShader::AddResourcesFromTextures(ResourceContext &ctx) const
nullptr,
std::make_shared<HdSt_DomeLightComputationGPU>(
_tokens->domeLightBRDF,
thisShader),
thisShader,
outputWidth,
outputHeight),
HdStComputeQueueZero);
}

Expand All @@ -653,5 +678,15 @@ HdStSimpleLightingShader::GetNamedTextureHandles() const
return _namedTextureHandles;
}

void
HdStSimpleLightingShader::SetDomeLightTexturesMaxResolution(unsigned int maxRes)
{
if (_domeLightTexturesMaxResolution != maxRes) {
_domeLightTexturesMaxResolution = maxRes;
_domeLightEnvironmentTextureHandle = nullptr;
_domeLightTextureHandles.clear();
}
}

PXR_NAMESPACE_CLOSE_SCOPE

6 changes: 6 additions & 0 deletions pxr/imaging/hdSt/simpleLightingShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class HdStSimpleLightingShader : public HdStLightingShader
return _shadowAovBindings;
}

HDST_API
void SetDomeLightTexturesMaxResolution(unsigned int maxRes);

private:
SdfPath _GetAovPath(TfToken const &aov, size_t shadowIndex) const;
void _ResizeOrCreateBufferForAov(size_t shadowIndex) const;
Expand All @@ -143,6 +146,9 @@ class HdStSimpleLightingShader : public HdStLightingShader
NamedTextureHandleVector _namedTextureHandles;

NamedTextureHandleVector _domeLightTextureHandles;
// Maximum resolution of processed textures for dome light
unsigned int _domeLightTexturesMaxResolution;

NamedTextureHandleVector _shadowTextureHandles;

HdSt_MaterialParamVector _lightTextureParams;
Expand Down
3 changes: 2 additions & 1 deletion pxr/imaging/hdSt/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ PXR_NAMESPACE_OPEN_SCOPE
(volumeRaymarchingStepSize) \
(volumeRaymarchingStepSizeLighting) \
(volumeMaxTextureMemoryPerField) \
(maxLights)
(maxLights) \
(domeLightTexturesMaxResolution)

// Material tags help bucket prims into different queues for draw submission.
// The tags supported by Storm are:
Expand Down
6 changes: 6 additions & 0 deletions pxr/imaging/hdx/simpleLightTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ HdxSimpleLightTask::Sync(HdSceneDelegate* delegate,
_maxLights = size_t(
renderIndex.GetRenderDelegate()->GetRenderSetting<int>(
HdStRenderSettingsTokens->maxLights, 16));

// Update dome light textures max resolution.
_lightingShader->SetDomeLightTexturesMaxResolution(static_cast<unsigned int>(
renderIndex.GetRenderDelegate()->GetRenderSetting<unsigned int>(
HdStRenderSettingsTokens->domeLightTexturesMaxResolution, 8192)));

_settingsVersion = renderDelegate->GetRenderSettingsVersion();
verifyNumLights = true;
}
Expand Down