Home Risen Risen2 Risen3 Forum English Russian

Register FAQ Calendar Today's Posts
Page 1 of 2 12 Last »
Results 1 to 20 of 21
  1. #1 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    I started to explore the compiled Shader Material files.
    Here is a description/listing of the /data/common/materials/(null)._xmat:
    Code:
    ResourceHeader {
        GEU32       Revision;               // 0x31305247 ("GR01")
        GEU32       DataRevision;           // 0x31304D53 ("SM01")
        GEU32       PropertyObjectOffset;   // 0x00000028
        GEU32       PropertyObjectSize;     // 0x000000D2
        GEU32       ResourceDataOffset;     // 0x000000FA
        GEU32       ResourceDataSize;       // 0x00000579
        SFFFileTime RawModificationTime;    // 0x01C8328915EFBB00 (2007-11-29T13:09:34Z)
        GEChar      RawFileExtension[ 8 ];  // ".xshmat\0"
    }
    PropertyObject {
        GEU16  AccessorVersion;    // 0x0001
        GEBool HasPropertyObject;  // 0x01
        if( HasPropertyObject ) {
            GEU16    Unknown1;      // 0x0001
            GEBool   Unknown2;      // 0x01
            bCString ClassName;     // 0x0013, "eCMaterialResource2"
            GEU16    Unknown3;      // 0x0001
            GEBool   Unknown4;      // 0x00
            GEU16    ClassVersion;  // 0x00C9
            GEU16    Unknown5;      // 0x00C9
            GEU32    DataSize;      // 0x000000AC
            Data {
                PropertyData {
                    GEU16 Version;        // 0x00C9
                    GEU32 PropertyCount;  // 0x00000004
                    Property[ 0 ] {
                        bCString Name;      // 0x000E, "PhysicMaterial"
                        bCString Type;      // 0x0029, "bTPropertyContainer<enum eEShapeMaterial>"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000006
                        Data {
                            GEU16 Version;  // 0x00C9
                            GEU32 Value;    // 0x00000000 (eEShapeMaterial_None)
                        }
                    }
                    Property[ 1 ] {
                        bCString Name;      // 0x0011, "IgnoredByTraceRay"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x00 (False)
                        }
                    }
                    Property[ 2 ] {
                        bCString Name;      // 0x0010, "DisableCollision"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x00 (False)
                        }
                    }
                    Property[ 3 ] {
                        bCString Name;      // 0x000F, "DisableResponse"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x00 (False)
                        }
                    }
                }
                ClassData {
                    GEU16 Version;  // 0x00C9
                }
            }
        }
    }
    ResourceData {
        GEU16  AccessorVersion;    // 0x0001
        GEBool HasPropertyObject;  // 0x01
        if( HasPropertyObject ) {
            GEU16    Unknown1;      // 0x0001
            GEBool   Unknown2;      // 0x01
            bCString ClassName;     // 0x000F, "eCShaderDefault"
            GEU16    Unknown3;      // 0x0001
            GEBool   Unknown4;      // 0x00
            GEU16    ClassVersion;  // 0x0003
            GEU16    Unknown5;      // 0x00C9
            GEU32    DataSize;      // 0x00000557
            Data {
                PropertyData {
                    GEU16 Version;        // 0x00C9
                    GEU32 PropertyCount;  // 0x0000000A
                    Property[ 0 ] {
                        bCString Name;      // 0x0012, "TransformationType"
                        bCString Type;      // 0x0038, "bTPropertyContainer<enum eEShaderMaterialTransformation>"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000006
                        Data {
                            GEU16 Version;  // 0x00C9
                            GEU32 Value;    // 0x00000003 (eEShaderMaterialTransformation_Tree_Branches)
                        }
                    }
                    Property[ 1 ] {
                        bCString Name;      // 0x000E, "EnableSpecular"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x01 (True)
                        }
                    }
                    Property[ 2 ] {
                        bCString Name;      // 0x000F, "DisableLighting"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x00 (False)
                        }
                    }
                    Property[ 3 ] {
                        bCString Name;      // 0x0009, "BlendMode"
                        bCString Type;      // 0x0033, "bTPropertyContainer<enum eEShaderMaterialBlendMode>"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000006
                        Data {
                            GEU16 Version;  // 0x00C9
                            GEU32 Value;    // 0x00000001 (eEShaderMaterialBlendMode_Masked)
                        }
                    }
                    Property[ 4 ] {
                        bCString Name;      // 0x000D, "MaskReference"
                        bCString Type;      // 0x0004, "char"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEU8 Value;  // 0x00
                        }
                    }
                    Property[ 5 ] {
                        bCString Name;      // 0x0010, "MaxShaderVersion"
                        bCString Type;      // 0x0031, "bTPropertyContainer<enum eEShaderMaterialVersion>"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000006
                        Data {
                            GEU16 Version;  // 0x00C9
                            GEU32 Value;    // 0x00000003 (eEShaderMaterialVersion_3_0)
                        }
                    }
                    Property[ 6 ] {
                        bCString Name;      // 0x0010, "FallbackMaterial"
                        bCString Type;      // 0x001F, "bCImageOrMaterialResourceString"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000002
                        Data {
                            bCString Value;  // 0x0000 ("")
                        }
                    }
                    Property[ 7 ] {
                        bCString Name;      // 0x000C, "UseDepthBias"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x00 (False)
                        }
                    }
                    Property[ 8 ] {
                        bCString Name;      // 0x0011, "TradeAlphaAsSolid"
                        bCString Type;      // 0x0004, "bool"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000001
                        Data {
                            GEBool Value;  // 0x00 (False)
                        }
                    }
                    Property[ 9 ] {
                        bCString Name;      // 0x000E, "RenderPriority"
                        bCString Type;      // 0x0003, "int"
                        GEU16    Version;   // 0x001E
                        GEU32    DataSize;  // 0x00000004
                        Data {
                            GEInt Value;  // 0x00000000
                        }
                    }
                }
                ClassData {
                    GEU16 Version;  // 0x0003
                    ColorSrcDiffuse {
                        GEU32 Version;  // 0x0000029A
                        if( Version >= 666 ) {
                            GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                            GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                        }
                        bCGuid Token;  // {80926BF2-8465-4C9D-9FAF-87AAB09AB553}, 0x01, __, __, __
                    }
                    ColorSrcOpacity {
                        GEU32 Version;  // 0x0000029A
                        if( Version >= 666 ) {
                            GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                            GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                        }
                        bCGuid Token;  // {________-____-____-____-____________}, 0x00, __, __, __
                    }
                    ColorSrcSelfIllumination {
                        GEU32 Version;  // 0x0000029A
                        if( Version >= 666 ) {
                            GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                            GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                        }
                        bCGuid Token;  // {________-____-____-____-____________}, 0x00, __, __, __
                    }
                    ColorSrcSpecular {
                        GEU32 Version;  // 0x0000029A
                        if( Version >= 666 ) {
                            GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                            GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                        }
                        bCGuid Token;  // {49F73761-EC0C-4CD1-82D5-EF4FD671798F}, 0x01, __, __, __
                    }
                    ColorSrcSpecularPower {
                        GEU32 Version;  // 0x0000029A
                        if( Version >= 666 ) {
                            GEU32 ColorComponent;  // 0x00000005 (eEShaderColorSrcComponent_Alpha)
                            GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                        }
                        bCGuid Token;  // {49F73761-EC0C-4CD1-82D5-EF4FD671798F}, 0x01, __, __, __
                    }
                    ColorSrcNormal {
                        GEU32 Version;  // 0x0000029A
                        if( Version >= 666 ) {
                            GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                            GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                        }
                        bCGuid Token;  // {________-____-____-____-____________}, 0x00, __, __, __
                    }
                    if( Version >= 2 ) {
                        ColorSrcDistortion {
                            GEU32 Version;  // 0x0000029A
                            if( Version >= 666 ) {
                                GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                                GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                            }
                            bCGuid Token;  // {________-____-____-____-____________}, 0x00, __, __, __
                        }
                    }
                    if( Version >= 3 ) {
                        ColorSrcLightEmission {
                            GEU32 Version;  // 0x0000029A
                            if( Version >= 666 ) {
                                GEU32 ColorComponent;  // 0x00000000 (eEShaderColorSrcComponent_None)
                                GEU32 ColorModifier;   // 0x00000000 (eEShaderColorModifier_None)
                            }
                            bCGuid Token;  // {________-____-____-____-____________}, 0x00, __, __, __
                        }
                    }
                    eCShaderBase {
                        GEU16 Version;  // 0x0001
                        eCShaderEllementBase {
                            GEU16  Version;       // 0x0002
                            bCGuid Token;         // {5578023A-6597-42BE-BE8C-6BD44ADB6F9E}, 0x01, __, __, __
                            bCRect EditorLayout;  // 0x00000020, 0x00000094, 0x00000110, 0x0000013C
                            if( Version >= 2 ) {
                                GEBool Unknown;  // 0x00 (False)
                            }
                        }
                        GEU32 ShaderEllementCount;  // 0x00000002
                        ShaderEllement[ 0 ] {
                            GEU16  AccessorVersion;    // 0x0001
                            GEBool HasPropertyObject;  // 0x01
                            if( HasPropertyObject ) {
                                GEU16    Unknown1;      // 0x0001
                                GEBool   Unknown2;      // 0x01
                                bCString ClassName;     // 0x0011, "eCColorSrcSampler"
                                GEU16    Unknown3;      // 0x0001
                                GEBool   Unknown4;      // 0x00
                                GEU16    ClassVersion;  // 0x0001
                                GEU16    Unknown5;      // 0x00C9
                                GEU32    DataSize;      // 0x00000182
                                Data {
                                    PropertyData {
                                        GEU16 Version;        // 0x00C9
                                        GEU32 PropertyCount;  // 0x00000005
                                        Property[ 0 ] {
                                            bCString Name;      // 0x000D, "ImageFilePath"
                                            bCString Type;      // 0x0015, "bCImageResourceString"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000002
                                            Data {
                                                bCString Value;  // 0x0000 ("")
                                            }
                                        }
                                        Property[ 1 ] {
                                            bCString Name;      // 0x000A, "TexRepeatU"
                                            bCString Type;      // 0x0033, "bTPropertyContainer<enum eEColorSrcSampleTexRepeat>"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000006
                                            Data {
                                                GEU16 Version;  // 0x00C9
                                                GEU32 Value;    // 0x00000000 (eEColorSrcSampleTexRepeat_Wrap)
                                            }
                                        }
                                        Property[ 2 ] {
                                            bCString Name;      // 0x000A, "TexRepeatV"
                                            bCString Type;      // 0x0033, "bTPropertyContainer<enum eEColorSrcSampleTexRepeat>"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000006
                                            Data {
                                                GEU16 Version;  // 0x00C9
                                                GEU32 Value;    // 0x00000000 (eEColorSrcSampleTexRepeat_Wrap)
                                            }
                                        }
                                        Property[ 3 ] {
                                            bCString Name;      // 0x000E, "AnimationSpeed"
                                            bCString Type;      // 0x0005, "float"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000004
                                            Data {
                                                GEFloat Value;  // 0x00000000 (0.0)
                                            }
                                        }
                                        Property[ 4 ] {
                                            bCString Name;      // 0x000C, "SwitchRepeat"
                                            bCString Type;      // 0x0030, "bTPropertyContainer<enum eEColorSrcSwitchRepeat>"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000006
                                            Data {
                                                GEU16 Version;  // 0x00C9
                                                GEU32 Value;    // 0x00000000 (eEColorSrcSwitchRepeat_Repeat)
                                            }
                                        }
                                    }
                                    ClassData {
                                        GEU16 Version;  // 0x0001
                                        TexCoord {
                                            eCTexCoordSrcProxy {
                                                GEInt  VertexTexCoord;  // 0x00000000
                                                bCGuid Token;           // {________-____-____-____-____________}, 0x00, __, __, __
                                            }
                                        }
                                        GEU32 Unknown;  // 0xFFFFFFFF
                                        eCColorSrcBase {
                                            GEU16 Version;  // 0x0001
                                            eCShaderEllementBase {
                                                GEU16  Version;       // 0x0002
                                                bCGuid Token;         // {80926BF2-8465-4C9D-9FAF-87AAB09AB553}, 0x01, __, __, __
                                                bCRect EditorLayout;  // 0x000001B0, 0x00000020, 0x000002A0, 0x000000C8
                                                if( Version >= 2 ) {
                                                    GEBool Unknown;  // 0x00 (False)
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        ShaderEllement[ 1 ] {
                            GEU16  AccessorVersion;    // 0x0001
                            GEBool HasPropertyObject;  // 0x01
                            if( HasPropertyObject ) {
                                GEU16    Unknown1;      // 0x0001
                                GEBool   Unknown2;      // 0x01
                                bCString ClassName;     // 0x0012, "eCColorSrcConstant"
                                GEU16    Unknown3;      // 0x0001
                                GEBool   Unknown4;      // 0x00
                                GEU16    ClassVersion;  // 0x0001
                                GEU16    Unknown5;      // 0x00C9
                                GEU32    DataSize;      // 0x00000074
                                Data {
                                    PropertyData {
                                        GEU16 Version;        // 0x00C9
                                        GEU32 PropertyCount;  // 0x00000002
                                        Property[ 0 ] {
                                            bCString Name;      // 0x0005, "Color"
                                            bCString Type;      // 0x000C, "bCFloatColor"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000010
                                            Data {
                                                bCFloatColor Value;  // 0x100F1960 (__vftbl?!), 0.0,  0.0, 0.0
                                            }
                                        }
                                        Property[ 1 ] {
                                            bCString Name;      // 0x0005, "Alpha"
                                            bCString Type;      // 0x0005, "float"
                                            GEU16    Version;   // 0x001E
                                            GEU32    DataSize;  // 0x00000004
                                            Data {
                                                GEFloat Value;  // 0x00000000 (0.0)
                                            }
                                        }
                                    }
                                    ClassData {
                                        GEU16 Version;  // 0x0001
                                        eCColorSrcBase {
                                            GEU16 Version;  // 0x0001
                                            eCShaderEllementBase {
                                                GEU16  Version;       // 0x0002
                                                bCGuid Token;         // {49F73761-EC0C-4CD1-82D5-EF4FD671798F}, 0x01, __, __, __
                                                bCRect EditorLayout;  // 0x000001B0, 0x000000E8, 0x000002A0, 0x00000190
                                                if( Version >= 2 ) {
                                                    GEBool Unknown;  // 0x00 (False)
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    The resource data is an eCShaderBase-based property object.
    The spec is not sufficient to read all *._xmat (other classes wil be documented later) - but you can already get an idea what is included in a Shader Material and how proxies are resolved by Tokens to ShaderEllements.
    Attached Files
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 04.12.2010 at 03:40.

  2. #2 Reply With Quote
    Ehrengarde Baltram's Avatar
    Join Date
    Jun 2006
    Posts
    2,263


    It so happens that I had just started working on a xmat editor (only to clone & modify existing mats) - so it's really convenient to have all this info about 'ClassData' now, I didn't quite understand this before. Thank you!
    Baltram is offline

  3. #3 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    First let’s recap how property objects (derived from bCObjectBase) are streamed with/without an accessor:
    Code:
    bCAccessorPropertyObject {
        GEU16  Version;  // 0x0001
        GEBool HasPropertyObject;
        if( GETrue == HasPropertyObject ) {
            GEU16    Reserved1;  // 0x0001
            GEBool   Reserved2;  // 0x01 (GETrue)
            bCString ClassName;
            GEU16    Reserved3;  // 0x0001
            GEBool   Reserved4;  // 0x00 (GEFalse)
            GEU16    ClassVersion;
            bCObjectBase {
                GEU16 Version;  // 0x00C9 (201)
                GEU32 Size;
                Data {
                    PropertyData {
                        GEU16 Version;  // 0x00C9 (201)
                        GEU32 Count;
                        for( Count ) {
                            bCString Name;
                            bCString Type;
                            GEU16    Version;  // 0x001E (30)
                            GEU32    Size;
                            Data {
                                GEU8 Value[ Size ];
                            }
                        }
                    }
                    ClassData {
                        // ClassName::OnRead/OnWrite()
                        // GEU16 ClassVersion; ...
                    }
                }
            }
        }
    }
    All properties and the class data block can be skipped.
    But
    • to parse the property data your have to support all used classes (objects can also be properties),
    • and to parse the class data blocks you have to know how each used <ClassName>::OnRead/OnWrite is implemented (including the version handling).


    Compiled Shader Material resources are nothing else than bCAccessorPropertyObject<eCMaterialResource2> (Object) as header and bCAccessorPropertyObject<eCShaderBase> (Object.GetShader) as data.

    ps: 201 is the current property system persistence version - therefore you will see it very often.

    pps: For some classes (eCGfxObject, eCNode, eCVegetation_Grid, eCVegetation_GridNode, gCWaterSubZone_PS) the PropertyObjectType seems to include a Flag (0x00000001) that results in skipping/ignoring the properties while reading/writing it. In this case the bCObjectBase block only contains the ClassData (ClassName::OnRead/OnWrite).
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 07.01.2011 at 13:42.

  4. #4 Reply With Quote
    Ehrengarde Baltram's Avatar
    Join Date
    Jun 2006
    Posts
    2,263
    Quote Originally Posted by NicoDE View Post
    • to parse the property data your have to support all used classes (objects can also be properties),
    • and to parse the class data blocks you have to know how each used <ClassName>::OnRead/OnWrite is implemented (including the version handling).
    That would be the clean way.

    But to access the most important data like texture paths and have, that way, at least a provisoric control over the materials, wouldn't it suffice to provide
    • only the commonly used property classes (rest can be skipped or treated as GEU8[size])
    • dummy functions for each type of ClassData found in the ~500 material files (or even skip ClassData)
    ?

    For example TPLEdit is a bit like that, I guess.

    Wondering what's the reason for them to choose 666, besides.
    Baltram is offline

  5. #5 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    Some notes about "random" values...

    Code:
    bCGuid {
        GUID   Guid;
        GEBool Valid;
        GEU8   Alignment[ 3 ];
    }
    bCGuid is streamed as block of 0x14 (20) bytes - this includes the alignment that compiler generated for this class. The Alignment bytes are almost always filled with garbage.
    The value of Guid should be ignored if Valid is GEFalse (0x00).

    bCFloatColor streaming seems to be implemented as Read/Write(this, sizeof(*this)). But bCFloatColor has virtual functions. Therefore the implicitly generated member __vftbl is also streamed. This is very dangerous - after reading a bCFloatColor the virtual function table pointer might/will point to the wrong memory location (the virtual functions cannot be safely called anymore).
    Therefore you should set the first pointer to 0 if you generate/modify bCFloatColor.

    Quote Originally Posted by Baltram View Post
    Wondering what's the reason for them to choose 666, besides.
    The first version of eCColorSrcProxy had only ColorComponent and Token. Later they introduced a Version (the first version value must be greater than the highest value of eEShaderColorSrcComponent that might happen in the future).
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 04.12.2010 at 00:45.

  6. #6 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    Let’s talk about ClassData blocks

    Code:
    eCColorSrcProxy {
        eEShaderColorSrcComponent ColorComponent;
        if( ColorComponent >= 666 ) {
            eEShaderColorSrcComponent ColorComponent;
            eEShaderColorModifier     ColorModifier;
        }
        bCGuid Token;
    }
    
    enum eEShaderColorModifier
    {
        eEShaderColorModifier_Default  = 0x00000000,  // ""
        eEShaderColorModifier_Negate   = 0x00000001,  // "-"
        eEShaderColorModifier_Invert   = 0x00000002,  // "1-"
        eEShaderColorModifier_Saturate = 0x00000003,  // "saturate"
        eEShaderColorModifier_Ceil     = 0x00000004,  // "ceil"
        eEShaderColorModifier_Floor    = 0x00000005,  // "floor"
        eEShaderColorModifier_Abs      = 0x00000006,  // "abs"
        eEShaderColorModifier_Frac     = 0x00000007,  // "frac"
        eEShaderColorModifier_Count,
        eEShaderColorModifier_ForceDWORD = 0x7FFFFFFF
    };
    
    enum eEShaderColorSrcComponent
    {
        eEShaderColorSrcComponent_Default = 0x00000000,  // ""
        eEShaderColorSrcComponent_RGB     = 0x00000001,  // ".rgb"
        eEShaderColorSrcComponent_R       = 0x00000002,  // ".r"
        eEShaderColorSrcComponent_G       = 0x00000003,  // ".g"
        eEShaderColorSrcComponent_B       = 0x00000004,  // ".b"
        eEShaderColorSrcComponent_A       = 0x00000005,  // ".a"
        eEShaderColorSrcComponent_Count,
        eEShaderColorSrcComponent_ForceDWORD = 0x7FFFFFFF
    };
    eCColorSrcProxy.Token is used to resolve the ColorSrc property to a Shader Element.

    eCShaderBase is derived from eCShaderEllementBase and the class data includes an array of Shader Elements:
    Code:
    eCShaderEllementBase {
        GEU16  Version;  // 0x0002
        bCGuid Token;
        bCRect EditorLayout;
        if( Version >= 2 ) {
            GEBool Unknown;
        }
    }
    
    eCShaderBase {
        GEU16                Version;  // 0x0001
        eCShaderEllementBase Inherited;
        GEU32                ShaderElementCount;
        for( ShaderElementCount ) {
            bCAccessorPropertyObject< eCShaderEllementBase > ShaderElement;
        }
    }
    Here are the other Shader class data blocks:
    Code:
    eCShaderDefault {
        GEU16           Version;  // 0x0005
        eCColorSrcProxy ColorSrcDiffuse;
        eCColorSrcProxy ColorSrcOpacity;
        eCColorSrcProxy ColorSrcSelfIllumination;
        eCColorSrcProxy ColorSrcSpecular;
        eCColorSrcProxy ColorSrcSpecularPower;
        eCColorSrcProxy ColorSrcNormal;
        if( Version >= 2 ) {
            eCColorSrcProxy ColorSrcDistortion;
        }
        if( Version >= 3 ) {
            eCColorSrcProxy ColorSrcLightEmission;
        }
        eCShaderBase Inherited;
    }
    Code:
    eCShaderLeafs {
        eCShaderDefault Inherited;
    }
    Code:
    eCShaderLightStreaks {
        GEU16           Version;  // 0x0001
        eCColorSrcProxy ColorSrcDiffuse;
        eCShaderBase    Inherited;
    }
    Code:
    eCShaderParticle {
        GEU16           Version;  // 0x0001
        eCColorSrcProxy ColorSrcDiffuse;
        eCShaderBase    Inherited;
    }
    Code:
    eCShaderSkyDome {
        GEU16           Version;  // 0x0001
        eCColorSrcProxy ColorSrcClouds;
        eCColorSrcProxy ColorSrcAbsorbation;
        eCShaderBase    Inherited;
    }
    ps: The registered(possible/allowed) values for the bTPropertyContainer<enum Xxx> are listed here.
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 04.12.2010 at 03:39.

  7. #7 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    The class data blocks of the Color Source elements:
    Code:
    eCColorSrcBase {
        GEU16                Version;  // 0x0001
        eCShaderEllementBase Inherited;
    }
    Code:
    eCColorSrcBlend {
        GEU16           Version;  // 0x0001
        eCColorSrcProxy ColorSrc1;
        eCColorSrcProxy ColorSrc2;
        eCColorSrcProxy BlendSrc;
        eCColorSrcBase  Inherited;
    }
    Code:
    eCColorSrcCamDistance {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcCamObstacle {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcCombiner {
        GEU16           Version;  // 0x0001
        eCColorSrcProxy ColorSrc1;
        eCColorSrcProxy ColorSrc2;
        eCColorSrcBase  Inherited;
    }
    Code:
    eCColorSrcConstant {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcConstantAnimation {
        GEU16          Version;  // 0x0001
        eCColorScale   ColorScale;
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcConstantSwitch {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcCubeSampler {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcFresnel {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcMask {
        GEU16           Version;  // 0x0001
        eCColorSrcProxy Color;
        eCColorSrcBase  Inherited;
    }
    Code:
    eCColorSrcSampler {
        GEU16              Version;  // 0x0001
        eCTexCoordSrcProxy TexCoord;
        GEU32              Unknown;  // 0xFFFFFFFF
        eCColorSrcBase     Inherited;
    }
    Code:
    eCColorSrcSkydomeSampler {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    }
    Code:
    eCColorSrcVertexColor {
        GEU16          Version;  // 0x0001
        eCColorSrcBase Inherited;
    };
    And the referred member types:
    Code:
    eCColorScale {
        GEU32 Version;  // 0x00000001
        GEU32 ArraySize;
        if( ArraySize ) {
            GEU32 ItemCount;
            for( ItemCount ) {
                GEFloat Time;
                GEFloat Red;
                GEFloat Green;
                GEFloat Blue;
                GEFloat Alpha;
            }
        }
    }
    Code:
    eCTexCoordSrcProxy {
        GEInt  VertexTexCoord;
        bCGuid Token;
    }
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 04.12.2010 at 03:18.

  8. #8 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    And finally the class data blocks of the Texture Coordinate Source elements:
    Code:
    eCTexCoordSrcBase {
        GEU16                Version;  // 0x0001
        eCShaderEllementBase Inherited;
    }
    Code:
    eCTexCoordSrcBumpOffset {
        GEU16              Version;  // 0x0001
        eCColorSrcProxy    Height;
        eCTexCoordSrcProxy TexCoord;
        eCTexCoordSrcBase  Inherited;
    }
    Code:
    eCTexCoordSrcColor {
        GEU16             Version;  // 0x0001
        eCColorSrcProxy   ColorU;
        eCColorSrcProxy   ColorV;
        eCTexCoordSrcBase Inherited;
    }
    Code:
    eCTexCoordSrcOscillator {
        GEU16              Version;  // 0x0001
        eCTexCoordSrcProxy TexCoord;
        eCTexCoordSrcBase  Inherited;
    }
    Code:
    eCTexCoordSrcReflect {
        eCTexCoordSrcBase Inherited;
    }
    Code:
    eCTexCoordSrcRotator {
        GEU16              Version;  // 0x0001
        eCTexCoordSrcProxy TexCoord;
        eCTexCoordSrcBase  Inherited;
    }
    Code:
    eCTexCoordSrcScale {
        GEU16              Version;  // 0x0001
        eCTexCoordSrcProxy TexCoord;
        eCTexCoordSrcBase  Inherited;
    }
    Code:
    eCTexCoordSrcScroller {
        GEU16              Version;  // 0x0001
        eCTexCoordSrcProxy TexCoord;
        eCTexCoordSrcBase  Inherited;
    };
    Good night to everyone.
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 04.12.2010 at 10:42.

  9. #9 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    How to "upgrade" an eCShaderDefault to the current version:
    Code:
    if( Version < 4 ) {
        bCString TransformationTypeString;
        switch( TransformationType )
        {
        case eEShaderMaterialTransformation_Default:
            TransformationTypeString = "Default";
            break;
        case eEShaderMaterialTransformation_Skinned:
            TransformationTypeString = "Skinned";
            break;
        case eEShaderMaterialTransformation_Morphed:
            TransformationTypeString = "Morphed";
            break;
        case eEShaderMaterialTransformation_Skinned_Morphed:
            TransformationTypeString = "SkinnedMorphed";
            break;
        }
        if( !TransformationTypeString.IsEmpty() )
        {
            FrozenOverlayMaterial      = "Special_Overlay_Frozen_"      + TransformationTypeString + "._xmat";
            BurnedOverlayMaterial      = "Special_Overlay_Burned_"      + TransformationTypeString + "._xmat";
            HighlightedOverlayMaterial = "Special_Overlay_Highlighted_" + TransformationTypeString + "._xmat";
        }
    }
    Code:
    if( Version < 5 ) {
        switch( TransformationType ) {
        case eEShaderMaterialTransformation_Skinned:
        case eEShaderMaterialTransformation_Morphed:
        case eEShaderMaterialTransformation_Skinned_Morphed:
            BRDFLightingType = eEShaderMaterialBRDFType_WrapAround;
            break;
        }
    }
    ps: "Special_Overlay_*_Morphed._xmat" do not exists - however, this is what the Engine does when it loads older eCShaderDefault class data.
    Attached Files
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 04.12.2010 at 15:06.

  10. #10 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    There was still the question how the class data is interpreted/used...

    Every shader object has Proxy (eCColorSrcProxy) properties that are resolved by Token to a Shader Element.

    Given the (null)._xmat in the first post this means:
    • ResourceData.Data.ClassData.ColorSrcDiffuse.Token is Valid and the Value is {80926BF2-8465-4C9D-9FAF-87AAB09AB553}
    • Now we iterate over ResourceData.Data.ClassData.eCShaderBase.ShaderEllement[] to look for a valid and matching [].*.eCShaderEllementBase.Token.
    • The first Shader Element matches and is therefore used as Source for the Diffuse Color.
    Note that the Shader Elements also use Proxies with Tokens to resolve properties to Shader Elements, e.g. ResourceData.Data.ClassData.eCShaderBase.ShaderEllement[0].Data.ClassData.TexCoord.eCTexCoordSrcProxy.Token (but the Token is not Valid and therefore does not resolve to a Shader Element).
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 05.12.2010 at 19:09.

  11. #11 Reply With Quote
    Ehrengarde Baltram's Avatar
    Join Date
    Jun 2006
    Posts
    2,263
    There is one enum in the xmat files I can't find in your enum list: eEShaderMaterialAmbientType. Maybe you could look this up if it's not too time-consuming?
    Baltram is offline

  12. #12 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    Looks like a deprecated property that has been introduced with eCShaderDefault version 4 and removed with version 5.
    As of Engine.dll version 1.0.95642.0 the eCShaderDefault class does not have a property named "AmbientLightType".
    If I have some spare time, I’ll have a look at the oldest version available (EFIGS release).
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 07.12.2010 at 13:15.

  13. #13 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    According to the .\data\compiled\effects\shadermaterial\ge_default.fxh:
    // enum
    #define EAmbientLightType_None 0
    #define EAmbientLightType_Simple 1
    #define EAmbientLightType_Complex 2
    The enumeration should look like this:
    Code:
    // eCShaderDefault.AmbientLightType (deprecated)
    enum eEShaderMaterialAmbientType
    {
        eEShaderMaterialAmbientType_None    = 0x00000000,
        eEShaderMaterialAmbientType_Simple  = 0x00000001,
        eEShaderMaterialAmbientType_Complex = 0x00000002
    };
    Good luck

    ps: The XFX_AMBIENTLIGHTTYPE shader macro now depends on the shader version: eCShaderVersionDefault_2_0 set it to 0x00000001 (Simple) and eCShaderVersionDefault_3_0 to 0x00000002 (Complex).
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 07.12.2010 at 13:39.

  14. #14 Reply With Quote
    Ehrengarde Baltram's Avatar
    Join Date
    Jun 2006
    Posts
    2,263
    Thanks!
    Baltram is offline

  15. #15 Reply With Quote
    Ehrengarde Baltram's Avatar
    Join Date
    Jun 2006
    Posts
    2,263
    Based on the information from this thread, I finished today a small xmat to ASCII converter (as an intermediate result of my work on a xmat editor). There are quite some inaccuracies in expressing the structure but at least it seems to work with every existing xmat: xmat2txt
    Baltram is offline

  16. #16 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    Thanks for sharing your tool
    You might have mentioned that the Microsoft Visual C++ 2010 Redistributable Package (x86) is required.

    ps: you should handle empty RawFileExtension values (e.g. in Arch_Temple_Throne_01_Diffuse_01)
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline Last edited by NicoDE; 13.12.2010 at 10:43.

  17. #17 Reply With Quote
    Ehrengarde Baltram's Avatar
    Join Date
    Jun 2006
    Posts
    2,263
    Quote Originally Posted by NicoDE View Post
    You might have mentioned that the Microsoft Visual C++ 2010 Redistributable Package (x86) is required.
    Oh, I didn't think about that, sorry. Btw, would you recommend me compiling my code in VC++ 2005 rather than 2010?
    Quote Originally Posted by NicoDE View Post
    ps: you should handle empty RawFileExtension values (e.g. in Arch_Temple_Throne_01_Diffuse_01)
    ...so that the output is ".xshmat\0" anyway?
    Baltram is offline

  18. #18 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    Quote Originally Posted by Baltram View Post
    Btw, would you recommend me compiling my code in VC++ 2005 rather than 2010?
    I think that this is not important (doesn’t matter) as long as you are not linking against Risen’s Genome libraries and use the exported classes (but I assume it would even work with MSVC 2010).
    The users of your tool can install the MSVC runtimes and can using it - no big problem.

    Quote Originally Posted by Baltram View Post
    ...so that the output is ".xshmat\0" anyway?
    Nothing special, but your text output contains non-printable characters (#0) and some text editors just do not like it
    I don’t know how the raw files (.xshmat) are formatted and what they contain. The import method is not implemented in this resource class... therefore I have no idea how to re-create the raw materials - but with an/your editor there is no need for the raw files...
    "Unter diesen schwierigen Umständen bin ich mir sicher, daß diese guten Menschen meinen augenblicklichen Bedarf an deren Gold verstehen werden." -- Connor
    NicoDE is offline

  19. #19 Reply With Quote
    Ranger
    Join Date
    Aug 2008
    Posts
    174
    Quote Originally Posted by NicoDE View Post
    Some notes about "random" values...
    bCFloatColor streaming seems to be implemented as Read/Write(this, sizeof(*this)). But bCFloatColor has virtual functions. Therefore the implicitly generated member __vftbl is also streamed. This is very dangerous - after reading a bCFloatColor the virtual function table pointer might/will point to the wrong memory location (the virtual functions cannot be safely called anymore).
    Therefore you should set the first pointer to 0 if you generate/modify bCFloatColor.
    When creating your own code not based on game engine (SDK) first four bytes of the bCFloatColor class data in the file should be skipped at all. When using game engine (SDK) to read/write bCFloatColor first 4 bytes and __vftbl are automatically taken into account (__vftbl is saved and restored to a proper value) so no need to worry about it:
    Spoiler:(zum lesen bitte Text markieren)

    Code:
    // virtual bCIStream & operator << ( bCIStream & );
    int __thiscall bCFloatColor__operator__(void *this, int a2)
    {
      int result; // eax@1
      void *v3; // esi@1
      int v4; // ebx@1
    
      v3 = this;
      v4 = *(_DWORD *)this;
      (*(void (__thiscall **)(int, void *, signed int))(*(_DWORD *)a2 + 4))(a2, this, 16);
      result = a2;
      *(_DWORD *)v3 = v4;
      return result;
    }
    PowerGamer is offline

  20. #20 Reply With Quote
    research NicoDE's Avatar
    Join Date
    Dec 2004
    Posts
    7,404
    Thanks for the clarification!

    Using the SharedBase TIL the pseudo code looks like this:
    Code:
    bCIStream *__thiscall bCFloatColor::operator<<(bCFloatColor *this, bCIStream *stream)
    {
      bCFloatColor *self; // esi@1
      const bCColorBase_vftable *vftable; // ebx@1
      bCIStream *result; // eax@1
    
      self = this;
      vftable = this->__vfptr;
      stream->__vfptr->ReadBuffer(stream, this, 0x10u);
      result = stream;
      self->__vfptr = vftable;
      return result;
    }
    NicoDE is offline

Page 1 of 2 12 Last »

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •