Integrating up through commit 90f050496

This commit is contained in:
alexpete
2021-04-07 14:03:29 -07:00
parent 8f2ed080a9
commit c2cbd430fe
2694 changed files with 285622 additions and 176874 deletions
@@ -102,14 +102,15 @@ namespace ShaderManagementConsole
bool result = false;
AZ::Data::AssetInfo sourceAssetInfo;
AZStd::string watchFolder;
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(result, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetSourceInfoBySourcePath,
m_absolutePath.c_str(), sourceAssetInfo, watchFolder);
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(
result, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetSourceInfoBySourcePath, m_absolutePath.c_str(), sourceAssetInfo,
watchFolder);
if (!result)
{
return AZ::Failure(AZStd::string::format("Could not find source data: '%s'.", m_absolutePath.c_str()));
}
m_relativePath = sourceAssetInfo.m_relativePath;
m_relativePath = m_shaderVariantListSourceData.m_shaderFilePath;
if (!AzFramework::StringFunc::Path::Normalize(m_relativePath))
{
return AZ::Failure(AZStd::string::format("Shader path could not be normalized: '%s'.", m_relativePath.c_str()));
@@ -117,7 +118,6 @@ namespace ShaderManagementConsole
AZStd::string shaderPath = m_relativePath;
AzFramework::StringFunc::Path::ReplaceExtension(shaderPath, AZ::RPI::ShaderAsset::Extension);
m_shaderAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::ShaderAsset>(shaderPath.c_str());
if (!m_shaderAsset)
@@ -20,6 +20,23 @@ import azlmbr.paths
import azlmbr.shadermanagementconsole
import azlmbr.shader
import collections
from PySide2 import QtWidgets
PROJECT_SHADER_VARIANTS_FOLDER = "ShaderVariants"
def prompt_message_box(text, informativeText = None, qButtons = QtWidgets.QMessageBox.Yes|QtWidgets.QMessageBox.No|QtWidgets.QMessageBox.Cancel):
msgBox = QtWidgets.QMessageBox()
msgBox.setText(text)
if informativeText:
msgBox.setInformativeText(informativeText)
msgBox.setStandardButtons(qButtons)
return msgBox.exec()
def clean_existing_shadervariantlist_files(filePaths):
for file in filePaths:
if os.path.exists(file):
os.remove(file)
def main():
print("==== Begin shader variant script ==========================================================")
@@ -49,7 +66,16 @@ def main():
shaderAssetInfo.relativePath
)
# TODO: [ATOM-14868] Add UI prompts in shader management console script once PySide2 is available
response = prompt_message_box(
"Generating .shadervariantlist File",
"This process may take a while. Would you like to save the generated .shadervariantlist file in the project folder? " \
"Otherwise, it will be saved in the same location as the .shader file."
)
is_save_in_project_folder = False
if response == QtWidgets.QMessageBox.Yes:
is_save_in_project_folder = True
elif response == QtWidgets.QMessageBox.Cancel:
return
# This loop collects all uniquely-identified shader items used by the materials based on its shader variant id.
shaderVariantIds = []
@@ -76,10 +102,9 @@ def main():
shaderVariantIds.append(shaderVariantId)
shaderVariantListShaderOptionGroups.append(shaderItem.GetShaderOptionGroup())
# Generate the shader variant list data by collecting shader option name-value pairs.
_, shaderFileName = os.path.split(filename)
# Generate the shader variant list data by collecting shader option name-value pairs.s
shaderVariantList = azlmbr.shader.ShaderVariantListSourceData ()
shaderVariantList.shaderFilePath = shaderFileName
shaderVariantList.shaderFilePath = shaderAssetInfo.relativePath
shaderVariants = []
stableId = 1
for shaderOptionGroup in shaderVariantListShaderOptionGroups:
@@ -104,9 +129,23 @@ def main():
shaderVariantList.shaderVariants = shaderVariants
# Save the shader variant list file
# clean previously generated shader variant list file so they don't clash.
pre, ext = os.path.splitext(shaderAssetInfo.relativePath)
projectShaderVariantListFilePath = os.path.join(azlmbr.paths.devassets, PROJECT_SHADER_VARIANTS_FOLDER, f'{pre}.shadervariantlist')
pre, ext = os.path.splitext(filename)
shaderVariantListFilePath = f'{pre}.shadervariantlist'
defaultShaderVariantListFilePath = f'{pre}.shadervariantlist'
clean_existing_shadervariantlist_files([
projectShaderVariantListFilePath
])
# Save the shader variant list file
if is_save_in_project_folder:
shaderVariantListFilePath = projectShaderVariantListFilePath
else:
shaderVariantListFilePath = defaultShaderVariantListFilePath
print(f"Saving .shadervariantlist file into: {shaderVariantListFilePath}")
azlmbr.shader.SaveShaderVariantListSourceData(shaderVariantListFilePath, shaderVariantList)
# Open the document in shader management console