We will start from Assembly Properties panel (far left icon in the Menu bar). For importing a new mesh it is best to start with an empty Assembly Elements list as displayed in the left image:
Next we’ll add a new mesh as shown on right image. That mesh will serve as a base to load our new mesh. After adding a new mesh, in the viewport there will be visible cube mesh, as seen in the next image.
Double-clicking on MDL Box entry in the Elements list will hide Assembly Properties panel, and show Model Properties panel. This is the main panel for working with the selected mesh’s material. Here we can change which texture the mesh will use, what parameters for the material are, does mesh cast and/or receive shadows, and even change the shader that is used. The Model Properties panel is shown in the following image:
Now we’ll import new mesh. There are a number of restrictions on the mesh type that is imported:
- Importer supports only Obj file format.
- The obj file has to have vertex positions, normals and texture coordinates.
- Mesh must be triangulated, that is each face must consist of only three vertices (triangle mesh).
- For a triangle, texture UV coordinates in each of the three vertices must be different from each other. To explain this one further, if u coordinate has a value of say 0.123 for vertex 1, then vertex 2 and 3 must have different u coordinate value from vertex 1 (and vertex 3 from vertex 2 also). This is important for correctly calculating tangents during mesh import.
We import a simple test sphere. When the mesh is imported it will use default material values:
In this tutorial we will focus on the default shader for opaque solid materials. Shader is named spg_pbr_shader.fx. Shader defines how the material parameters and textures are used, and each shader in the game has different usage of the parameters and textures. On the image are parameters used by the spg_pbr_shader.fx
- Diffuse (albedo) gives an object it color.It also serves as specular color for metals.It is affected by Color parameter.
- Normal map serves for applying detail on a mesh and affects in which direction light reflects off the surface.
- For special texture, each channel serves for different usage. The red channel is for specular intensity that along with the SpecularLvl parameter and specular color for metals defines the specular reflection of light. The green channel defines glossiness that together with Glossiness, GlossMapPw and GlossMapOff parameters affect the glossiness of the surface of the material. The blue channel is for light emission (self-illumination) which together with Multiplier and Level parameter define how much light the object is emitting.
Next we’ll show how parameters affect the appearance of the mesh. The textures used for demonstration are from a site about PBR materials, http://freepbr.com . Materials are free for use, and the site has very good quality materials. We highly suggest that you visit it and since the materials are free you can use them for your models.
Textures used are for rusted iron that can be downloaded here . The albedo and normal map can be used directly but for the special it needs to be created. Since the game engine works with glossiness (which is roughness inversed), the texture provided (rustediron2_roughness.png) needs to be inverted when putting into special texture’s green channel (the channel for glossiness). For this material the specular intensity (red channel in special texture) can be set to white. The blue channel is for self illumination and it should be set to black (except if we wish for the object to emit light). Engine uses dds texture format, and for special and normal texture it should be saved as: 18.104.22.168 ARGB 32 bpp | unsigned, with mip maps generated. Textures saved in this format are uncompressed and have best quality and for normal and special textures there can be visible artefacts if they are saved in compressed format. For the albedo (diffuse) texture it can be saved as compressed DXT5 ARGB 8 bpp | interpolated alpha format since the visible artefacts of compression are much less noticeable.
Now when we have prepared the textures, we can load them and tweak (if needed) the parameters.
- The first one is NormalScale. It scales the effect that normal texture has on the reflection of light. In effect the higher the setting the more pronounced are the details on the mesh.
- Next is the SpecularLvl. This setting applies only to non metallic objects, that is for ones for which Metalness parameter is low or 0. Materials that are plastic, rock, wood etc should have Metalness param set to 0.0 and SpecularLvl to their appropriate values. It affects (together with specular intensity channel in special map) how much of the light reflects of the surface.
- Glossiness, together with the GlossMapPw and GlossMapOff affects the glossiness channel. Glossiness scales the gloss channel. GlossMapPw affects the contrast between lower and higher values of the gloss channel. GlossMapOff adds and offset (brightness) the channel.
- Metalness as name suggests defines whether the material is metal, in between or non metal.
- Color colorizes the albedo texture.
- Alpha sets the transparency of the model. This parameter should be kept at 1.0 as making an object transparent in this manner can produce some visual artefacts. Transparent materials are achieved with a different shader named spg_pbr_transparent_shader.fx, which will be discussed in a follow up tutorial.
- AlphaTestTr on the other hand can be used for “hard” transparency, that is it defines the threshold at which the object part will be fully invisible. It uses alpha channel in the diffuse (albedo) texture and it’s usage is demonstrated in the following image.
After we have calibrated material parameters we can save the model into whale engine format, by clicking on Save Whale Model icon. Now the mesh is ready for usage in assembly and with it in game.
Continue to the next article: