Skip to content

Ayataka

Alex Miyamoto edited this page Feb 8, 2021 · 8 revisions

The Usagi Model Converter

Ayataka is the model converter for Usagi, it was designed to be able to handle a wide variety of model formats and convert them to a common type.

It is the oldest tool in Usagi, and whilst it has been updated to use the protocol buffer files it is dependent on building the game first.

Ayataka produces both the renderable data and the collision data.
As any entity definition including a model automatically creates sub entities for all of the bones in a model ayataka should convert all models before processing these hierarchies (not presently the case and is causing dependency issues, resolved by running the command to build data a second time). It exports the bone hierarchy as an xml so that regardless of the model format the same data format is available for bones.

Currently only FBX is supported (we hope to add gltf support shortly), and the FBX SDK must to installed to make use of it.

As of 0.3 Ayataka now uses the same effect definition files as everything else in the game. In order for an effect definition to be valid to be used for a model it must have shader variants named:
deferred
translucent
depth
omni_depth

Omni-depth is a special case for point light shadows where the shader is expected to send the same model to six different render targets in a single pass.

Additionally you must have support for skeletal animation, usually through the use of a define set in the material definition. If the model is not static then the skeletal variation ".skel" will be used.

There are a few requirements for a model shader, it must have:
Input attributes uv0 - uVX (where X is the number of UVs)
Shader variable mTexMatrix (count equal to the number of texture reads which support transforms)
Shader variable iBoneCount (for skeletal animation)

The vertex shader must also include model_transform.inc so that the bone palette is available.

You can accomplish this using the defines system, or by creating a completely separate effect within the same effect pack.

Ayataka will attempt to parse to find good defaults as best it can, based on the texture names it will set the following shader boolean values if provided:
DiffuseColor -> bDiffuseMap
NormalMap -> bBumpMap
SpecularColor -> bSpecMap
EmissiveFactor -> bEmissiveMap
Reflection -> bReflectionMap

If present the following variables will be set given defaults based on material properties:
vec4 ambient
vec4 diffuse
float alpha
float specularpow
vec4 specular
vec4 reflection
float reflectionfactor

You are not required to provide all or any variables in your effect, they are just there for convenience.

If you do not wish to use the defaults you should add a yml file in the following format to the same directory as the .fbx. Please see the EnumTables in MaterialOverrides.cpp for acceptable syntax

ModelName.yml

MaterialOverrides:
  HUD: #Material name
    ShaderPak: Model # Effect pack name
    Effect: FBXDefault # Which effect in the pack
    AddDefines: distortion # add .distortion to the name
    SubDefines: bump # remove .bump if present in the name
    Transparent: true # move this material to the transparent pass
    AlphaStateGroup: # Override alpha states
      rgbSrcFunc: One
      rgbDestFunc: OneMinusSrcAlpha
      rgbOp: Add
      alphaSrcFunc: One
      alphaDestFunc: Zero
      alphaOp: Add
      alphaTestFunc: Always
      alphaTestReference: 0.0
    Layer: Translucent  # Change the layer to transparent  
    Textures: # override textures
      - hint: "DiffuseColor"
        texture: Textures/white_default
    Constants: # override variables
      - set: Material1
        name: reflectionfactor
        value: 1.0

These variables can also be overridden at runtime.

Ideally we would like to be editing these overrides in real time through an editor similar to the particle editor but that is low on the priority list.