Difference between revisions of "Material Effects PLG (RW Section)"

From GTAMods Wiki
Jump to navigation Jump to search
(Dual Texturing (rwMATFXEFFECTDUAL))
m
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{RW Section|Material Effects PLG|0x0120}}
+
{{RW Section
 +
| NAME = Material Effects PLG
 +
| VENDORNAME = Criterion Games
 +
| MODULENAME = Toolkit
 +
| MODULEID = 000001
 +
| IDENTIFIER = 20
 +
| PARENTS = [[Material (RW Section)|Material]] ''([[Extension (RW Section)|Extension]])'', [[Atomic (RW Section)|Atomic]] ''([[Extension (RW Section)|Extension]], see [[Material_Effects_PLG_(RW_Section)#Atomic_extension|below]])''
 +
}}
  
 
'''Material Effects PLG''' is an extension to the [[Material (RW Section)|Material]] section in the [[RenderWare binary stream file|Renderware stream file format]]. It is part of the [[List_of_RW_section_IDs#Toolkit|Renderware Toolkit]] and can be used to attach certain effects to a material, such as bump mapping, reflections and UV-Animations.
 
'''Material Effects PLG''' is an extension to the [[Material (RW Section)|Material]] section in the [[RenderWare binary stream file|Renderware stream file format]]. It is part of the [[List_of_RW_section_IDs#Toolkit|Renderware Toolkit]] and can be used to attach certain effects to a material, such as bump mapping, reflections and UV-Animations.
 +
 +
If a material defines material effects, the [[Atomic (RW Section)|Atomic]] that draws the material's parent geometry also contains a material effects extension. However, the format of this section is different from the actual one that is defined for the material.
  
 
== Binary structure ==
 
== Binary structure ==
Line 7: Line 16:
 
Basically each section is structured starting with a header, that contains a effect type identifier, followed by two effects that can be overlayed, if the effect type supports it.
 
Basically each section is structured starting with a header, that contains a effect type identifier, followed by two effects that can be overlayed, if the effect type supports it.
  
   4b - DWORD - Type (Header)
+
   uint32 - Type (Header)
   Xb - Effect - First Effect
+
   First Effect (variable size)
   Xb - Effect - Second Effect
+
   Second Effect (variable size)
  
 
It's certain, that at least the second effect is not used, even both effects can be disabled by setting the type identifier to 0x00 ([[Material Effects PLG (RW Section)#No Effect (rwMATFXNULL)|rwMATFXNULL]]). It is important to note, that the effect rwMATFXNULL allocates 4 bytes of memory for it's effect header.
 
It's certain, that at least the second effect is not used, even both effects can be disabled by setting the type identifier to 0x00 ([[Material Effects PLG (RW Section)#No Effect (rwMATFXNULL)|rwMATFXNULL]]). It is important to note, that the effect rwMATFXNULL allocates 4 bytes of memory for it's effect header.
Line 17: Line 26:
 
The section starts with a type identifier. The section's actual size depends on the section type.
 
The section starts with a type identifier. The section's actual size depends on the section type.
  
   4b - DWORD - Type
+
   uint32 - Type
  
 
The section type can be of one of the following values:
 
The section type can be of one of the following values:
Line 39: Line 48:
 
The effect starts with a header, containing its type identifier.
 
The effect starts with a header, containing its type identifier.
  
   4b - DWORD - 0x00, rwMATFXEFFECTNULL
+
   uint32 - 0x00, rwMATFXEFFECTNULL
  
 
There are no other contents stored within this effect.
 
There are no other contents stored within this effect.
Line 47: Line 56:
 
The effect starts with a header, containing its type identifier, followed by some settings.
 
The effect starts with a header, containing its type identifier, followed by some settings.
  
   4b - DWORD     - 0x01, rwMATFXEFFECTBUMPMAP
+
   uint32     - 0x01, rwMATFXEFFECTBUMPMAP
   4b - FLOAT      - Intensity
+
   float32    - Intensity
   4b - BOOL      - Contains Bump Map
+
   bool32      - Contains Bump Map
   Xb - RwTexture - Bump Map (Only if effect contains a bump map)
+
   RwTexture   - Bump Map (Only if effect contains a bump map)
   4b - BOOL      - Contains Height Map
+
   bool32      - Contains Height Map
   Xb - RwTexture - Height Map (Only if the effect contains a height map)
+
   RwTexture   - Height Map (Only if the effect contains a height map)
  
 
Note that there are two switches within the effect, that determine the existence of two child sections, containing the actual bump or height map. The textures are stored as raw [[Texture (RW_Section)|RwTexture]]s, simply within the effect structure.
 
Note that there are two switches within the effect, that determine the existence of two child sections, containing the actual bump or height map. The textures are stored as raw [[Texture (RW_Section)|RwTexture]]s, simply within the effect structure.
 +
 +
Bump maps are restricted in their format: The actual texture inside the [[Texture archive|TXD archive]] needs to be stored in X8R8G8B8-Format, meaning there are four 8-bit channels for red, green, blue and alpha. However, bump maps do not support alpha maps (a second texture that encodes opacity-information per texel), compression or mip-mapping for performance reasons.
  
 
=== Environment Mapping (rwMATFXENVMAP) ===
 
=== Environment Mapping (rwMATFXENVMAP) ===
  
Environment maps are used to simulate real-time reflections by blending in a pre-rendered environmental texture. Renderware does not support real-time reflections, besides [https://en.wikipedia.org/wiki/Reflection_Mapping Environment Mapping] out of the box, but it can be hooked up with mods like [[ENBSeries_(SA)|ENBSeries]].
+
Environment maps are used to simulate real-time reflections by blending in a pre-rendered environmental texture. Renderware does not support real-time reflections, besides [[wikipedia:Reflection mapping|Environment Mapping]] out of the box, but it can be hooked up with mods like [[ENBSeries_(SA)|ENBSeries]].
  
   4b - DWORD     - 0x02, rwMATFXENVMAP
+
   uint32     - 0x02, rwMATFXENVMAP
   4b - FLOAT      - Reflection Coefficient (default is 1.0)
+
   float32    - Reflection Coefficient (default is 1.0)
   4b - BOOL      - Use Frame Buffer Alpha Channel
+
   bool32      - Use Frame Buffer Alpha Channel
   4b - BOOL      - Contains Environment Map
+
   bool32      - Contains Environment Map
   Xb - RwTexture - Environment Map
+
   RwTexture   - Environment Map
  
 
The effect itself contains a switch that determines the existence of a environment map in form of a texture. If the switch is true, the texture is stored as a raw [[Texture (RW_Section)|RwTexture]] section, succeeded by the switch itself.
 
The effect itself contains a switch that determines the existence of a environment map in form of a texture. If the switch is true, the texture is stored as a raw [[Texture (RW_Section)|RwTexture]] section, succeeded by the switch itself.
Line 72: Line 83:
 
Dual Texturing enables the engine to blend two textures together. The effect therefor defines a set of blending options.
 
Dual Texturing enables the engine to blend two textures together. The effect therefor defines a set of blending options.
  
   4b - DWORD     - 0x04, rwMATFXEFFECTDUAL
+
   uint32     - 0x04, rwMATFXEFFECTDUAL
   4b - FLOAT    - Blending Power (default is 1.0)
+
   int32      - src blend mode
   4b - DWORD    - Blending Mode
+
   int32      - dest blend mode
   4b - BOOL      - Contains Texture
+
   bool32    - Contains Texture
   Xb - RwTexture - Texture
+
   RwTexture - Texture
  
If the effect contains a texture, it is stored as a raw [[Texture (RW_Section)|RwTexture]] section right after the ''Contains Texture'' option. The ''Blend Mode'' option defines how two textures are blend together. Basically each mode executes a different vector function that returns the blending result for each texel.
+
If the effect contains a texture, it is stored as a raw [[Texture (RW_Section)|RwTexture]] section right after the ''Contains Texture'' option. The ''Blend Mode'' options defines how two textures are blended together. Basically each mode executes a different vector function that returns the blending result for each texel.
  
The first set of functions returns a constant value for each texel.
+
The first set of blend functions returns a constant value for each texel.
  
 
   0x00 - rwNOBLEND
 
   0x00 - rwNOBLEND
 
   0x01 - rwBLENDZERO            (0,    0,    0,    0  )
 
   0x01 - rwBLENDZERO            (0,    0,    0,    0  )
   rwBLENDONE              (1,    1,    1,    1  )
+
   0x02 - rwBLENDONE              (1,    1,    1,    1  )
 
+
  0x03 - rwBLENDSRCCOLOR        (Rs,  Gs,  Bs,  As  )
The very first function, rwNOBLEND, disables blending at all, meaning that only the base texture of the material will be drawn. This has pretty much the same effect, as the second function, which blends the base texture over the blend texture. rwBLENDONE does the exact opposite by blending the blend texture over the base texture.
+
  0x04 - rwBLENDINVSRCCOLOR      (1-Rs, 1-Gs, 1-Bs, 1-As)
 +
  0x05 - rwBLENDSRCALPHA        (As,  As,  As,  As  )
 +
  0x06 - rwBLENDINVSRCALPHA      (1-As, 1-As, 1-As, 1-As)
 +
  0x07 - rwBLENDDESTALPHA        (Ad,  Ad,  Ad,  Ad  )
 +
  0x08 - rwBLENDINVDESTALPHA    (1-Ad, 1-Ad, 1-Ad, 1-Ad)
 +
  0x09 - rwBLENDDESTCOLOR        (Rd,   Gd,   Bd,   Ad  )
 +
  0x0A - rwBLENDINVDESTCOLOR    (1-Rd, 1-Gd, 1-Bd, 1-Ad)
 +
  0x0B - rwBLENDSRCALPHASAT      (f,    f,    f,    1  )  f = min (As, 1-Ad)
  
The other blend functions are blending together both textures, depending on different texture channels.
+
The very first function, rwNOBLEND, disables blending at all, meaning that only the base texture of the material will be drawn.
 
+
In the other cases the final color is the sum of the base texture multiplied by the value of the dest Blend mode and the dual pass texture multiplied by the value of the src blend mode.
  0x02 - rwBLENDSRCCOLOR        (Rs,  Gs,  Bs,  As  )
 
  0x03 - rwBLENDINVSRCCOLOR      (1-Rs, 1-Gs, 1-Bs, 1-As)
 
  0x04 - rwBLENDSRCALPHA        (As,  As,  As,  As  )
 
  0x05 - rwBLENDINVSRCALPHA      (1-As, 1-As, 1-As, 1-As)
 
  0x06 - rwBLENDDESTALPHA        (Ad,  Ad,  Ad,  Ad  )
 
  0x07 - rwBLENDINVDESTALPHA    (1-Ad, 1-Ad, 1-Ad, 1-Ad)
 
  0x08 - rwBLENDDESTCOLOR        (Rd,  Gd,  Bd,  Ad  )
 
  0x09 - rwBLENDINVDESTCOLOR    (1-Rd, 1-Gd, 1-Bd, 1-Ad)
 
  0x0A - rwBLENDSRCALPHASAT      (f,    f,    f,    1  )  f = min (As, 1-Ad)
 
  
 
=== UV-Animation (rwMATFXEFFECTUVTRANSFORM) ===
 
=== UV-Animation (rwMATFXEFFECTUVTRANSFORM) ===
Line 104: Line 113:
 
UV-Animation itself does not contain any further information, besides it obligatory header.
 
UV-Animation itself does not contain any further information, besides it obligatory header.
  
   4b - DWORD     - 0x05, rwMATFXEFFECTUVTRANSFORM
+
   uint32     - 0x05, rwMATFXEFFECTUVTRANSFORM
  
 
If this effect is defined, the [[Material (RW_Section)|Material]] also contains a [[UV Animation PLG (RW_Section)|UV Animation PLG]] extension.
 
If this effect is defined, the [[Material (RW_Section)|Material]] also contains a [[UV Animation PLG (RW_Section)|UV Animation PLG]] extension.
  
== See also ==
+
== Atomic extension ==
* [[Material (RW Section)|Material]]
+
 
* [[Reflection Material (RW Section)|Reflection Material]]
+
Renderware does not support advanced shading or physically based rendering (PBR). In order to better quality rendering, it defines different rendering pipelines a draw call can be passed to. Each pipeline supports different features, like Bump Mapping for the illusion of uneven or rough surfaces, Environment Mapping to approximate reflection or Vertex Colors to support approximative precalculated lightning. Rockstar even defined a set of [[Pipeline Set (RW Section)|custom rendering pipelines]] to support their custom engine features, like [[Reflection Material (RW Section)|reflective materials]] or [[Night Vertex Colors (RW Section)|extra vertex colors]]. For more information about the general rendering workflow in Renderware, please refer to the [[RenderWare]] article.
* [[Specular Material (RW Section)|Specular Material]]
+
 
* [[UV Animation PLG (RW Section)|UV Animation PLG]]
+
In order to choose the right parameters for the rendering pipelines, while passing each [[Atomic (RW Section)|Atomic]] to a draw-call, the Atomic itself needs to know which effects the linked geometry uses. The MatFX plugin uses another [[Material (RW Section)|Material]] chunk that specifies whether the MatFX pipeline should be attached to the Atomic:
* [[Texture (RW Section)|Texture]]
+
 
* [[Geometry List (RW Section)|Geometry List]]
+
  bool32    - MatFX enabled
* [[RenderWare_binary_stream_file|RW file format specification]]
+
 
 +
In RW versions >= 3.4.0.0 this chunk is only written when the value is 1.
 +
 
 +
An Atomic can also have a [[Right To Render (RW Section)|Right To Render]] chunk in its Extension data, this however is ignored by the engine. In the case of MatFX this chunk is only written when a null-pipeline was attached when the file was written. This is generally the case if the file was exported from a modeling program.
 +
 
 +
== Rendering ==
 +
 
 +
=== Environment mapping ===
 +
 
 +
Environment mapping on the PS2 works different than on the PC in some ways:
 +
* The environment effect is rendered as a second pass and hence uses alpha blending which gives a different result than using multiple texture stages
 +
* The environment pass uses the same vertex colors as the diffuse pass
 +
* Texture coordinates are generated differently (independent of camera position)
 +
 
 +
For an implementation of PS2-like env-mapping on PC see [[SkyGfx]]
  
{{N|SA|VC}}
+
{{N|SA|VC|3}}
[[Category:GTA_3]]
 

Latest revision as of 12:29, 11 September 2020

Material Effects PLG
RenderWare Stream Section
Vendor Criterion Games
Module Toolkit
Module ID 0x000001
Identifier 0x20
Chunk ID 0x00000120
Versions All
Hierarchy
Parents:
Material (Extension), Atomic (Extension, see below)
Children:
None
Extensions:
None
File Format

Material Effects PLG is an extension to the Material section in the Renderware stream file format. It is part of the Renderware Toolkit and can be used to attach certain effects to a material, such as bump mapping, reflections and UV-Animations.

If a material defines material effects, the Atomic that draws the material's parent geometry also contains a material effects extension. However, the format of this section is different from the actual one that is defined for the material.

Binary structure

Basically each section is structured starting with a header, that contains a effect type identifier, followed by two effects that can be overlayed, if the effect type supports it.

 uint32  - Type (Header)
 First Effect (variable size)
 Second Effect (variable size)

It's certain, that at least the second effect is not used, even both effects can be disabled by setting the type identifier to 0x00 (rwMATFXNULL). It is important to note, that the effect rwMATFXNULL allocates 4 bytes of memory for it's effect header.

Header

The section starts with a type identifier. The section's actual size depends on the section type.

 uint32  - Type

The section type can be of one of the following values:

 0 rwMATFXEFFECTNULL            No Effect
 1 rwMATFXEFFECTBUMPMAP         Bump Map
 2 rwMATFXEFFECTENVMAP          Environment Map (Reflections)
 3 rwMATFXEFFECTBUMPENVMAP      Bump Map/Environment Map
 4 rwMATFXEFFECTDUAL            Dual Textures
 5 rwMATFXEFFECTUVTRANSFORM     UV-Tranformation
 6 rwMATFXEFFECTDUALUVTRANSFORM Dual Textures/UV-Transformation

The effect types 3 (rwMATFXEFFECTBUMPENVMAP) and 6 (rwMATFXEFFECTDUALUVTRANSFORM) are requiring both effects to be set. For all other section types, the second effect is usually set to 0 (rwMATFXEFFECTNULL).

Effects (Types)

Each effect starts with a header on it's own, containing the effect identifier. The effect identifier is of the same type as the section identifier and therefor the effect identifier of the first effect typically equals the section identifier. Exceptions are the section types 3 (rwMATFXEFFECTBUMPENVMAP) and 6 (rwMATFXEFFECTDUALUVTRANSFORM), which are invalid when beeing used as effect type.

No Effect (rwMATFXNULL)

The effect starts with a header, containing its type identifier.

 uint32  - 0x00, rwMATFXEFFECTNULL

There are no other contents stored within this effect.

Bump Mapping (rwMATFXEFFECTBUMPMAP)

The effect starts with a header, containing its type identifier, followed by some settings.

 uint32      - 0x01, rwMATFXEFFECTBUMPMAP
 float32     - Intensity
 bool32      - Contains Bump Map
 RwTexture   - Bump Map (Only if effect contains a bump map)
 bool32      - Contains Height Map
 RwTexture   - Height Map (Only if the effect contains a height map)

Note that there are two switches within the effect, that determine the existence of two child sections, containing the actual bump or height map. The textures are stored as raw RwTextures, simply within the effect structure.

Bump maps are restricted in their format: The actual texture inside the TXD archive needs to be stored in X8R8G8B8-Format, meaning there are four 8-bit channels for red, green, blue and alpha. However, bump maps do not support alpha maps (a second texture that encodes opacity-information per texel), compression or mip-mapping for performance reasons.

Environment Mapping (rwMATFXENVMAP)

Environment maps are used to simulate real-time reflections by blending in a pre-rendered environmental texture. Renderware does not support real-time reflections, besides Environment Mapping out of the box, but it can be hooked up with mods like ENBSeries.

 uint32      - 0x02, rwMATFXENVMAP
 float32     - Reflection Coefficient (default is 1.0)
 bool32      - Use Frame Buffer Alpha Channel
 bool32      - Contains Environment Map
 RwTexture   - Environment Map

The effect itself contains a switch that determines the existence of a environment map in form of a texture. If the switch is true, the texture is stored as a raw RwTexture section, succeeded by the switch itself.

Dual Texturing (rwMATFXEFFECTDUAL)

Dual Texturing enables the engine to blend two textures together. The effect therefor defines a set of blending options.

 uint32     - 0x04, rwMATFXEFFECTDUAL
 int32      - src blend mode
 int32      - dest blend mode
 bool32     - Contains Texture
 RwTexture  - Texture

If the effect contains a texture, it is stored as a raw RwTexture section right after the Contains Texture option. The Blend Mode options defines how two textures are blended together. Basically each mode executes a different vector function that returns the blending result for each texel.

The first set of blend functions returns a constant value for each texel.

 0x00 - rwNOBLEND
 0x01 - rwBLENDZERO             (0,    0,    0,    0   )
 0x02 - rwBLENDONE              (1,    1,    1,    1   )
 0x03 - rwBLENDSRCCOLOR         (Rs,   Gs,   Bs,   As  )
 0x04 - rwBLENDINVSRCCOLOR      (1-Rs, 1-Gs, 1-Bs, 1-As)
 0x05 - rwBLENDSRCALPHA         (As,   As,   As,   As  )
 0x06 - rwBLENDINVSRCALPHA      (1-As, 1-As, 1-As, 1-As)
 0x07 - rwBLENDDESTALPHA        (Ad,   Ad,   Ad,   Ad  )
 0x08 - rwBLENDINVDESTALPHA     (1-Ad, 1-Ad, 1-Ad, 1-Ad)
 0x09 - rwBLENDDESTCOLOR        (Rd,   Gd,   Bd,   Ad  )
 0x0A - rwBLENDINVDESTCOLOR     (1-Rd, 1-Gd, 1-Bd, 1-Ad)
 0x0B - rwBLENDSRCALPHASAT      (f,    f,    f,    1   )  f = min (As, 1-Ad)

The very first function, rwNOBLEND, disables blending at all, meaning that only the base texture of the material will be drawn. In the other cases the final color is the sum of the base texture multiplied by the value of the dest Blend mode and the dual pass texture multiplied by the value of the src blend mode.

UV-Animation (rwMATFXEFFECTUVTRANSFORM)

UV-Animation itself does not contain any further information, besides it obligatory header.

 uint32     - 0x05, rwMATFXEFFECTUVTRANSFORM

If this effect is defined, the Material also contains a UV Animation PLG extension.

Atomic extension

Renderware does not support advanced shading or physically based rendering (PBR). In order to better quality rendering, it defines different rendering pipelines a draw call can be passed to. Each pipeline supports different features, like Bump Mapping for the illusion of uneven or rough surfaces, Environment Mapping to approximate reflection or Vertex Colors to support approximative precalculated lightning. Rockstar even defined a set of custom rendering pipelines to support their custom engine features, like reflective materials or extra vertex colors. For more information about the general rendering workflow in Renderware, please refer to the RenderWare article.

In order to choose the right parameters for the rendering pipelines, while passing each Atomic to a draw-call, the Atomic itself needs to know which effects the linked geometry uses. The MatFX plugin uses another Material chunk that specifies whether the MatFX pipeline should be attached to the Atomic:

 bool32     - MatFX enabled

In RW versions >= 3.4.0.0 this chunk is only written when the value is 1.

An Atomic can also have a Right To Render chunk in its Extension data, this however is ignored by the engine. In the case of MatFX this chunk is only written when a null-pipeline was attached when the file was written. This is generally the case if the file was exported from a modeling program.

Rendering

Environment mapping

Environment mapping on the PS2 works different than on the PC in some ways:

  • The environment effect is rendered as a second pass and hence uses alpha blending which gives a different result than using multiple texture stages
  • The environment pass uses the same vertex colors as the diffuse pass
  • Texture coordinates are generated differently (independent of camera position)

For an implementation of PS2-like env-mapping on PC see SkyGfx