resonance 1.0.1
Loading...
Searching...
No Matches
Rnd::Mat Class Reference

Surface description a Rnd::Mesh draws with. More...

#include <mat.h>

Inheritance diagram for Rnd::Mat:
Collaboration diagram for Rnd::Mat:

Classes

class  Stage
 One texture stage of a material. More...

Public Types

enum  BlendMode {
  kBlendModeDest = 0 , kBlendModeSrc = 1 , kBlendModeAdd = 2 , kBlendModeMultiply = 3 ,
  kBlendModeMultiply2 = 4 , kBlendModeSrcAlpha = 5 , kBlendModeSrcAlphaAdd = 6 , kBlendModeSrcAdd = 7 ,
  kBlendModeInvSrcAlpha = 8 , kBlendModeDestAlpha = 9 , kBlendModeInvDestAlpha = 10 , kBlendModeSrcAlphaOpaque = 11 ,
  kBlendModeSrcAlphaCutout = 12
}
 Frame buffer blend, as the text dump labels the values. More...
enum  Cull { kCullModeCw = 0 , kCullModeCcw = 1 , kCullModeNone = 2 }
 Face winding the rasteriser discards, as the text dump labels the values. More...
enum  TexGen {
  kGenModeFixed = 0 , kGenModeSphere = 1 , kGenModePlanar = 2 , kGenModeOrthoCube = 3 ,
  kGenModeLocalCube = 4
}
 How a texture stage produces its texture coordinates. More...
enum  TexWrap { kWrapModeClamp = 0 , kWrapModeRepeat = 1 , kWrapModeMirror = 2 }
 How a texture coordinate outside the unit square resolves. More...
enum  { kSerialVersion = 7 }
 Serial version this build writes, and the highest version it loads. More...

Public Member Functions

 Mat (const HxStr &name)
 Construct a material with the default surface.
virtual ~Mat ()
void AddStage ()
 Append one stage with the default surface, owned by this material.
void RemoveStage (int nIndex)
 Remove one stage, dropping this material's reference on its texture.
void GetMeshReferrers (std::vector< Mesh * > &meshes)
 Append every referrer of this material whose class is "Mesh" to meshes.
virtual void DumpText (Dbg &sink)
 Write the material to the engine text sink.
virtual void Save (Stream &stream)
 Serialise the material.
virtual void Replace (Object *pFrom, Object *pTo)
 Replace one object reference with another.
virtual const HxStr & ClassName () const
 Return the registered class name, "Mat".
virtual void Copy (const Object *pSource, unsigned nFlags)
 Copy another material over this one.
virtual void Load (Stream &stream)
 Load the material.
virtual void SyncMat (int nStage)
 Virtual with an empty body in Rnd::Mat.
virtual void SetAmbient (const Color &color)
 Set the ambient colour.
virtual void SetDiffuse (const Color &color)
 Set the diffuse colour, retaining the current alpha.
virtual void SetEmissive (const Color &color)
 Set the emissive colour.
virtual void SetAlpha (float flAlpha)
 Set the diffuse alpha.
virtual void SetSpecular (const Color &color, float flAlpha)
 Set the specular colour and its alpha.
virtual void SetLighting (int nEnable, int nVertAmbient, int nVertDiffuse, int nVertSpecular, int nVertEmissive, int nVertAlpha, int nNormalize)
 Set the lighting enable flag, the five per-vertex source flags, and the normalise flag.
virtual void Refresh ()
 Resynchronise the material after its state or its stage vector has changed.
void SetMultiPass (int nMultiPass)
 Set the multi-pass count.
void SetFlat (int nFlat)
 Set whether the surface shades flat.
Public Member Functions inherited from Rnd::Object
 Object ()
 Construct an unnamed object.
 Object (const HxStr &name)
 Construct an object and register it under name.
virtual ~Object ()
 Erase the registry entry and release the name buffer.
void SetName (const HxStr &name)
 Re-register this object under a different name.
void AddRef (Object *pReferrer)
 Register pReferrer as a store of a pointer to this object.
void RemoveRef (Object *pReferrer)
 Drop one registration made by AddRef().

Static Public Member Functions

static void * operator new (size_t nSize)
 Allocate a material block under the tag "Rnd::Mat".
static void operator delete (void *pBlock)
 Release a material block under the same tag.

Public Attributes

std::vector< Stage > mStages
Color mEmissive
 Colour the surface emits.
Color mAmbient
 Ambient colour.
Color mDiffuse
 Diffuse colour.
Color mSpecular
int mVertAmbient
 Non-zero when the vertex colour supplies the ambient term in place of mAmbient.
int mVertDiffuse
 Non-zero when the vertex colour supplies the diffuse term in place of mDiffuse.
int mVertEmissive
 Vertex emissive flag.
int mVertAlpha
 Vertex alpha flag.
Cull mCull
int mFlat
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal

Static Public Attributes

static HxStr sClassName
 Registered class name of Rnd::Mat, the string "Mat".

Protected Member Functions

void RemoveStageTexRefs ()
 Drop this material's reference on every stage texture.
Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.

Protected Attributes

BlendMode mBlend
int mEnable
int mVertSpecular
int mNormalize
int mMultiPass
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs

Detailed Description

Surface description a Rnd::Mesh draws with.

Its RTTI descriptor is at 0x008ef0e0. It has Rnd::Object as its one public non-virtual base at offset 0. The Object subobject is 0x1c bytes. The material's members start at +0x1c and the whole object is 0xa0 bytes.

A material combines the four lighting colours, the flags that pick per-vertex colours over the material colours, and a vector of texture stages. The stage vector is what binds textures; the material itself has no texture reference.

The PlayStation 2 subclass Rnd::PsMat adds the hardware binding path and overrides the one material virtual to invalidate the cached register state.

Member Enumeration Documentation

◆ BlendMode

Frame buffer blend, as the text dump labels the values.

The same enumeration types a texture stage, where the default is kBlendModeMultiply.

Enumerator
kBlendModeDest 
kBlendModeSrc 
kBlendModeAdd 
kBlendModeMultiply 
kBlendModeMultiply2 
kBlendModeSrcAlpha 
kBlendModeSrcAlphaAdd 
kBlendModeSrcAdd 
kBlendModeInvSrcAlpha 
kBlendModeDestAlpha 
kBlendModeInvDestAlpha 
kBlendModeSrcAlphaOpaque 
kBlendModeSrcAlphaCutout 

◆ Cull

Face winding the rasteriser discards, as the text dump labels the values.

Enumerator
kCullModeCw 

Discard clockwise faces.

kCullModeCcw 

Discard counter-clockwise faces.

kCullModeNone 

Draw both windings.

◆ TexGen

How a texture stage produces its texture coordinates.

Enumerator
kGenModeFixed 

Use the vertex coordinates as they are.

kGenModeSphere 

Sphere map.

kGenModePlanar 

Planar projection.

kGenModeOrthoCube 

Cube map in object space.

kGenModeLocalCube 

Cube map in local space.

◆ TexWrap

How a texture coordinate outside the unit square resolves.

Enumerator
kWrapModeClamp 
kWrapModeRepeat 
kWrapModeMirror 

◆ anonymous enum

anonymous enum

Serial version this build writes, and the highest version it loads.

Enumerator
kSerialVersion 

Constructor & Destructor Documentation

◆ Mat()

Rnd::Mat::Mat ( const HxStr & name)

Construct a material with the default surface.

Ambient and diffuse start white, emissive and specular start black with full alpha, the blend starts at kBlendModeSrcAlpha, and lighting starts enabled.

Parameters
nameThe object name, passed to the Rnd::Object constructor.
Ghidra address:
NTSC-U/C: 0x004d0ea8
Ghidra address:
PAL: 0x0050f2f8

◆ ~Mat()

virtual Rnd::Mat::~Mat ( )
virtual
Ghidra address:
NTSC-U/C: 0x004dbb10
Ghidra address:
PAL: 0x0051a0b0

Member Function Documentation

◆ operator new()

void * Rnd::Mat::operator new ( size_t nSize)
static

Allocate a material block under the tag "Rnd::Mat".

Parameters
nSizeThe object size the compiler supplies.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x004db900
Ghidra address:
PAL: 0x00519ea0

◆ operator delete()

void Rnd::Mat::operator delete ( void * pBlock)
static

Release a material block under the same tag.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x004db920
Ghidra address:
PAL: 0x00519ec0

◆ AddStage()

void Rnd::Mat::AddStage ( )

Append one stage with the default surface, owned by this material.

The routine has no caller in the shipped build. The name is inferred.

Ghidra address:
NTSC-U/C: 0x004d2198
Ghidra address:
PAL: 0x005105e8

◆ RemoveStage()

void Rnd::Mat::RemoveStage ( int nIndex)

Remove one stage, dropping this material's reference on its texture.

The index is not checked. The routine has no caller in the shipped build. The name is inferred.

Parameters
nIndexThe position of the stage.
Ghidra address:
NTSC-U/C: 0x004dcf60
Ghidra address:
PAL: 0x0051b500

◆ GetMeshReferrers()

void Rnd::Mat::GetMeshReferrers ( std::vector< Mesh * > & meshes)

Append every referrer of this material whose class is "Mesh" to meshes.

Walks the referrer list in order and appends each match through dynamic_cast. TnlArena's constructor is the one caller. The definition sits in the TnlArena unit, and the title is inferred.

Parameters
meshesThe vector to append to.
Ghidra address:
NTSC-U/C: 0x00406010
Ghidra address:
PAL: 0x0043f910

◆ RemoveStageTexRefs()

void Rnd::Mat::RemoveStageTexRefs ( )
protected

Drop this material's reference on every stage texture.

Walks mStages and calls Rnd::Object::RemoveRef() for each stage whose mTex is set. Both destructors in the hierarchy call it out of line, this class's at 0x004dbb10 and Rnd::PsMat's at 0x005915d4, which is the evidence for protected rather than private access. Copy() and Load() inline the same body instead of calling it.

Ghidra address:
NTSC-U/C: 0x004dcd20
Ghidra address:
PAL: 0x0051b2c0

◆ DumpText()

virtual void Rnd::Mat::DumpText ( Dbg & sink)
virtual

Write the material to the engine text sink.

Parameters
sinkThe text sink.
Ghidra address:
NTSC-U/C: 0x004d0f78
Ghidra address:
PAL: 0x0050f3c8

Reimplemented from Rnd::Object.

◆ Save()

virtual void Rnd::Mat::Save ( Stream & stream)
virtual

Serialise the material.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x004d1638
Ghidra address:
PAL: 0x0050fa88

Implements Rnd::Object.

◆ Replace()

virtual void Rnd::Mat::Replace ( Object * pFrom,
Object * pTo )
virtual

Replace one object reference with another.

A material references objects only through its stages, so the routine walks the stage vector and swaps every texture reference whose current value is the old object.

Parameters
pFromThe object being replaced.
pToThe object to point at, which may be null.
Ghidra address:
NTSC-U/C: 0x004dcc20
Ghidra address:
PAL: 0x0051b1c0

Implements Rnd::Object.

◆ ClassName()

virtual const HxStr & Rnd::Mat::ClassName ( ) const
virtual

Return the registered class name, "Mat".

The key is the one a data file writes for the class, which the registry at Rnd::Manager::Init() maps to the creator at 0x004dbc80.

Returns
The class name.
Ghidra address:
NTSC-U/C: 0x004dbc70
Ghidra address:
PAL: 0x0051a210

Implements Rnd::Object.

◆ Copy()

virtual void Rnd::Mat::Copy ( const Object * pSource,
unsigned nFlags )
virtual

Copy another material over this one.

Parameters
pSourceThe source object, which has to be a material for the copy to have any effect.
nFlagsThe copy flags.
Ghidra address:
NTSC-U/C: 0x004dce18
Ghidra address:
PAL: 0x0051b3b8

Implements Rnd::Object.

◆ Load()

virtual void Rnd::Mat::Load ( Stream & stream)
virtual

Load the material.

Reports "Can't load new Mat" through the failure sink when the file version exceeds kSerialVersion. A file below version 3 stores a source factor and a destination factor instead of a blend mode, and the loader folds the pair into the nearest blend mode.

Parameters
streamThe stream to read from.
Ghidra address:
NTSC-U/C: 0x004d1a90
Ghidra address:
PAL: 0x0050fee0

Implements Rnd::Object.

◆ SyncMat()

virtual void Rnd::Mat::SyncMat ( int nStage)
virtual

Virtual with an empty body in Rnd::Mat.

No subclass in the shipped build overrides it, so its purpose is undetermined. It fills the ninth vtable slot.

Parameters
nStageThe stage index. Ignored by the body. Refresh() passes the index of each stage in turn, and TnlCatcher::SetMultiplied() passes 0 (0x004552ac).
Ghidra address:
NTSC-U/C: 0x004db958
Ghidra address:
PAL: 0x00519ef8

◆ SetAmbient()

virtual void Rnd::Mat::SetAmbient ( const Color & color)
virtual

Set the ambient colour.

Rnd::PsMat overrides the setter to invalidate the cached hardware material state.

Parameters
colorThe new ambient colour.
Ghidra address:
NTSC-U/C: 0x004db970
Ghidra address:
PAL: 0x00519f10

Reimplemented in Rnd::PsMat.

◆ SetDiffuse()

virtual void Rnd::Mat::SetDiffuse ( const Color & color)
virtual

Set the diffuse colour, retaining the current alpha.

The body reads three floats and the fourth component of the argument is discarded, so the parameter type is not recoverable from the body alone. The one caller fixes it. Rnd::MatAnim::SetFrameSelf() blends the diffuse channel over all four components with vmulax.xyzw at 0x004d5028, stores the whole quadword into the temporary it passes, and blends the three stage channels of the same routine over three components with vmulax.xyz instead. The argument is therefore a Color and not a Vector3.

Parameters
colorThe new diffuse colour, whose alpha is discarded.
Ghidra address:
NTSC-U/C: 0x004db980
Ghidra address:
PAL: 0x00519f20

Reimplemented in Rnd::PsMat.

◆ SetEmissive()

virtual void Rnd::Mat::SetEmissive ( const Color & color)
virtual

Set the emissive colour.

Parameters
colorThe new emissive colour.
Ghidra address:
NTSC-U/C: 0x004db9a0
Ghidra address:
PAL: 0x00519f40

Reimplemented in Rnd::PsMat.

◆ SetAlpha()

virtual void Rnd::Mat::SetAlpha ( float flAlpha)
virtual

Set the diffuse alpha.

Parameters
flAlphaThe new alpha.
Ghidra address:
NTSC-U/C: 0x004db9b0
Ghidra address:
PAL: 0x00519f50

Reimplemented in Rnd::PsMat.

◆ SetSpecular()

virtual void Rnd::Mat::SetSpecular ( const Color & color,
float flAlpha )
virtual

Set the specular colour and its alpha.

The colour argument is a Color on the same evidence as SetDiffuse(), the specular blend at 0x004d54d8 being the fourth of the four quadword blends. The alpha of the colour is discarded and the separate argument is stored in its place, and the only caller passes zero for it.

Parameters
colorThe new specular colour, whose alpha is discarded.
flAlphaThe new specular alpha.
Ghidra address:
NTSC-U/C: 0x004db9b8
Ghidra address:
PAL: 0x00519f58

Reimplemented in Rnd::PsMat.

◆ SetLighting()

virtual void Rnd::Mat::SetLighting ( int nEnable,
int nVertAmbient,
int nVertDiffuse,
int nVertSpecular,
int nVertEmissive,
int nVertAlpha,
int nNormalize )
virtual

Set the lighting enable flag, the five per-vertex source flags, and the normalise flag.

Parameters
nEnableWhether lighting applies at all.
nVertAmbientWhether the ambient term comes from the vertex.
nVertDiffuseWhether the diffuse term comes from the vertex.
nVertSpecularWhether the specular term comes from the vertex.
nVertEmissiveWhether the emissive term comes from the vertex.
nVertAlphaWhether the alpha comes from the vertex.
nNormalizeWhether normals are renormalised.
Ghidra address:
NTSC-U/C: 0x004dcbc0
Ghidra address:
PAL: 0x0051b160

◆ Refresh()

virtual void Rnd::Mat::Refresh ( )
virtual

Resynchronise the material after its state or its stage vector has changed.

Copy() finishes with this call. The name is inferred from the position of the call and from the stage vector the routine walks.

Ghidra address:
NTSC-U/C: 0x004dcd88
Ghidra address:
PAL: 0x0051b328

◆ SetMultiPass()

void Rnd::Mat::SetMultiPass ( int nMultiPass)

Set the multi-pass count.

Parameters
nMultiPassThe new count.
Ghidra address:
NTSC-U/C: 0x004db960
Ghidra address:
PAL: 0x00519f00

◆ SetFlat()

void Rnd::Mat::SetFlat ( int nFlat)

Set whether the surface shades flat.

Parameters
nFlatNon-zero for flat shading.
Ghidra address:
NTSC-U/C: 0x004db968
Ghidra address:
PAL: 0x00519f08

Member Data Documentation

◆ sClassName

HxStr Rnd::Mat::sClassName
static

Registered class name of Rnd::Mat, the string "Mat".

Ghidra address:
NTSC-U/C: 0x00700420
Ghidra address:
PAL: 0x00743e48

◆ mStages

std::vector<Stage> Rnd::Mat::mStages

◆ mBlend

BlendMode Rnd::Mat::mBlend
protected

◆ mEmissive

Color Rnd::Mat::mEmissive

Colour the surface emits.

Defaults to black with full alpha. +0x30

Public because HudPoints::SetFrame() at 0x00418de8 copies it directly through a Rnd::Mat pointer from outside the hierarchy to colour a text, and the image has no accessor for it.

◆ mAmbient

Color Rnd::Mat::mAmbient

Ambient colour.

Defaults to white. +0x40

Public because EmitFaceVu1Setup(), SelectLightForVertex(), and the PsMesh upload at 0x00583ba0 read it directly through Rnd::PsMat::sCurrent, and the image has no accessor.

◆ mDiffuse

Color Rnd::Mat::mDiffuse

Diffuse colour.

Defaults to white. +0x50

Public on the same evidence as mAmbient.

◆ mSpecular

Color Rnd::Mat::mSpecular

◆ mEnable

int Rnd::Mat::mEnable
protected

◆ mVertAmbient

int Rnd::Mat::mVertAmbient

Non-zero when the vertex colour supplies the ambient term in place of mAmbient.

Serialised as one byte. +0x74

Public because EmitFaceVu1Setup(), SelectLightForVertex(), and the PsMesh upload at 0x00583ba0 read it directly through Rnd::PsMat::sCurrent, and the image has no accessor.

◆ mVertDiffuse

int Rnd::Mat::mVertDiffuse

Non-zero when the vertex colour supplies the diffuse term in place of mDiffuse.

Serialised as one byte. +0x78

Public on the same evidence as mVertAmbient.

◆ mVertSpecular

int Rnd::Mat::mVertSpecular
protected

◆ mVertEmissive

int Rnd::Mat::mVertEmissive

Vertex emissive flag.

Serialised as one byte. +0x80

Public on the same evidence as mVertAmbient.

◆ mVertAlpha

int Rnd::Mat::mVertAlpha

Vertex alpha flag.

Serialised as one byte. +0x84

Public on the same evidence as mVertAmbient.

◆ mNormalize

int Rnd::Mat::mNormalize
protected

◆ mCull

Cull Rnd::Mat::mCull

< Winding the rasteriser discards. Public because Rnd::Mesh::FindCollisions() at 0x0047f950 reads it directly to decide whether a back-facing hit counts, which is access from outside the hierarchy, and the image has no accessor for it. +0x8c

◆ mMultiPass

int Rnd::Mat::mMultiPass
protected

◆ mFlat

int Rnd::Mat::mFlat

< Non-zero for flat shading. Serialised as one byte. Public because Rnd::Mesh::ComputeNormals() at 0x00485ef0 and Rnd::Mesh::WeldVerts() at 0x00483e70 read it directly, which is access from outside the hierarchy, and the image has no accessor for it. +0x94


The documentation for this class was generated from the following file: