Difference between revisions of "W4 Default Materials"

From Ciliz|W4
(Created page with "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...")
 
Line 1: Line 1:
 +
== 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.
 
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.
 
Note. All standard materials (as well as a few additional ones) can be found in the '''/apps/samples/sample-materials/''' catalog of W4 SDK.
  
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.
+
== 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:
 
The material allows you to set the following parameters:
baseColor - the main color of the object;
+
* baseColor - the main color of the object;
specColor - glare color.
+
* specColor - glare color.
  
 +
Example:
 +
<syntaxhighlight lang="c++">
 +
teapot->setMaterialInst(Material::getDefault()->createInstance());
 +
//or
 +
teapot->setMaterialInst(MaterialInst::predefined::mesh());
 +
</syntaxhighlight>
  
 +
=== 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.
 
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.
  
 +
Example:
 +
<syntaxhighlight lang="c++">
 +
teapot->setMaterialInst(Material::getDefaultLambert()->createInstance());
 +
//or
 +
teapot->setMaterialInst(MaterialInst::predefined::lambert());
 +
</syntaxhighlight>
 +
=== 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.
  
 +
Example:
 +
<syntaxhighlight lang="c++">
 +
teapot->setMaterialInst(Material::getDefaultBlinn()->createInstance());
 +
//or
 +
teapot->setMaterialInst(MaterialInst::predefined::blinn());
 +
</syntaxhighlight>
 +
== Setting parameters ==
 
Let's consider a small fragment of a program with different parameters:
 
Let's consider a small fragment of a program with different parameters:
+
<syntaxhighlight lang="c++">
 +
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.)
 +
                      )));
 +
</syntaxhighlight>
 
The above example applies the following functions:
 
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 ==
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.
 
 
 
 
 
In addition to the materials listed above, the W4 Engine also contains materials for special nodes:
 
In addition to the materials listed above, the W4 Engine also contains materials for special nodes:
 
 
 
 
The implementation of a standard skybox for the camera where you can set your own cubemap. An example of usage is in '''/apps/samples/gist-skybox/'''.
 
The implementation of a standard skybox for the camera where you can set your own cubemap. An example of usage is in '''/apps/samples/gist-skybox/'''.

Revision as of 05:57, 20 July 2020

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.

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.

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.

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: The implementation of a standard skybox for the camera where you can set your own cubemap. An example of usage is in /apps/samples/gist-skybox/.