Difference between revisions of "W4 Material System"

From Ciliz|W4
Line 2: Line 2:
  
 
Note. If you still need to create your own material or apply material from a third-party resource, it is suggested to read the article [[W4_Material_Creation]].
 
Note. If you still need to create your own material or apply material from a third-party resource, it is suggested to read the article [[W4_Material_Creation]].
 +
 +
List of standard shader attributes (passed data) that can be used in W4 Engine:
 +
 +
 +
Parameters (uniforms), which are used to work with the shader, can be either set from code or loaded from a material file (see W4_Material_File_Format).
 +
 +
 +
Standard parameters that are initially present in W4 Engine:
 +
 +
 +
In addition to the standard parameters described above, the material system allows to apply user parameters.
 +
 +
 +
If the user adds some new parameter in the shader code, then this parameter is passed by the engine with no additional effort. This allows you to add a variety of shaders to your project.
 +
 +
 +
The W4 Engine material system generates materials itself, depending on the type of the object for which the material is used. For example, with the same source code for a custom shader, the resulting material for a regular mesh does not handle animations (they are not needed), but for a skinned mesh it does. As a result, two special shaders are generated from one.
 +
 +
 +
Similarly, having initially one source shader, a different shading can be applied for various model types (eg. see W4_LIGHT_MODEL below).
 +
 +
 +
 +
The current implementation of the W4 Engine contains several models for working with materials.
 +
 +
 +
 +
W4_LIGHT_MODEL is a set of solutions for implementing lighting.
 +
 +
BuildIn shader defines
 +
 +
 +
 +
When using the W4_LIGHT_MODEL model, all default materials have the following parameters to customize:
 +
 +
W4_DIRECTIONAL_LIGHT - sets the availability of directional light sources
 +
W4_POINT_LIGHT - sets the availability of point light sources
 +
W4_SPOT_LIGHT - sets the availability of spot (projection) light sources
 +
W4_N_DIRECTIONAL_LIGHT - sets the quantity of directional light sources
 +
W4_N_POINT_LIGHT - sets the quantity of point light sources
 +
W4_N_SPOTS_LIGHT - sets the quantity of spot (projection) light sources
 +
W4_STATIC / W4_SKINNED - type of surface to drawn
 +
W4_NO_SHADOWS / W4_SHADOWS - does the surface display shadows or not
 +
 +
 +
 +
There are also special parameters that add functionality to the material. These parameters are described in the material:
 +
 +
 +
W4_LIGHT_MODEL N - W4_LIGHT_MODEL specifies the use of a standard lighting model, with N being the number of parameters of the lighting model
 +
 +
 +
 +
Let's examine how to use W4_LIGHT_MODEL with the help of the Bump material example.
 +
 +
 +
In this case, the bump.mat file looks the following way:
 +
 +
 +
 +
The vertex shader does not change:
 +
 +
 +
 +
Whereas the fragment shader has some features:
 +
 +
 +
 +
When using the W4_LIGHT_MODEL parameter, you can apply the w4_calculateLightFactor function. This function calculates the lighting value, taking into account (consideration) all the necessary light sources. Signature:
 +
 +
 +
 +
 +
The function returns the value through the input parameter results (W4_LIGHT_MODEL dimensional array)
 +
 +
 +
 +
In order for the function to work, a custom lighting model must be implemented:
 +
 +
 +
 +
In our case, the standard function is used for calculating lighting according to the Blinn model
 +
 +
 +
 +
 +
In the example above, we have value 2 specified in "W4_LIGHT_MODEL". This is explained by the fact that different lighting models may require a different number of returned values. For instance, the Blinn model operates with two or more return values.  In results [0], diffuse light components are stored, and in results [1] - specular.
 +
 +
 +
 +
The following are standard supported lighting models:

Revision as of 05:35, 20 July 2020

The W4 Framework contains a set of standard materials sufficient for the implementation of typical projects within the engine specialization. Further below we will examine the solutions used in the W4 Engine.

Note. If you still need to create your own material or apply material from a third-party resource, it is suggested to read the article W4_Material_Creation.

List of standard shader attributes (passed data) that can be used in W4 Engine:


Parameters (uniforms), which are used to work with the shader, can be either set from code or loaded from a material file (see W4_Material_File_Format).


Standard parameters that are initially present in W4 Engine:


In addition to the standard parameters described above, the material system allows to apply user parameters.


If the user adds some new parameter in the shader code, then this parameter is passed by the engine with no additional effort. This allows you to add a variety of shaders to your project.


The W4 Engine material system generates materials itself, depending on the type of the object for which the material is used. For example, with the same source code for a custom shader, the resulting material for a regular mesh does not handle animations (they are not needed), but for a skinned mesh it does. As a result, two special shaders are generated from one.


Similarly, having initially one source shader, a different shading can be applied for various model types (eg. see W4_LIGHT_MODEL below).


The current implementation of the W4 Engine contains several models for working with materials.


W4_LIGHT_MODEL is a set of solutions for implementing lighting.

BuildIn shader defines


When using the W4_LIGHT_MODEL model, all default materials have the following parameters to customize:

W4_DIRECTIONAL_LIGHT - sets the availability of directional light sources W4_POINT_LIGHT - sets the availability of point light sources W4_SPOT_LIGHT - sets the availability of spot (projection) light sources W4_N_DIRECTIONAL_LIGHT - sets the quantity of directional light sources W4_N_POINT_LIGHT - sets the quantity of point light sources W4_N_SPOTS_LIGHT - sets the quantity of spot (projection) light sources W4_STATIC / W4_SKINNED - type of surface to drawn W4_NO_SHADOWS / W4_SHADOWS - does the surface display shadows or not


There are also special parameters that add functionality to the material. These parameters are described in the material:


W4_LIGHT_MODEL N - W4_LIGHT_MODEL specifies the use of a standard lighting model, with N being the number of parameters of the lighting model


Let's examine how to use W4_LIGHT_MODEL with the help of the Bump material example.


In this case, the bump.mat file looks the following way:


The vertex shader does not change:


Whereas the fragment shader has some features:


When using the W4_LIGHT_MODEL parameter, you can apply the w4_calculateLightFactor function. This function calculates the lighting value, taking into account (consideration) all the necessary light sources. Signature:



The function returns the value through the input parameter results (W4_LIGHT_MODEL dimensional array)


In order for the function to work, a custom lighting model must be implemented:


In our case, the standard function is used for calculating lighting according to the Blinn model



In the example above, we have value 2 specified in "W4_LIGHT_MODEL". This is explained by the fact that different lighting models may require a different number of returned values. For instance, the Blinn model operates with two or more return values. In results [0], diffuse light components are stored, and in results [1] - specular.


The following are standard supported lighting models: