Difference between revisions of "Material File Format/en"

From Ciliz|W4
(Created page with "# data - description of the data source. It can be either a file (with keys: path and type = file), or a generator which compiled into the engine (with keys: generator, type =...")
Line 39: Line 39:
 
=== Hints ===
 
=== Hints ===
 
In order not to set the same parameters again and again, you can set default values for any parameter in the material file. These parameters will be set for each new MatInstance. The following parameter types are supported: INT, FLOAT, BOOL, VEC2, VEC3, VEC4, TEXTURE, СUBEMAP.
 
In order not to set the same parameters again and again, you can set default values for any parameter in the material file. These parameters will be set for each new MatInstance. The following parameter types are supported: INT, FLOAT, BOOL, VEC2, VEC3, VEC4, TEXTURE, СUBEMAP.
 +
 +
<div class="mw-translate-fuzzy">
 
* By default, the transparency of the material is disabled. It can be enabled in two ways:
 
* By default, the transparency of the material is disabled. It can be enabled in two ways:
 +
</div>
 +
<div class="mw-translate-fuzzy">
 
# Set the blending key to true. In this case, the SRC_ALPHA functions for the shader result and ONE_MINUS_SRC_ALPHA for the background are set for the material.
 
# Set the blending key to true. In this case, the SRC_ALPHA functions for the shader result and ONE_MINUS_SRC_ALPHA for the background are set for the material.
 +
</div>
 +
<div class="mw-translate-fuzzy">
 
# Define a record with a 'blending' key containing src and dst values, respectively. Possible values are: ZERO,  ONE,  SRC_COLOR,  ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA,  DST_ALPHA,  ONE_MINUS_DST_ALPHA,  CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA,  ONE_MINUS_CONSTANT_ALPHA, SRC_ALPHA_SATURATE.
 
# Define a record with a 'blending' key containing src and dst values, respectively. Possible values are: ZERO,  ONE,  SRC_COLOR,  ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA,  DST_ALPHA,  ONE_MINUS_DST_ALPHA,  CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA,  ONE_MINUS_CONSTANT_ALPHA, SRC_ALPHA_SATURATE.
 +
</div>
 +
 +
<div class="mw-translate-fuzzy">
 
* The entry for the TEXTURE and CUBEMAP types consists of the following key-value pairs:
 
* The entry for the TEXTURE and CUBEMAP types consists of the following key-value pairs:
 +
</div>
 +
<div class="mw-translate-fuzzy">
 
# type - TEXTURE or CUBEMAP .
 
# type - TEXTURE or CUBEMAP .
 +
</div>
 +
<div class="mw-translate-fuzzy">
 
# data - description of the data source. It can be either a file (with keys: path and type = file), or a generator which compiled into the engine (with keys: generator, type = generator and params (generator parameters)).  
 
# data - description of the data source. It can be either a file (with keys: path and type = file), or a generator which compiled into the engine (with keys: generator, type = generator and params (generator parameters)).  
 
The actual version of the engine contains one generator with a Vec4 type of the generator parameter (Variant) for creating the texture of one color - "[default] color". For type CUBEMAP 'data' contains 6 data sources, denoted by numbers from 0 to 6 (respectively X +, X-, Y +, Y-, Z +, Z-);
 
The actual version of the engine contains one generator with a Vec4 type of the generator parameter (Variant) for creating the texture of one color - "[default] color". For type CUBEMAP 'data' contains 6 data sources, denoted by numbers from 0 to 6 (respectively X +, X-, Y +, Y-, Z +, Z-);
# Опциональное поле sWrapping для задания типа заполнения текстурой (Repeat, MirroredRepeat, ClampToEdge) по координате S .
+
</div>
# Опциональное поле tWrapping для задания типа заполнения текстурой (Repeat, MirroredRepeat, ClampToEdge) по координате T .
+
* Опциональное поле sWrapping для задания типа заполнения текстурой (Repeat, MirroredRepeat, ClampToEdge) по координате S .
# Опциональное поле filtering для задания режима фильтрации текстуры (Level0 - Level3).
+
* Опциональное поле tWrapping для задания типа заполнения текстурой (Repeat, MirroredRepeat, ClampToEdge) по координате T .
 +
* Опциональное поле filtering для задания режима фильтрации текстуры (Level0 - Level3).

Revision as of 13:42, 4 June 2020

Scope

Material is part of the W4 Engine Material System. The values of the shader parameters that will be used by default for all instances of this material, as well as the instructions for the render (blending) and texture (wrapping and filtering) can be set in the material file (.mat).

Detailed Description

File Structure

Example .mat file:

 {
     "vertexFile" : "<path from the project root directory to the vertex shader file (.vs)>",
     "fragmentFile" : "<path from the project root directory to the fragment shader file(.fs)>",
     ["blending" : <enable blending (true/false)>,]
     ["blending" : {"src" : "<blending function for the result of your shader>", "dst" : "<blending function for background>"},]
     "params" : {
         "texture0": {"type": "TEXTURE", "data": {"path": "<path from the project root directory to the texture file>", "type": "file"}[, "sWrapping": "{Repeat|MirroredRepeat|ClampToEdge}"][, "tWrapping" : "{Repeat|MirroredRepeat|ClampToEdge}"][, "filtering": "{Level0|Level1|Level2|Level3}"]},
         "texture1": {"type": "TEXTURE", "data": {"generator": "[default] color", "params": {"type": "Vec4", "value": { "x": 1.0, "y": 1.0 , "z": 1.0, "w": 1.0 }}, "type": "generator"}},
         "cubemap0": {"type": "CUBEMAP", "data": {
                 "0": {"path": "<path from the project root directory to the X+ texture file>", "type": "file"},
                 "1": {"path": "<path from the project root directory to the X- texture file>", "type": "file"},
                 "2": {"path": "<path from the project root directory to the Y+ texture file>", "type": "file"},
                 "3": {"path": "<path from the project root directory to the Y- texture file>", "type": "file"},
                 "4": {"path": "<path from the project root directory to the Z+ texture file>", "type": "file"},
                 "5": {"path": "<path from the project root directory to the Z- texture file>", "type": "file"}
             }
         },
         "intParam": { "type": "INT", "data": -42 },
         "floatParam": { "type": "BOOL", "data": 3.14159259 },
         "boolParam": { "type": "BOOL", "data": true },
         "vec2Param": { "type": "VEC2", "data": { "x": 0.1, "y": 0.2 }},
         "vec3Param": { "type": "VEC3", "data": { "x": 0.1, "y": 0.2 , "z": 0.3 }},
         "vec4Param": { "type": "VEC4", "data": { "x": 0.1, "y": 0.2 , "z": 0.3, "w": 0.4 }}
     }
 }

The following values ​​are mandatory:

  • vertexFile
  • fragmentFile

Everything else is optional.

Hints

In order not to set the same parameters again and again, you can set default values for any parameter in the material file. These parameters will be set for each new MatInstance. The following parameter types are supported: INT, FLOAT, BOOL, VEC2, VEC3, VEC4, TEXTURE, СUBEMAP.

  • By default, the transparency of the material is disabled. It can be enabled in two ways:
  1. Set the blending key to true. In this case, the SRC_ALPHA functions for the shader result and ONE_MINUS_SRC_ALPHA for the background are set for the material.
  1. Define a record with a 'blending' key containing src and dst values, respectively. Possible values are: ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA, ONE_MINUS_CONSTANT_ALPHA, SRC_ALPHA_SATURATE.
  • The entry for the TEXTURE and CUBEMAP types consists of the following key-value pairs:
  1. type - TEXTURE or CUBEMAP .
  1. data - description of the data source. It can be either a file (with keys: path and type = file), or a generator which compiled into the engine (with keys: generator, type = generator and params (generator parameters)).

The actual version of the engine contains one generator with a Vec4 type of the generator parameter (Variant) for creating the texture of one color - "[default] color". For type CUBEMAP 'data' contains 6 data sources, denoted by numbers from 0 to 6 (respectively X +, X-, Y +, Y-, Z +, Z-);

  • Опциональное поле sWrapping для задания типа заполнения текстурой (Repeat, MirroredRepeat, ClampToEdge) по координате S .
  • Опциональное поле tWrapping для задания типа заполнения текстурой (Repeat, MirroredRepeat, ClampToEdge) по координате T .
  • Опциональное поле filtering для задания режима фильтрации текстуры (Level0 - Level3).