Difference between revisions of "Material Effects PLG (RW Section)"
m |
m |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{RW Section|Material Effects PLG| | + | {{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. | ||
Line 62: | Line 69: | ||
=== 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 [ | + | 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]]. |
uint32 - 0x02, rwMATFXENVMAP | uint32 - 0x02, rwMATFXENVMAP | ||
Line 120: | Line 127: | ||
In RW versions >= 3.4.0.0 this chunk is only written when the value is 1. | In RW versions >= 3.4.0.0 this chunk is only written when the value is 1. | ||
− | An Atomic can also have a [[Right | + | 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 == | == Rendering == | ||
+ | |||
=== Environment mapping === | === Environment mapping === | ||
Line 130: | Line 138: | ||
* Texture coordinates are generated differently (independent of camera position) | * Texture coordinates are generated differently (independent of camera position) | ||
− | For an implementation of PS2-like env-mapping on PC see [ | + | For an implementation of PS2-like env-mapping on PC see [[SkyGfx]] |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | {{N|SA|VC}} | + | {{N|SA|VC|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.
Contents
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