W4 Default Materials

From Ciliz|W4

Scope

The W4 Framework contains several standard materials that can be used by calling the appropriate function. You can set parameters for standard materials. If no parameters are specified, the default values are used. Parameter setting is described in the Parameter Setting paragraph.

Note. All standard materials (as well as a few additional ones) can be found in the /apps/samples/sample-materials/ catalog of W4 SDK.

Regular nodes

This section describes the standard materials used for regular nodes. Let's look at the implementation of standard materials with the Utah teapot mesh (from the W4_Mesh_Converter article) as a sample.

getDefault()

The material allows you to set the following parameters:

  • baseColor - the main color of the object;
  • specColor - glare color.
DefaultMat 01.png

Example:

teapot->setMaterialInst(Material::getDefault()->createInstance());
//or
teapot->setMaterialInst(MaterialInst::predefined::mesh());

getDefaultLambert()

The material allows you to set the texture specified via the texture0 parameter. This material uses the Lambert light model and lights that were created in the scene.

DefaultMat 02.png

Example:

teapot->setMaterialInst(Material::getDefaultLambert()->createInstance());
//or
teapot->setMaterialInst(MaterialInst::predefined::lambert());

getDefaultBlinn()

The material allows you to set the texture specified via the texture0 parameter. This material uses the Blinn light model and lights that were created in the scene.

DefaultMat 03.png

Example:

teapot->setMaterialInst(Material::getDefaultBlinn()->createInstance());
//or
teapot->setMaterialInst(MaterialInst::predefined::blinn());

Setting parameters

Let's consider a small fragment of a program with different parameters:

auto matInst_1 = Material::getDefault()->createInstance();
matInst_1->setParam("baseColor", vec4(1.0f, 1.0f, 1.0f, 1.0f));
matInst_1->setParam("specColor", math::color::random());

auto matInst_2 = Material::getDefaultLambert()->createInstance();
matInst_2->setTexture(resources::TextureId::TEXTURE_0, Texture::get("resourses/textures/texture.png"));

auto matInst_3 = Material::getDefaultBlinn()->createInstance();
matInst_3->setTexture(
                      resources::TextureId::TEXTURE_0, 
                      Texture::get(ResourceGenerator(
                                  ColorTextureGenerator,
                                  math::vec4(.0, 1., 1., 1.)
                      )));

The above example applies the following functions:

  • Color parameters are set for matInst_1 material. The setParam (“paramName“, paramValue) function is used.
  • A texture is set for the matInst_2 material.
  • For material matInst_3, a color texture generator is used to set the color instead of the texture.

Special nodes

In addition to the materials listed above, the W4 Engine also contains materials for special nodes:

getDefaultSkybox() Standard skybox for the camera where you can set your own cubemap. An example of usage is in /apps/samples/gist-skybox/.
getDefaultBackground() Standard background for the application. An example of usage is in /apps/samples/gist-background/.
getDefaultShadowMap() Material for displaying shadows falling on an object. An example of usage is in /apps/samples/sample-shadows/.