CreateShaderVariantListDocumentFromShaderInSameFolder.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if not azlmbr.atomtools.util.IsDocumentPathEditable(inputPath):
  22. print("Cannot create shader variant list in same folder as input file")
  23. return
  24. outputPath = rootPath + ".shadervariantlist"
  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()