ScanMountGoat / Smush-Material-Research

Smash Ultimate material and rendering information
https://scanmountgoat.github.io/Smush-Material-Research/
MIT License
19 stars 8 forks source link
lighting rendering smash-bros smash-ultimate textures

Smash Ultimate Material Research

A collection of dumps, scripts, and markdown files for research into lighting, shading, rendering, and materials for Smash Ultimate. The markdown files contain information on researched values for materials and can be viewed directly in the browser. Please submit an issue or pull request for any incorrect or missing information. Ask questions or discuss in game rendering using discussions.

Website

The repository has a website for tutorials and real time demos. If any pages don't load properly or one of the demos is messed up, report the bug in issues.

Generating Data - WIP

Most of the dumps are generated using the smush_materials Rust project. The Rust toolchain can be installed from https://www.rust-lang.org/tools/install. Build the project with cargo build --release. For commandline usage, run cargo run --release -- --help.

SQLite Material Database

Most of the data is stored in an SQLite database generated by the program in the Smush-Material-DB repo. The repo contains instructions for how to build and run the tool. The database can be used with the provided python scripts for data visualization even without any SQL knowledge.

XMB to XML

cargo run --release -- xmb <ARC root folder> <export folder>

Stage Light NUANMB JSON

cargo run --release -- stage_lighting <ARC root folder> <export folder>

Shader Info

Generates the shader info JSON with rendering related information used by ssbh_wgpu. This includes the required material parameters and vertex attributes from the nufxlb as well as data mined from the decompiled source code like alpha testing and accessed color channels for parameters and attributes.

cargo run --release -- shader_info <nuc2effectlibrary.nufxlb> <shader binary folder> <decompiled source folder> <output JSON>

Shader Database

The JSON dump of the Nufx file can be converted to an SQLite database for more efficient querying.
python create_shader_db.py nuc2effectlibrary.json nufx.db
The file contains duplicate entries for each render pass (_opaque, _sort, etc). These entries can be removed by adding the --remove_duplicates flag.
python create_shader_db.py nuc2effectlibrary.json nufx.db --remove_duplicates

Nushdb Metadata

Generates a separate JSON metadata file for each of the shaders in the nushdb files. This metadata describes how material inputs are mapped to the shader code.

cargo run --release -- nushdb_metadata </render/shader/bin folder> <export folder>

Shader Binaries

Extracts the shader binaries from the .nushdb files since each file contains multiple shaders.
cargo run --release -- shader_binaries </render/shader/bin folder> <binary export folder>

For just outputting the program byte code, add the --code flag. This is necessary for analyzing the shader assembly or decompiling. In some cases, it may be necessary to manually strip the 80 (0x50) byte header from each file before dissassembling. The header should not be removed when decompiling with Ryujinx.ShaderTools.
cargo run --release -- shader_binaries --code </render/shader/bin folder> <binary export folder>

Decompiled Shaders - WIP

The shaders can be decompiled using Ryujinx's ShaderTools. Make sure to export the binaries with the --code flag.
python batch_decompile_shaders.py <ShaderTools.exe> <binary export folder> <export folder>

Annotated Decompiled Shaders

Replaces input and output attributes, textures, and uniforms in the decompiled shaders using variable names from the nushdb metadata. See shaders for details. The start of the main function contains declarations for uniform parameters. Not all parameters are used in the actual code.

cargo run --release -- annotate_decompiled_shaders <decompiled shaders> </render/shader/bin folder> <export folder>

GLSL Dependencies

Finds all the lines of a decompiled GLSL shader that contribute to the final assignment of the given variable. This is helpful when trying to analyze the source code related to a particular variable since only the relevant lines are added to the output file. This command works with any decompiled GLSL shader, but the annotated source files will be easier to interpret.

cargo run --release -- glsl_dependencies <GLSL input file> <GLSL output file> <var>
cargo run --release -- glsl_dependencies "SunShaft1PS.glsl" "out.glsl" OUT_color.x

Additional Tools

ssbh_lib - Contains the ssbh_lib_json and ssbh_data_json executables for editing various rendering related file types as JSON
xmb_lib - Contains the xmb executable that can be used to convert XMB files to and from XML
Ryujinx - Nintendo Switch emulator used for the research and documentation of in game rendering.
Yuzu - Nintendo Switch emulator used for early research. Not recommended for research due to its decompiled shaders and rendering commands being structured differently than Ryujinx.
RenderDoc - a powerful GPU debugging program that can be used with Ryujinx or Yuzu to analyze in game rendering.