Initial MP1 materials

This commit is contained in:
Jack Andersen 2015-07-24 17:43:49 -10:00
parent fb0abb652a
commit 4972c2ae95
4 changed files with 255 additions and 1 deletions

View File

@ -127,6 +127,95 @@ public:
}
};
/* RGBA8 structure (GXColor) */
struct GXColor : BigDNA
{
Value<atUint8> r;
Value<atUint8> g;
Value<atUint8> b;
Value<atUint8> a;
Delete expl;
void read(Athena::io::IStreamReader& reader)
{reader.readUBytesToBuf(&r, 4);}
void write(Athena::io::IStreamWriter& writer) const
{writer.writeUBytes(&r, 4);}
};
/* More GX structures */
enum GXAttrType
{
GX_NONE,
GX_DIRECT,
GX_INDEX8,
GX_INDEX16
};
enum GXTevColorArg {
GX_CC_CPREV = 0, /*!< Use the color value from previous TEV stage */
GX_CC_APREV = 1, /*!< Use the alpha value from previous TEV stage */
GX_CC_C0 = 2, /*!< Use the color value from the color/output register 0 */
GX_CC_A0 = 3, /*!< Use the alpha value from the color/output register 0 */
GX_CC_C1 = 4, /*!< Use the color value from the color/output register 1 */
GX_CC_A1 = 5, /*!< Use the alpha value from the color/output register 1 */
GX_CC_C2 = 6, /*!< Use the color value from the color/output register 2 */
GX_CC_A2 = 7, /*!< Use the alpha value from the color/output register 2 */
GX_CC_TEXC = 8, /*!< Use the color value from texture */
GX_CC_TEXA = 9, /*!< Use the alpha value from texture */
GX_CC_RASC = 10, /*!< Use the color value from rasterizer */
GX_CC_RASA = 11, /*!< Use the alpha value from rasterizer */
GX_CC_ONE = 12,
GX_CC_HALF = 13,
GX_CC_KONST = 14,
GX_CC_ZERO = 15 /*!< Use to pass zero value */
};
enum GXTevAlphaArg {
GX_CA_APREV = 0, /*!< Use the alpha value from previous TEV stage */
GX_CA_A0 = 1, /*!< Use the alpha value from the color/output register 0 */
GX_CA_A1 = 2, /*!< Use the alpha value from the color/output register 1 */
GX_CA_A2 = 3, /*!< Use the alpha value from the color/output register 2 */
GX_CA_TEXA = 4, /*!< Use the alpha value from texture */
GX_CA_RASA = 5, /*!< Use the alpha value from rasterizer */
GX_CA_KONST = 6,
GX_CA_ZERO = 7 /*!< Use to pass zero value */
};
enum GXTevOp {
GX_TEV_ADD = 0,
GX_TEV_SUB = 1,
GX_TEV_COMP_R8_GT = 8,
GX_TEV_COMP_R8_EQ = 9,
GX_TEV_COMP_GR16_GT = 10,
GX_TEV_COMP_GR16_EQ = 11,
GX_TEV_COMP_BGR24_GT = 12,
GX_TEV_COMP_BGR24_EQ = 13,
GX_TEV_COMP_RGB8_GT = 14,
GX_TEV_COMP_RGB8_EQ = 15,
GX_TEV_COMP_A8_GT = GX_TEV_COMP_RGB8_GT, // for alpha channel
GX_TEV_COMP_A8_EQ = GX_TEV_COMP_RGB8_EQ // for alpha channel
};
enum GXTevBias {
GX_TB_ZERO = 0,
GX_TB_ADDHALF = 1,
GX_TB_SUBHALF = 2,
};
enum GXTevScale {
GX_CS_SCALE_1 = 0,
GX_CS_SCALE_2 = 1,
GX_CS_SCALE_4 = 2,
GX_CS_DIVIDE_2 = 3
};
enum GXTevRegID {
GX_TEVPREV = 0,
GX_TEVREG0 = 1,
GX_TEVREG1 = 2,
GX_TEVREG2 = 3
};
/* Case-insensitive comparator for std::map sorting */
struct CaseInsensitiveCompare
{

22
DataSpec/DNAMP1/CMDL.hpp Normal file
View File

@ -0,0 +1,22 @@
#ifndef _DNAMP1_CMDL_HPP_
#define _DNAMP1_CMDL_HPP_
#include "../DNACommon/DNACommon.hpp"
#ifndef __atdna__
#include "CMDLMaterials.hpp"
#endif
namespace Retro
{
namespace DNAMP1
{
struct CMDL : BigDNA
{
DECL_DNA
};
}
}
#endif // _DNAMP1_CMDL_HPP_

View File

@ -0,0 +1,141 @@
#ifndef _DNAMP1_CMDL_MATERIALS_HPP_
#define _DNAMP1_CMDL_MATERIALS_HPP_
#include "../DNACommon/DNACommon.hpp"
namespace Retro
{
namespace DNAMP1
{
struct CMDLMaterial : BigDNA
{
Delete expl;
struct MaterialSetHead : BigDNA
{
DECL_DNA
Value<atUint32> textureCount;
Vector<UniqueID32, DNA_COUNT(textureCount)> textureIDs;
Value<atUint32> materialCount;
Vector<UniqueID32, DNA_COUNT(materialCount)> materialEndOffs;
} head;
struct Material : BigDNA
{
DECL_DNA
struct Flags : BigDNA
{
DECL_DNA
Value<atUint32> flags;
inline bool konstValuesEnabled() const {return flags & 0x8;}
inline void setKonstValuesEnabled(bool enabled) {flags &= ~0x8; flags |= enabled << 3;}
inline bool depthSorting() const {return flags & 0x10;}
inline void setDepthSorting(bool enabled) {flags &= ~0x10; flags |= enabled << 4;}
inline bool punchthroughAlpha() const {return flags & 0x20;}
inline void setPunchthroughAlpha(bool enabled) {flags &= ~0x20; flags |= enabled << 5;}
inline bool samusReflection() const {return flags & 0x40;}
inline void setSamusReflection(bool enabled) {flags &= ~0x40; flags |= enabled << 6;}
inline bool depthWrite() const {return flags & 0x80;}
inline void setDepthWrite(bool enabled) {flags &= ~0x80; flags |= enabled << 7;}
inline bool samusReflectionSurfaceEye() const {return flags & 0x100;}
inline void setSamusReflectionSurfaceEye(bool enabled) {flags &= ~0x100; flags |= enabled << 8;}
inline bool shadowOccluderMesh() const {return flags & 0x200;}
inline void setShadowOccluderMesh(bool enabled) {flags &= ~0x200; flags |= enabled << 9;}
inline bool samusReflectionIndirectTexture() const {return flags & 0x400;}
inline void setSamusReflectionIndirectTexture(bool enabled) {flags &= ~0x400; flags |= enabled << 10;}
inline bool lightmap() const {return flags & 0x800;}
inline void setLightmap(bool enabled) {flags &= ~0x800; flags |= enabled << 11;}
inline bool lightmapUVArray() const {return flags & 0x2000;}
inline void setLightmapUVArray(bool enabled) {flags &= ~0x2000; flags |= enabled << 13;}
inline atUint16 textureSlots() const {return flags >> 16;}
inline void setTextureSlots(atUint16 texslots) {flags &= ~0xffff0000; flags |= (atUint32)texslots << 16;}
} flags;
Value<atUint32> textureCount;
Vector<UniqueID32, DNA_COUNT(textureCount)> texureIdxs;
struct VAFlags : BigDNA
{
DECL_DNA
Value<atUint32> vaFlags;
inline GXAttrType position() const {return GXAttrType(vaFlags & 0x3);}
inline void setPosition(GXAttrType val) {vaFlags &= ~0x3; vaFlags |= val;}
inline GXAttrType normal() const {return GXAttrType(vaFlags >> 2 & 0x3);}
inline void setNormal(GXAttrType val) {vaFlags &= ~0xC; vaFlags |= val << 2;}
inline GXAttrType color0() const {return GXAttrType(vaFlags >> 4 & 0x3);}
inline void setColor0(GXAttrType val) {vaFlags &= ~0x30; vaFlags |= val << 4;}
inline GXAttrType color1() const {return GXAttrType(vaFlags >> 6 & 0x3);}
inline void setColor1(GXAttrType val) {vaFlags &= ~0xC0; vaFlags |= val << 6;}
inline GXAttrType tex0() const {return GXAttrType(vaFlags >> 8 & 0x3);}
inline void setTex0(GXAttrType val) {vaFlags &= ~0x300; vaFlags |= val << 8;}
inline GXAttrType tex1() const {return GXAttrType(vaFlags >> 10 & 0x3);}
inline void setTex1(GXAttrType val) {vaFlags &= ~0xC00; vaFlags |= val << 10;}
inline GXAttrType tex2() const {return GXAttrType(vaFlags >> 12 & 0x3);}
inline void setTex2(GXAttrType val) {vaFlags &= ~0x3000; vaFlags |= val << 12;}
inline GXAttrType tex3() const {return GXAttrType(vaFlags >> 14 & 0x3);}
inline void setTex3(GXAttrType val) {vaFlags &= ~0xC000; vaFlags |= val << 14;}
inline GXAttrType tex4() const {return GXAttrType(vaFlags >> 16 & 0x3);}
inline void setTex4(GXAttrType val) {vaFlags &= ~0x30000; vaFlags |= val << 16;}
inline GXAttrType tex5() const {return GXAttrType(vaFlags >> 18 & 0x3);}
inline void setTex5(GXAttrType val) {vaFlags &= ~0xC0000; vaFlags |= val << 18;}
inline GXAttrType tex6() const {return GXAttrType(vaFlags >> 20 & 0x3);}
inline void setTex6(GXAttrType val) {vaFlags &= ~0x300000; vaFlags |= val << 20;}
} vaFlags;
Value<atUint32> groupIdx;
Value<atUint32> konstCount;
Vector<GXColor, DNA_COUNT(konstCount)> konstColors;
enum GXBlendFactor
{
GX_BL_ZERO,
GX_BL_ONE,
GX_BL_SRCCLR,
GX_BL_INVSRCCLR,
GX_BL_SRCALPHA,
GX_BL_INVSRCALPHA,
GX_BL_DSTALPHA,
GX_BL_INVDSTALPHA
};
Value<atUint16> blendDstFac;
Value<atUint16> blendSrcFac;
Vector<atUint32, DNA_COUNT(flags.samusReflectionIndirectTexture())> indTexSlot;
Value<atUint32> colorChannelCount;
struct ColorChannel : BigDNA
{
DECL_DNA
Value<atUint32> flags;
inline bool lighting() const {return flags & 0x1;}
inline void setLighting(bool enabled) {flags &= ~0x1; flags |= enabled;}
inline bool useAmbient() const {return flags & 0x2;}
inline void setUseAmbient(bool enabled) {flags &= ~0x2; flags |= enabled << 1;}
inline bool useMaterial() const {return flags & 0x4;}
inline void setUseMaterial(bool enabled) {flags &= ~0x4; flags |= enabled << 2;}
inline bool lightmask() const {return flags >> 3 & 0xff;}
inline void setLightmask(atUint8 mask) {flags &= ~0x7f8; flags |= (atUint32)mask << 3;}
inline bool diffuseFn() const {return flags >> 11 & 0x3;}
inline void setDiffuseFn(atUint8 fn) {flags &= ~0x1800; flags |= (atUint32)fn << 11;}
inline bool attenuationFn() const {return flags >> 13 & 0x3;}
inline void setAttenuationFn(atUint8 fn) {flags &= ~0x6000; flags |= (atUint32)fn << 13;}
};
Vector<ColorChannel, DNA_COUNT(colorChannelCount)> colorChannels;
Value<atUint32> tevStageCount;
struct TEVStage : BigDNA
{
DECL_DNA
};
Vector<TEVStage, DNA_COUNT(tevStageCount)> tevStages;
};
void read(Athena::io::IStreamReader& reader)
{
head.read(reader);
}
void write(Athena::io::IStreamWriter& writer) const
{
head.write(writer);
}
};
}
}
#endif // _DNAMP1_CMDL_MATERIALS_HPP_

View File

@ -1,7 +1,9 @@
make_dnalist(liblist
PAK
MLVL
STRG)
STRG
CMDL
CMDLMaterials)
add_library(DNAMP1
DNAMP1.hpp DNAMP1.cpp
${liblist}