示例#1
0
        protected override void OnPopulate()
        {
            StageGroup *grp    = Header->First;
            int         offset = 0x80; //There are 8 groups max

            for (int r = 0; r < 8; r++, grp = grp->Next, offset += 0x30)
            {
                if (((byte *)Header)[offset] == 0x61)
                {
                    TEVStage s0 = new TEVStage(r * 2);

                    KSel      KSEL = new KSel(grp->ksel.Data.Value);
                    RAS1_TRef TREF = new RAS1_TRef(grp->tref.Data.Value);

                    s0.rawColEnv   = grp->eClrEnv.Data.Value;
                    s0.rawAlphaEnv = grp->eAlpEnv.Data.Value;
                    s0.rawCMD      = grp->eCMD.Data.Value;

                    s0.kcsel = KSEL.KCSEL0;
                    s0.kasel = KSEL.KASEL0;

                    s0.ti = TREF.TI0;
                    s0.tc = TREF.TC0;
                    s0.cc = TREF.CC0;
                    s0.te = TREF.TE0;

                    s0.getValues();
                    AddChild(s0, false);

                    if (grp->oClrEnv.Reg == 0x61 && grp->oAlpEnv.Reg == 0x61 && grp->oCMD.Reg == 0x61)
                    {
                        TEVStage s1 = new TEVStage(r * 2 + 1);

                        s1.rawColEnv   = grp->oClrEnv.Data.Value;
                        s1.rawAlphaEnv = grp->oAlpEnv.Data.Value;
                        s1.rawCMD      = grp->oCMD.Data.Value;

                        s1.kcsel = KSEL.KCSEL1;
                        s1.kasel = KSEL.KASEL1;

                        s1.ti = TREF.TI1;
                        s1.tc = TREF.TC1;
                        s1.cc = TREF.CC1;
                        s1.te = TREF.TE1;

                        s1.getValues();
                        AddChild(s1, false);
                    }

                    //new MDL0ShaderStructNode().Initialize(this, grp, StageGroup.Size);
                }
            }
        }
示例#2
0
        public void DefaultAsMetal(int texcount)
        {
            Name       = String.Format("Shader{0}", Index);
            _datalen   = 512;
            _autoMetal = true;

            ref0                             =
                ref1                         =
                    ref2                     =
                        ref3                 =
                            ref4             =
                                ref5         =
                                    ref6     =
                                        ref7 = -1;

            switch ((texCount = texcount) - 1)
            {
            case 0: ref0 = 0; break;

            case 1: ref1 = 1; break;

            case 2: ref2 = 2; break;

            case 3: ref3 = 3; break;

            case 4: ref4 = 4; break;

            case 5: ref5 = 5; break;

            case 6: ref6 = 6; break;

            case 7: ref7 = 7; break;
            }

            stages = 4;

            Children.Clear();

            int      i = 0;
            TEVStage s;

            while (i++ < 4)
            {
                AddChild(s = new TEVStage(i));
                s.DefaultAsMetal(texcount - 1);
            }

            //MDL0ShaderStructNode s1 = new MDL0ShaderStructNode(); AddChild(s1);
            //MDL0ShaderStructNode s2 = new MDL0ShaderStructNode(); AddChild(s2);
            //s1.DefaultAsMetal(texcount - 1);
            //s2.DefaultAsMetal(texcount - 1);
        }
        public override void OnPopulate()
        {
            StageGroup *grp = Header->First;

            for (int r = 0; r < 8; r++, grp = grp->Next)
            {
                if (grp->mask.Reg == 0x61)
                {
                    TEVStage s0 = new TEVStage();

                    KSel      ksel = new KSel(grp->ksel.Data.Value);
                    RAS1_TRef tref = new RAS1_TRef(grp->tref.Data.Value);

                    s0._colorEnv = grp->eClrEnv.Data;
                    s0._alphaEnv = grp->eAlpEnv.Data;
                    s0._cmd      = grp->eCMD.Data;

                    s0._kcSel = ksel.KCSel0;
                    s0._kaSel = ksel.KASel0;

                    s0._texMapID   = tref.TexMapID0;
                    s0._texCoord   = tref.TexCoord0;
                    s0._colorChan  = tref.ColorChannel0;
                    s0._texEnabled = tref.TexEnabled0;

                    AddChild(s0, false);

                    if (grp->oClrEnv.Reg == 0x61 && grp->oAlpEnv.Reg == 0x61 && grp->oCMD.Reg == 0x61)
                    {
                        TEVStage s1 = new TEVStage();

                        s1._colorEnv = grp->oClrEnv.Data;
                        s1._alphaEnv = grp->oAlpEnv.Data;
                        s1._cmd      = grp->oCMD.Data;

                        s1._kcSel = ksel.KCSel1;
                        s1._kaSel = ksel.KASel1;

                        s1._texMapID   = tref.TexMapID1;
                        s1._texCoord   = tref.TexCoord1;
                        s1._colorChan  = tref.ColorChannel1;
                        s1._texEnabled = tref.TexEnabled1;

                        AddChild(s1, false);
                    }
                }
            }
        }
        public void DefaultAsMetal(int texcount)
        {
            _datalen   = 512;
            _autoMetal = true;

            _ref0                             =
                _ref1                         =
                    _ref2                     =
                        _ref3                 =
                            _ref4             =
                                _ref5         =
                                    _ref6     =
                                        _ref7 = -1;

            switch ((texCount = texcount) - 1)
            {
            case 0: _ref0 = 0; break;

            case 1: _ref1 = 1; break;

            case 2: _ref2 = 2; break;

            case 3: _ref3 = 3; break;

            case 4: _ref4 = 4; break;

            case 5: _ref5 = 5; break;

            case 6: _ref6 = 6; break;

            case 7: _ref7 = 7; break;
            }

            _stages = 4;

            Children.Clear();

            int      i = 0;
            TEVStage s;

            while (i++ < 4)
            {
                AddChild(s = new TEVStage());
                s.DefaultAsMetal(texcount - 1);
            }
        }
        public void Default()
        {
            _datalen                          = 512;
            _ref0                             =
                _ref1                         =
                    _ref2                     =
                        _ref3                 =
                            _ref4             =
                                _ref5         =
                                    _ref6     =
                                        _ref7 = -1;

            _stages = 1;

            TEVStage stage = new TEVStage();

            AddChild(stage, true);
            stage.Default();
        }
示例#6
0
        public void Default()
        {
            Name                             = String.Format("Shader{0}", Index);
            _datalen                         = 512;
            ref0                             =
                ref1                         =
                    ref2                     =
                        ref3                 =
                            ref4             =
                                ref5         =
                                    ref6     =
                                        ref7 = -1;

            stages = 1;

            //MDL0ShaderStructNode s = new MDL0ShaderStructNode();
            //AddChild(s, true);
            //s.Default();

            TEVStage stage = new TEVStage(Children.Count);

            AddChild(stage, true);
            stage.Default();
        }
示例#7
0
        public string GeneratePixelShaderCode(MDL0ObjectNode Object, PSGRENDER_MODE PSGRenderMode, TKContext ctx)
        {
            tempShader = "";

            int numStages = ShaderNode.Children.Count;
            int numTexgen = Children.Count;

            w("//Pixel Shader for TEV stages\n");
            w("//{0} TEV stages, {1} texgens, {2} IND stages\n", numStages, numTexgen, IndirectShaderStages);

            int nIndirectStagesUsed = 0;

            if (IndirectShaderStages > 0)
            {
                for (int i = 0; i < numStages; ++i)
                {
                    TEVStage stage = ShaderNode.Children[i] as TEVStage;
                    if (stage.IndirectActive && stage.bt < IndirectShaderStages)
                    {
                        nIndirectStagesUsed |= 1 << stage.bt;
                    }
                }
            }

            DepthTextureEnable = (/*bpmem.ztex2.op != ZTEXTURE_DISABLE && */ !ZCompareLoc && EnableDepthTest && EnableDepthUpdate) /* || g_ActiveConfig.bEnablePerPixelDepth*/;

            //A few required defines and ones that will make our lives a lot easier
            if (ctx.bSupportsGLSLBinding || ctx.bSupportsGLSLUBO)
            {
                w("#version 330 compatibility\n");
                if (ctx.bSupportsGLSLBinding)
                {
                    w("#extension GL_ARB_shading_language_420pack : enable\n");
                }
                //if (ctx.bSupportsGLSLUBO)
                //    w("#extension GL_ARB_uniform_buffer_object : enable\n");
            }
            else
            {
                w("#version 120\n");
            }

            if (ctx.bSupportsGLSLATTRBind)
            {
                w("#extension GL_ARB_explicit_attrib_location : enable\n");
            }

            w("#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
            w("#define lerp(x, y, z) mix(x, y, z)\n");

            w("float fmod(float x, float y)\n");
            w("{\n");
            w("float z = fract(abs(x / y)) * abs(y);\n");
            w("return (x < 0) ? -z : z;\n");
            w("}\n");

            for (uint i = 0; i < 8; i++)
            {
                w("{0}uniform sampler2D samp{1};\n", WriteBinding(i, ctx), i);
            }

            w("\n");

            w("uniform vec4 " + I_COLORS + "[4];\n");
            w("uniform vec4 " + I_KCOLORS + "[4];\n");
            w("uniform vec4 " + I_ALPHA + ";\n");
            w("uniform vec4 " + I_TEXDIMS + "[8];\n");
            w("uniform vec4 " + I_ZBIAS + "[2];\n");
            w("uniform vec4 " + I_INDTEXSCALE + "[2];\n");
            w("uniform vec4 " + I_INDTEXMTX + "[6];\n");
            w("uniform vec4 " + I_FOG + "[3];\n");

            // Compiler will optimize these out by itself.
            w("uniform vec4 " + I_PLIGHTS + "[40];\n");
            w("uniform vec4 " + I_PMATERIALS + "[4];\n");

            w("vec4 ocol0;\n");

            if (DepthTextureEnable)
            {
                w("float depth;\n");
            }

            w("vec4 rawpos = gl_FragCoord;\n");

            w("vec4 colors_0 = gl_Color;\n");
            w("vec4 colors_1 = gl_SecondaryColor;\n");

            if (numTexgen < 7)
            {
                for (int i = 0; i < numTexgen; i++)
                {
                    w("vec3 uv{0} = gl_TexCoord[{0}].xyz;\n", i);
                }
                w("vec4 clipPos = gl_TexCoord[{0}];\n", numTexgen);
                w("vec4 Normal = gl_TexCoord[{0}];\n", numTexgen + 1);
            }
            else
            {
                for (int i = 0; i < 8; ++i)
                {
                    w("vec4 uv{0} = gl_TexCoord[{0}];\n", i);
                }
            }

            w("void main()\n{\n");

            AlphaPretest Pretest = PretestAlpha();

            //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_ALPHA_PASS && !DepthTextureEnable && Pretest >= 0)
            //{
            //    if (Pretest == AlphaPretest.AlwaysFail)
            //    {
            //        w("ocol0 = vec4(0);\n");
            //        w("discard;\n");

            //        if(PSGRenderMode != PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
            //            w("gl_FragColor = ocol0;\n");

            //        w("return;\n");
            //    }
            //    else
            //        w("ocol0 = " + I_ALPHA + ".aaaa;\n");

            //    w("}\n");

            //    return tempShader;
            //}

            w("vec4 c0 = " + I_COLORS + "[1], c1 = " + I_COLORS + "[2], c2 = " + I_COLORS + "[3], prev = vec4(0.0f, 0.0f, 0.0f, 0.0f), textemp = vec4(0.0f, 0.0f, 0.0f, 0.0f), rastemp = vec4(0.0f, 0.0f, 0.0f, 0.0f), konsttemp = vec4(0.0f, 0.0f, 0.0f, 0.0f);\n");
            w("vec3 comp16 = vec3(1.0f, 255.0f, 0.0f), comp24 = vec3(1.0f, 255.0f, 255.0f*255.0f);\n");
            w("vec4 alphabump = vec4(0.0f,0.0f,0.0f,0.0f);\n");
            w("vec3 tevcoord = vec3(0.0f, 0.0f, 0.0f);\n");
            w("vec2 wrappedcoord=vec2(0.0f,0.0f), tempcoord=vec2(0.0f,0.0f);\n");
            w("vec4 cc0 = vec4(0.0f,0.0f,0.0f,0.0f), cc1 = vec4(0.0f,0.0f,0.0f,0.0f);\n");
            w("vec4 cc2 = vec4(0.0f,0.0f,0.0f,0.0f), cprev = vec4(0.0f,0.0f,0.0f,0.0f);\n");
            w("vec4 crastemp=vec4(0.0f,0.0f,0.0f,0.0f), ckonsttemp = vec4(0.0f,0.0f,0.0f,0.0f);\n\n");

            if (Children.Count < 7)
            {
                w("vec3 _norm0 = normalize(Normal.xyz);\n\n");
                w("vec3 pos = vec3(clipPos.x,clipPos.y,Normal.w);\n");
            }
            else
            {
                w("vec3 _norm0 = normalize(vec3(uv4.w,uv5.w,uv6.w));\n\n");
                w("vec3 pos = vec3(uv0.w,uv1.w,uv7.w);\n");
            }

            w("vec4 mat, lacc;\nvec3 ldir, h;\nfloat dist, dist2, attn;\n");

            Object.tabs = tabs;
            tempShader += Object.GenerateLightingShader(I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");

            //if (numTexgen < 7)
            //    w("clipPos = vec4(rawpos.x, rawpos.y, clipPos.z, clipPos.w);\n");
            //else
            //    w("vec4 clipPos = vec4(rawpos.x, rawpos.y, uv2.w, uv3.w);\n");

            // HACK to handle cases where the tex gen is not enabled
            if (numTexgen == 0)
            {
                w("vec3 uv0 = vec3(0.0f, 0.0f, 0.0f);\n");
            }
            else
            {
                for (int i = 0; i < numTexgen; ++i)
                {
                    // optional perspective divides
                    if (((MDL0MaterialRefNode)Children[i]).Projection == TexProjection.STQ)
                    {
                        w("if (uv{0}.z != 0.0f)\n", i);
                        w("    uv{0}.xy = uv{0}.xy / uv{0}.z;\n", i);
                    }

                    //w("uv{0}.xy = uv{0}.xy * "+I_TEXDIMS+"[{0}].zw;\n", i);
                }
            }

            for (int i = 0; i < IndirectShaderStages; i++)
            {
                if ((nIndirectStagesUsed & (1 << i)) != 0)
                {
                    uint texcoord = (ShaderNode._swapBlock._Value16.Value >> ((i + 1) * 3) & 7);

                    if (texcoord < numTexgen)
                    {
                        w("tempcoord = uv{0}.xy * " + I_INDTEXSCALE + "[{1}].{2};\n", texcoord, i / 2, (i & 1) != 0 ? "zw" : "xy");
                    }
                    else
                    {
                        w("tempcoord = vec2(0.0f, 0.0f);\n");
                    }

                    SampleTexture(String.Format("vec3 indtex{0}", i), "tempcoord", "abg", (ShaderNode._swapBlock._Value16.Value >> (i * 3) & 7));
                }
            }

            foreach (TEVStage stage in ShaderNode.Children)
            {
                if (stage.Index < ActiveShaderStages)
                {
                    w(stage.Write(this, Object));
                }
                else
                {
                    break;
                }
            }

            if (numStages > 0)
            {
                w("prev.rgb = {0};\n", tevCOutputTable[(int)((TEVStage)ShaderNode.Children[numStages - 1]).ColorRegister]);
                w("prev.a = {0};\n", tevAOutputTable[(int)((TEVStage)ShaderNode.Children[numStages - 1]).AlphaRegister]);
            }

            // emulation of unsigned 8 overflow when casting
            //w("prev = fract(4.0f + prev * (255.0f/256.0f)) * (256.0f/255.0f);\n");

            if (Pretest == AlphaPretest.AlwaysFail)
            {
                w("ocol0 = vec4(0.0f);\n");

                //if (DepthTextureEnable)
                //    w("depth = 1.0f;\n");

                //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
                //    w("ocol1 = vec4(0.0f);\n");
                //else
                w("gl_FragColor = ocol0;\n");

                if (DepthTextureEnable)
                {
                    w("gl_FragDepth = depth;\n");
                }

                w("discard;\n");

                w("return;\n");
            }
            else
            {
                if (Pretest != AlphaPretest.AlwaysPass)
                {
                    WriteAlphaTest(PSGRenderMode);
                }

                //if (_fog != null && (_fog.Type != 0) || DepthTextureEnable)
                //{
                //    // the screen space depth value = far z + (clip z / clip w) * z range
                //    w("float zCoord = " + I_ZBIAS + "[1].x + (clipPos.z / clipPos.w) * " + I_ZBIAS + "[1].y;\n");
                //}

                //if (DepthTextureEnable)
                //{
                //    // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format...
                //    if (/*bpmem.ztex2.op != ZTEXTURE_DISABLE && */!ZCompLoc && EnableDepthTest && EnableDepthUpdate)
                //    {
                //        //if (bpmem.ztex2.op == ZTEXTURE_ADD)
                //        //    Write("zCoord = dot("+I_ZBIAS+"[0].xyzw, textemp.xyzw) + "+I_ZBIAS+"[1].w + zCoord;\n");
                //        //else
                //            w("zCoord = dot(" + I_ZBIAS + "[0].xyzw, textemp.xyzw) + " + I_ZBIAS + "[1].w;\n");

                //        // scale to make result from frac correct
                //        w("zCoord = zCoord * (16777215.0f/16777216.0f);\n");
                //        w("zCoord = fract(zCoord);\n");
                //        w("zCoord = zCoord * (16777216.0f/16777215.0f);\n");
                //    }
                //    w("depth = zCoord;\n");
                //}

                //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_ALPHA_PASS)
                //    w("ocol0 = vec4(prev.rgb, " + I_ALPHA + ".a);\n");
                //else
                {
                    WriteFog();
                    w("ocol0 = prev;\n");
                }

                //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
                //{
                //    w("ocol1 = ocol0;\n");
                //    w("ocol0.a = " + I_ALPHA + ".a;\n");
                //}

                //if (DepthTextureEnable)
                //    w("gl_FragDepth = depth;\n");
                //if (PSGRenderMode != PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
                w("gl_FragColor = ocol0;\n");
            }
            w("}\n");

            return(tempShader);
        }
        //private void CreateStruct()
        //{
        //    if (_resource.Children.Count < 8)
        //    {
        //        MDL0ShaderStructNode shadstr = new MDL0ShaderStructNode();
        //        _resource.AddChild(shadstr, true);
        //        shadstr.Default();
        //        Nodes[Nodes.Count - 1].EnsureVisible();
        //        //TreeView.SelectedNode = Nodes[Nodes.Count - 1];
        //    }
        //}
        private void CreateStage()
        {
            if (_resource.Children.Count < 16)
            {
                TEVStage stage = new TEVStage();
                _resource.AddChild(stage, true);
                stage.Default();

                ((MDL0ShaderNode)_resource).STGs = (byte)_resource.Children.Count;

                Nodes[Nodes.Count - 1].EnsureVisible();
                //TreeView.SelectedNode = Nodes[Nodes.Count - 1];
            }
        }
示例#9
0
        protected internal override void OnRebuild(VoidPtr address, int length, bool force)
        {
            MDL0Shader *header = (MDL0Shader *)address;

            if (Model._isImport)
            {
                ref1                         =
                    ref2                     =
                        ref3                 =
                            ref4             =
                                ref5         =
                                    ref6     =
                                        ref7 = -1;

                if (Model._importOptions._mdlType == 0)
                {
                    stages = 3;
                }
                else
                {
                    stages = 1;
                }
            }

            header->_dataLength = length;
            header->_index      = Index;

            header->_stages = Model._isImport ? stages : (byte)Children.Count;

            header->_res0 = res0;
            header->_res1 = res1;
            header->_res2 = res2;

            header->_ref0 = ref0;
            header->_ref1 = ref1;
            header->_ref2 = ref2;
            header->_ref3 = ref3;
            header->_ref4 = ref4;
            header->_ref5 = ref5;
            header->_ref6 = ref6;
            header->_ref7 = ref7;

            header->_pad0 = pad0;
            header->_pad1 = pad1;

            *header->SwapBlock = _swapBlock;

            //int offset = 0x80;
            //foreach (MDL0ShaderStructNode s in Children)
            //{
            //    s.Rebuild(address + offset, 0x30, force);
            //    offset += 0x30;
            //}

            StageGroup *grp = (StageGroup *)(address + 0x80);

            for (int i = 0; i < Children.Count; i++)
            {
                TEVStage c = (TEVStage)Children[i]; //Current Stage

                if (i % 2 == 0)                     //Even Stage
                {
                    *grp = StageGroup.Default;

                    grp->SetGroup(i / 2);
                    grp->SetStage(i);

                    grp->eClrEnv.Data.Value = c.rawColEnv;
                    grp->eAlpEnv.Data.Value = c.rawAlphaEnv;
                    grp->eCMD.Data.Value    = c.rawCMD;

                    if (i == Children.Count - 1) //Last stage is even, odd stage isn't used
                    {
                        grp->ksel.Data.Value = KSel.Shift(0, 0, c.kcsel, c.kasel, 0, 0);
                        grp->tref.Data.Value = RAS1_TRef.Shift(c.ti, c.tc, c.te ? 1 : 0, c.cc, 7, 7, 0, 7);
                    }
                }
                else //Odd Stage
                {
                    TEVStage p = (TEVStage)Children[i - 1]; //Previous Stage

                    grp->SetStage(i);

                    grp->oClrEnv.Data.Value = c.rawColEnv;
                    grp->oAlpEnv.Data.Value = c.rawAlphaEnv;
                    grp->oCMD.Data.Value    = c.rawCMD;

                    grp->ksel.Data.Value = KSel.Shift(0, 0, p.kcsel, p.kasel, c.kcsel, c.kasel);
                    grp->tref.Data.Value = RAS1_TRef.Shift(p.ti, p.tc, p.te ? 1 : 0, p.cc, c.ti, c.tc, c.te ? 1 : 0, c.cc);

                    grp = grp->Next;
                }
            }

            if (Model._isImport)
            {
                StageGroup *struct0 = header->First;
                *           struct0 = StageGroup.Default;
                struct0->SetGroup(0);
                switch (Model._importOptions._mdlType)
                {
                case 0:     //Character

                    struct0->SetStage(0);
                    struct0->SetStage(1);

                    struct0->mask.Data.Value    = 0xFFFFF0;
                    struct0->ksel.Data.Value    = 0xE378C0;
                    struct0->tref.Data.Value    = 0x03F040;
                    struct0->eClrEnv.Data.Value = 0x28F8AF;
                    struct0->oClrEnv.Data.Value = 0x08FEB0;
                    struct0->eAlpEnv.Data.Value = 0x08F2F0;
                    struct0->oAlpEnv.Data.Value = 0x081FF0;

                    //new MDL0ShaderStructNode().Initialize(this, header->First, StageGroup.Size);

                    StageGroup *struct1 = struct0->Next;
                    *           struct1 = StageGroup.Default;

                    struct1->SetGroup(1);
                    struct1->SetStage(2);

                    struct1->mask.Data.Value    = 0xFFFFF0;
                    struct1->ksel.Data.Value    = 0x0038C0;
                    struct1->tref.Data.Value    = 0x3BF3BF;
                    struct1->eClrEnv.Data.Value = 0x0806EF;
                    struct1->eAlpEnv.Data.Value = 0x081FF0;

                    //new MDL0ShaderStructNode().Initialize(this, struct0->Next, StageGroup.Size);
                    break;

                case 1:     //Stage/Item

                    struct0->SetStage(0);

                    struct0->mask.Data.Value    = 0xFFFFF0;
                    struct0->ksel.Data.Value    = 0x0038C0;
                    struct0->tref.Data.Value    = 0x3BF040;
                    struct0->eClrEnv.Data.Value = 0x28F8AF;
                    struct0->eAlpEnv.Data.Value = 0x08F2F0;

                    //new MDL0ShaderStructNode().Initialize(this, header->First, StageGroup.Size);
                    break;
                }
            }
        }
示例#10
0
        public override void OnRebuild(VoidPtr address, int length, bool force)
        {
            MDL0Shader *header = (MDL0Shader *)address;

            if (Model._isImport)
            {
                _ref1                         =
                    _ref2                     =
                        _ref3                 =
                            _ref4             =
                                _ref5         =
                                    _ref6     =
                                        _ref7 = -1;

                if (Collada._importOptions._mdlType == 0)
                {
                    _stages = 3;
                }
                else
                {
                    _stages = 1;
                }
            }

            header->_dataLength = length;
            header->_index      = Index;

            header->_stages = Model._isImport ? _stages : (byte)Children.Count;

            header->_res0 = 0;
            header->_res1 = 0;
            header->_res2 = 0;

            header->_ref0 = _ref0;
            header->_ref1 = _ref1;
            header->_ref2 = _ref2;
            header->_ref3 = _ref3;
            header->_ref4 = _ref4;
            header->_ref5 = _ref5;
            header->_ref6 = _ref6;
            header->_ref7 = _ref7;

            header->_pad0 = 0;
            header->_pad1 = 0;

            *header->SwapBlock = _swapBlock;

            StageGroup *grp = (StageGroup *)(address + 0x80);

            for (int i = 0; i < Children.Count; i++)
            {
                TEVStage c = (TEVStage)Children[i]; //Current Stage

                if (i % 2 == 0)                     //Even Stage
                {
                    *grp = StageGroup.Default;

                    grp->SetGroup(i / 2);
                    grp->SetStage(i);

                    grp->eClrEnv.Data = c._colorEnv;
                    grp->eAlpEnv.Data = c._alphaEnv;
                    grp->eCMD.Data    = c._cmd;

                    if (i == Children.Count - 1) //Last stage is even, odd stage isn't used
                    {
                        grp->ksel.Data = new KSel(0, 0, c._kcSel, c._kaSel, 0, 0);
                        grp->tref.Data = new RAS1_TRef(c._texMapID, c._texCoord, c._texEnabled, c._colorChan, TexMapID.TexMap7, TexCoordID.TexCoord7, false, ColorSelChan.Zero);
                    }
                }
                else //Odd Stage
                {
                    TEVStage p = (TEVStage)Children[i - 1]; //Previous Stage

                    grp->SetStage(i);

                    grp->oClrEnv.Data = c._colorEnv;
                    grp->oAlpEnv.Data = c._alphaEnv;
                    grp->oCMD.Data    = c._cmd;

                    grp->ksel.Data = new KSel(0, 0, p._kcSel, p._kaSel, c._kcSel, c._kaSel);
                    grp->tref.Data = new RAS1_TRef(p._texMapID, p._texCoord, p._texEnabled, p._colorChan, c._texMapID, c._texCoord, c._texEnabled, c._colorChan);

                    grp = grp->Next;
                }
            }

            if (Model._isImport)
            {
                StageGroup *struct0 = header->First;
                *           struct0 = StageGroup.Default;
                struct0->SetGroup(0);

                switch (Collada._importOptions._mdlType)
                {
                case Modeling.Collada.ImportOptions.MDLType.Character:

                    struct0->SetStage(0);
                    struct0->SetStage(1);

                    struct0->mask.Data.Value    = 0xFFFFF0;
                    struct0->ksel.Data.Value    = 0xE378C0;
                    struct0->tref.Data.Value    = 0x03F040;
                    struct0->eClrEnv.Data.Value = 0x28F8AF;
                    struct0->oClrEnv.Data.Value = 0x08FEB0;
                    struct0->eAlpEnv.Data.Value = 0x08F2F0;
                    struct0->oAlpEnv.Data.Value = 0x081FF0;

                    StageGroup *struct1 = struct0->Next;
                    *           struct1 = StageGroup.Default;

                    struct1->SetGroup(1);
                    struct1->SetStage(2);

                    struct1->mask.Data.Value    = 0xFFFFF0;
                    struct1->ksel.Data.Value    = 0x0038C0;
                    struct1->tref.Data.Value    = 0x3BF3BF;
                    struct1->eClrEnv.Data.Value = 0x0806EF;
                    struct1->eAlpEnv.Data.Value = 0x081FF0;

                    break;

                case Modeling.Collada.ImportOptions.MDLType.Stage:

                    struct0->SetStage(0);

                    struct0->mask.Data.Value    = 0xFFFFF0;
                    struct0->ksel.Data.Value    = 0x0038C0;
                    struct0->tref.Data.Value    = 0x3BF040;
                    struct0->eClrEnv.Data.Value = 0x28F8AF;
                    struct0->eAlpEnv.Data.Value = 0x08F2F0;

                    break;
                }
            }
        }
        public override void OnPopulate()
        {
            StageGroup* grp = Header->First;
            for (int r = 0; r < 8; r++, grp = grp->Next)
                if (grp->mask.Reg == 0x61)
                {
                    TEVStage s0 = new TEVStage();

                    KSel ksel = new KSel(grp->ksel.Data.Value);
                    RAS1_TRef tref = new RAS1_TRef(grp->tref.Data.Value);

                    s0._colorEnv = grp->eClrEnv.Data;
                    s0._alphaEnv = grp->eAlpEnv.Data;
                    s0._cmd = grp->eCMD.Data;

                    s0._kcSel = ksel.KCSel0;
                    s0._kaSel = ksel.KASel0;

                    s0._texMapID = tref.TexMapID0;
                    s0._texCoord = tref.TexCoord0;
                    s0._colorChan = tref.ColorChannel0;
                    s0._texEnabled = tref.TexEnabled0;

                    AddChild(s0, false);

                    if (grp->oClrEnv.Reg == 0x61 && grp->oAlpEnv.Reg == 0x61 && grp->oCMD.Reg == 0x61)
                    {
                        TEVStage s1 = new TEVStage();

                        s1._colorEnv = grp->oClrEnv.Data;
                        s1._alphaEnv = grp->oAlpEnv.Data;
                        s1._cmd = grp->oCMD.Data;

                        s1._kcSel = ksel.KCSel1;
                        s1._kaSel = ksel.KASel1;

                        s1._texMapID = tref.TexMapID1;
                        s1._texCoord = tref.TexCoord1;
                        s1._colorChan = tref.ColorChannel1;
                        s1._texEnabled = tref.TexEnabled1;

                        AddChild(s1, false);
                    }
                }
        }
        public void DefaultAsMetal(int texcount)
        {
            _datalen = 512;
            _autoMetal = true;

            _ref0 =
            _ref1 =
            _ref2 =
            _ref3 =
            _ref4 =
            _ref5 =
            _ref6 =
            _ref7 = -1;

            switch ((texCount = texcount) - 1)
            {
                case 0: _ref0 = 0; break;
                case 1: _ref1 = 1; break;
                case 2: _ref2 = 2; break;
                case 3: _ref3 = 3; break;
                case 4: _ref4 = 4; break;
                case 5: _ref5 = 5; break;
                case 6: _ref6 = 6; break;
                case 7: _ref7 = 7; break;
            }

            _stages = 4;

            Children.Clear();

            int i = 0;
            TEVStage s;
            while (i++ < 4)
            {
                AddChild(s = new TEVStage());
                s.DefaultAsMetal(texcount - 1);
            }
        }
        public void Default()
        {
            _datalen = 512;
            _ref0 =
            _ref1 =
            _ref2 =
            _ref3 =
            _ref4 =
            _ref5 =
            _ref6 =
            _ref7 = -1;

            _stages = 1;

            TEVStage stage = new TEVStage();
            AddChild(stage, true);
            stage.Default();
        }