CreateShaderVariantListDocumentFromShaderInProjectFolder.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import os
  7. import sys
  8. import azlmbr.bus
  9. import azlmbr.paths
  10. import GenerateShaderVariantListUtil
  11. def main():
  12. print("==== Begin shader variant script ==========================================================")
  13. if len(sys.argv) != 2:
  14. print("The script requires a .shader file as input argument")
  15. return
  16. inputPath = sys.argv[1]
  17. rootPath, extension = os.path.splitext(inputPath)
  18. if extension != ".shader":
  19. print("The input argument for the script is not a valid .shader file")
  20. return
  21. projectShaderVariantListFolder = os.path.join(azlmbr.paths.projectroot, "ShaderVariants")
  22. outputPath = rootPath + ".shadervariantlist"
  23. outputPath = azlmbr.shadermanagementconsole.ShaderManagementConsoleRequestBus(azlmbr.bus.Broadcast, 'GenerateRelativeSourcePath', outputPath)
  24. outputPath = os.path.join(projectShaderVariantListFolder, outputPath)
  25. # Create shader variant list document
  26. documentId = azlmbr.atomtools.AtomToolsDocumentSystemRequestBus(
  27. azlmbr.bus.Broadcast,
  28. 'CreateDocumentFromTypeName',
  29. 'Shader Variant List'
  30. )
  31. # Update shader variant list
  32. azlmbr.shadermanagementconsole.ShaderManagementConsoleDocumentRequestBus(
  33. azlmbr.bus.Event,
  34. 'SetShaderVariantListSourceData',
  35. documentId,
  36. GenerateShaderVariantListUtil.create_shadervariantlist_for_shader(inputPath)
  37. )
  38. # Save the shader variant list
  39. documentId = azlmbr.atomtools.AtomToolsDocumentSystemRequestBus(
  40. azlmbr.bus.Broadcast,
  41. 'SaveDocumentAsCopy',
  42. documentId,
  43. outputPath
  44. )
  45. print("==== End shader variant script ============================================================")
  46. if __name__ == "__main__":
  47. main()