Material Effects PLG (RW Section)

From GTAMods Wiki
Revision as of 18:19, 7 June 2016 by The hero (talk | contribs) (Explained env mapping differences)
Jump to navigation Jump to search
{{{NAME}}}
RenderWare Stream Section
Vendor {{{VENDORNAME}}}
Module {{{MODULENAME}}}
Module ID 0x{{{MODULEID}}}
Identifier 0x{{{IDENTIFIER}}}
Chunk ID 0x{{{MODULEID}}}{{{IDENTIFIER}}}
Versions All
Hierarchy
Parents:
None
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.

 4b - DWORD  - Type (Header)
 Xb - Effect - First Effect
 Xb - Effect - Second Effect

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.

 4b - DWORD  - 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.

 4b - DWORD  - 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.

 4b - DWORD      - 0x01, rwMATFXEFFECTBUMPMAP
 4b - FLOAT      - Intensity
 4b - BOOL       - Contains Bump Map
 Xb - RwTexture  - Bump Map (Only if effect contains a bump map)
 4b - BOOL       - Contains Height Map
 Xb - 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.

 4b - DWORD      - 0x02, rwMATFXENVMAP
 4b - FLOAT      - Reflection Coefficient (default is 1.0)
 4b - BOOL       - Use Frame Buffer Alpha Channel
 4b - BOOL       - Contains Environment Map
 Xb - 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.

 4b - DWORD     - 0x04, rwMATFXEFFECTDUAL
 4b - FLOAT     - Blending Power (default is 1.0)
 4b - DWORD     - Blending Mode
 4b - BOOL      - Contains Texture
 Xb - 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 option defines how two textures are blend 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.

 0x00 - rwNOBLEND
 0x01 - rwBLENDZERO             (0,    0,    0,    0   )
 0x02 - rwBLENDONE              (1,    1,    1,    1   )

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.

The other blend functions are blending together both textures, depending on different texture channels.

 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)

UV-Animation (rwMATFXEFFECTUVTRANSFORM)

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

 4b - DWORD     - 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. Therefor the atomic typically defines a Right to Render section, which indicates the existence of extensions within the Geometry or Material. If this section enables Material Effects, at least one of the Materials of the Atomics's geometry might contain a Material Effects extension. Also the Atomic itself features a Material Effects extension (with the same section identifier), that has a bit of a different binary structure: it does not define any Material Effects, but instead it defines a single scalar value:

 4b - DWORD     - Unknown (0 for RW-Versions < 3.3, 1 otherwise)

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

See also