The materials library

Xtreme3D

Lesson 5
The materials library

Level: Beginner
Version of the Xtreme3D: 3.0.x
Author: Gecko

One of the most remarkable features of Xtreme3D - use of library materials. The material is a set of parameters that define the appearance of the object. This set consists of the values of color, clarity, texture, the type of mixing, and so on. The concept of the material in the Xtreme3D is much more fundamental than in many other cursors. Very often under the material means the texture, but Xtreme3D material may not have texture. In other cases, the system of materials is poor or incomplete, which cannot be said about the Xtreme3D.

The material is created once and can be applied to any number of objects, supporting materials. Change the settings of the material touches all the objects using this material. The principle gives tangible benefits (saving memory, the amount of code, time and labor programr), although it may cause some inconvenience (for example, if you want to change the parameters of the material referred to only one particular object). The material in the Xtreme3D has a unique name, on which the change settings. The name of the specified string value, for example "mGround".

The library material (Material Library) is called the special design that contains a list of the materials. The library can be active or inactive. In the first case, to which you can add content, configure it , and applied to the objects. In the second case, it is impossible. Since different libraries can contain materials with the same name, cannot be made active, two or more of the library at the same time.

The meaning in the use of multiple libraries of materials is the ability to determine for them the individual path to ���������. These paths are taken into account when loading models, using the external texture files. By default, the libraries are looking for texture in the working directory of the game. Of course, store them there - not the best idea. Undoubtedly, it is better to organize them in separate folders. For example, if you have three folders with three different models of levels, it will be possible to create for each of them the library materials and assign them the path to ��������� corresponding to the desired folders.

There is a huge amount and variety of settings of materials. In addition, materials allow to apply to them shaders, "photograph" in them pictures from the screen or with the camera, as well as store data although, for example, masks and maps of the heights. Cover in one article all the opportunities available to the system Xtreme3D, is unreal. Therefore, we consider only the most basic: color, texture and a few others.

Is First created and activated the materials library:

Matlib=MaterialLibraryCreate();
MaterialLibraryActivate(matlib);

Now you can create the materials:

MaterialCreate('mTexture', 'texture.jpg');

This function at the same time, creates the material and assigns it the texture from the file. Xtreme3D supports BMP, JPG, PNG, TGA, DDS. It is recommended to use the textures with the party equal to 128, 256, 512 and other degrees of deuce. The texture does not necessarily have to be a square.

You can create a material without texture, just leaving the name of the file is empty:

MaterialCreate('mColor', '');

In this case, you can specify the color of the material. The easiest way to do this is the function of

MaterialSetDiffuseColor('mColor', c_red, 1);

The color you can pass the built-in constants GML (_red, c_yellow, c_green , etc.), the functions make_color_rgb(r, g, b) or make_color_hsv(h, s, v) for models of color RGB and HSV, respectively, as well as in the reverse hexadecimal format, for example, $0000FF means red.

In addition to the colors, The MaterialSetDiffuseColor sets the value of transparency - Alpha - lies in the range from 0 to 1. Alpha in our case is equal to 1 (Full Opacity).

Strictly speaking, The MaterialSetDiffuseColor specifies only one of the components of the color of the material as well as all their four - Ambient, diffuse, specular and Emission. This separation is due to the fact that the surface areas with different levels of ambient light can have different color. Ambient determines the overall shade of material that is independent of the Lighting (the color of the shadow side), Diffuse - the color of the lit side, Specular - the color of the �����, Emission - the color of the simulation of luminous. Moreover, the light sources also have their own components of ambient, diffuse and Specular, and this makes the color of objects even more complex and diverse.

You can disable for material lighting (and, at the same time, the influence of the mist, which will be discussed later):

MaterialSetOptions('mColor', 1, 0);

The first parameter, in this case equal to 1, is responsible for the effect of fog, the second - for the impact of lighting.

Apply the created material to an object is very simple:

ObjectSetMaterial(object, 'mTexture');

By the way, back to the material with a texture. With this texture can do amazing things! For example, changing the mode of projection on the sphere will make a material similar to reflection on the metal:

MaterialSetTextureMappingMode('mTexture', tmmSphere);

And to repeat many times the texture on the surface of the object, change its size:

MaterialSetTextureScale('mTexture', 10, 10).

This texture is repeated ten times.

As an independent work try to create and apply the materials on the planet from the previous lesson about the hierarchy. As the textures can use real maps the surface of the Earth and the Moon. And the sun can be left without textures and do a simple yellow. Remember as well as creates a light source and make it the child of the sun that it radiated light (in this case, it is worth to disable lighting for his material).