Exporting Custom Materials - Pherakki/Blender-Tools-for-DSCS GitHub Wiki

Exporting Custom Materials

Background

The DSCS models handle materials and shaders thusly:

  • Each material refers to a shader file, given in the shaders directory of an unpacked MVGL.
  • Each material contains a list of arguments that must be passed to that shader file in order for it to work properly.

The shaders are written in the Cg language and thus not able to be directly previewed in Blender. The ability to interact with these shaders from Blender is therefore highly limited. There are plans to write an external tool to allow these shaders to be assigned in a more visual manner, but this tool is still under development.

By default, the tools will assign the shader 088100c1_00880111_00000000_00058000 to any material with a diffuse texture (more on that in the next section), plus the toon texture pc001ah01s.img. This is enough to get the model to display, but does not provide any of the advanced features that can be accessed via the shader files.

Assigning textures

Each material can refer to a maximum of seven different textures, dependent on the shader assigned to the material (see: Changing the Shader):

  • ColorSampler (the "base" texture)
  • NormalSampler (a normal map)
  • EnvSampler (a reflection texture mapped onto a cube)
  • OverlayColorSampler (a second "base" texture overlaid on the first "base" texture)
  • OverlayNormalSampler (a normal map for the overlay texture)
  • CLUTSampler (a texture used for toon-shading shadows)
  • EnvsSampler (a reflection texture mapped onto a sphere)

To ensure that the exported model will use a texture for one of these purposes, there must be an Image Texture Node in the node tree for the material. It doesn't matter what it is attached to, if anything; it just needs to exist with the name of the relevant Texture Slot it should be placed in. Again, do not add textures that are not referenced by the shader.

Note: The names of image nodes in the images for this page are out-of-date. Refer to the seven options above to find valid names.

Add Image Texture Node Add Image Texture Node

Fig 1. Image Texture Nodes can be added via these menus shown in the left image. On the right is a texture node named such that whichever texture it refers to will be entered into the "DiffuseTextureID" slot for this material in the exported model. Note that the shown texture node does not have a texture attached; you should ensure a texture is loaded by the node before exporting.

In order for any new textures to be used in-game, they must be present in an "images" folder that gets installed along with your .name, .skel, and .geom files that are produced by the export function.

Exporting UV maps

Each model can be assigned a maximum of three UV maps. These are assigned to the three slots in the order they appear in Blender properties panel for that mesh. The role each UV map plays depends on the shader you assign to the material - you will need to read the shader source code to determine what each UV map will do. UV maps are assigned to the three slots in the order they appear in the outliner for your mesh.

UV Map Naming

Fig 2. A single UV map on a mesh, assigned to the UVMap slot.

Changing the shader

If you're feeling dangerous, you can change the shader used by the material by adding a "Custom Property" to the material. This property must be called "shader_hex", and hold the name of a shader file found in the shaders folder of an unpacked MVGL. You must also add an additional set of "Custom Properties" - the arguments to the shader. Each shader accepts a set of uniform-type variables in the shader function declarations. You can see which variables these are by opening up the fragment shader and vertex shader (given the suffixes _fp and _vp respectively in the filename) for the particular shader you selected, and seeing which variables in the header have the type "uniform".

Shader Inputs

You must ensure that the inputs to the shader align with the vertex data your model provides. The following inputs are possible:

  • Position
  • Normal
  • Tangent
  • Binormal
  • Indices
  • Weights
  • UV0
  • UV1
  • UV2
  • Color

"Position", "Indices", and "Weights" are automatically handled for you. For the remainder, assign them according to the following rules:

  • "Normal" is exported if the Mesh has a custom property called "export_normals" set to 1.
  • "Tangent" is exported if the Mesh has a custom property called "export_tangents" set to 1.
  • "Binormal" is exported if the Mesh has a custom property called "export_binormals" set to 1.
  • UV0 - 2 are exported according to the section Exporting UV Maps.
  • Color is exported if there is at least one Colour Map assigned to a mesh. The first colour map in the outliner only will be exported.

Shader Uniforms

You will need to create custom properties for any of the following variables that appear in the header of either the fragment or vertex shader:

  • DiffuseColor
  • Bumpiness
  • SpecularStrength
  • SpecularPower
  • ReflectionStrength
  • FresnelExp
  • FresnelMin
  • FuzzySpecColor
  • SubColor
  • SurfaceColor
  • Rolloff
  • VelvetStrength
  • OverlayBumpiness
  • OverlayStrength
  • Curvature
  • GlassStrength
  • UpsideDown
  • ParallaxBiasX
  • ParallaxBiasY
  • Time
  • ScrollSpeedSet1
  • ScrollSpeedSet2
  • ScrollSpeedSet3
  • OffsetSet1
  • OffsetSet2
  • DistortionStrength
  • LightMapStrength
  • LightMapPower
  • OffsetSet3
  • Fat
  • RotationSet1
  • RotationSet2
  • ScaleSet1
  • ZBias

These are all float-type vectors, with a size between 1 and 4 - the shader header will tell you how large the data type is (e.g. if the type is 'float3', you must create a Custom Property in Blender with the name of the relevant shader argument that holds three floating-point numbers). You must, of course, also ensure that the texture dependencies of the shader are satisfied.

Note that, in order for this material to be rendered in-game, the relevant shader must be installed along with your models in the modded DSDBP archive. You can do this by creating a folder called "shaders" that sits at the same level as the "images" folder and the .name, .skel, and .geom files for your model, and copying the fragment shader and vertex shader (given the suffixes _fp and _vp respectively in the filename) into this folder. If you are using SimpleDSCSModManager, it will automatically include any required shaders for your users when they install your mod to their game.

UV Map Naming

Fig 3. A material with the shader 088101c1_00880111_00000000_00050000 specified, which expects an input "SpecularStrength". Note that texture slot data here will be overwritten by the tools on export and can be ignored.

⚠️ **GitHub.com Fallback** ⚠️