Example #1
0
        private void GenerateAmbientColorChannelCommands(Material mat)
        {
            XFCommand ambientColorChannelCommand = new XFCommand(XFRegister.SETCHAN0_AMBCOLOR);

            for (int i = 0; i < 2; i++)
            {
                if (mat.AmbientColors[i] == null)
                {
                    continue;
                }
                Util.Color color = mat.AmbientColors[i].Value;

                XFCommandArgument ambientColorChanArg = new XFCommandArgument();

                ambientColorChanArg.SetBits((byte)(color.R * 255), 24, 8);
                ambientColorChanArg.SetBits((byte)(color.G * 255), 16, 8);
                ambientColorChanArg.SetBits((byte)(color.B * 255), 8, 8);
                ambientColorChanArg.SetBits((byte)(color.A * 255), 0, 8);

                ambientColorChannelCommand.Args.Add(ambientColorChanArg);
            }

            if (ambientColorChannelCommand.Args.Count > 0)
            {
                XFCommands.Add(ambientColorChannelCommand);
            }
        }
Example #2
0
        private void GenerateChannelControlCommands(Material mat)
        {
            XFCommand channelControlCommand = new XFCommand(XFRegister.SETCHAN0_COLOR);

            int[] channelControlIndices = new int[4] {
                0, 2, 1, 3
            };
            for (int i = 0; i < 4; i++)
            {
                int channelControlIndex = channelControlIndices[i];

                if (mat.ChannelControls[channelControlIndex] == null)
                {
                    channelControlCommand.Args.Add(new XFCommandArgument());
                    continue;
                }
                ChannelControl chanCtrl = mat.ChannelControls[channelControlIndex].Value;

                XFCommandArgument chanControlArg = new XFCommandArgument();

                chanControlArg.SetBits((int)chanCtrl.MaterialSrcColor, 0, 1);
                chanControlArg.SetFlag(chanCtrl.Enable, 1);
                chanControlArg.SetBits((int)chanCtrl.LitMask, 2, 4);
                chanControlArg.SetBits((int)chanCtrl.AmbientSrcColor, 6, 1);

                if (chanCtrl.AttenuationFunction == J3DAttenuationFn.None_0)
                {
                    chanControlArg.SetBits((int)DiffuseFn.None, 7, 2);
                    chanControlArg.SetBits(0, 10, 1);
                }
                else
                {
                    chanControlArg.SetBits((int)chanCtrl.DiffuseFunction, 7, 2);
                    chanControlArg.SetBits(1, 10, 1);
                }

                if (chanCtrl.AttenuationFunction != J3DAttenuationFn.None_2)
                {
                    chanControlArg.SetFlag(true, 9);
                }

                chanControlArg.SetBits((int)chanCtrl.LitMask >> 4, 11, 4);

                channelControlCommand.Args.Add(chanControlArg);
            }

            XFCommands.Add(channelControlCommand);

            XFCommand numChannelControlsCommand = new XFCommand(XFRegister.SETNUMCHAN);

            numChannelControlsCommand.Args.Add(new XFCommandArgument(mat.ColorChannelControlsCount));
            XFCommands.Add(numChannelControlsCommand);
        }
Example #3
0
        private void GenerateTexGenXFCommands(Material mat)
        {
            XFCommand texGensCommand   = new XFCommand(XFRegister.SETTEXMTXINFO);
            XFCommand dtTexGensCommand = new XFCommand(XFRegister.SETPOSMTXINFO);

            for (int i = 0; i < 8; i++)
            {
                if (mat.TexCoord1Gens[i] == null)
                {
                    continue;
                }
                TexCoordGen texgen = mat.TexCoord1Gens[i].Value;

                XFCommandArgument texGenArg = new XFCommandArgument();
                texGenArg.SetBits(0, 1, 1);
                texGenArg.SetBits(0, 2, 1);
                texGenArg.SetBits(5, 12, 3);
                texGenArg.SetBits(0, 15, 3);

                if (texgen.Type == TexGenType.Matrix3x4)
                {
                    texGenArg.SetFlag(true, 1);
                }
                switch (texgen.Source)
                {
                case TexGenSrc.Position:
                case TexGenSrc.Normal:
                case TexGenSrc.Binormal:
                case TexGenSrc.Tangent:
                    texGenArg.SetFlag(true, 2);
                    break;
                }
                switch (texgen.Type)
                {
                case TexGenType.Bump0:
                case TexGenType.Bump1:
                case TexGenType.Bump2:
                case TexGenType.Bump3:
                case TexGenType.Bump4:
                case TexGenType.Bump5:
                case TexGenType.Bump6:
                case TexGenType.Bump7:
                    texGenArg.SetBits(1, 4, 2);
                    texGenArg.SetBits(texgen.Source - TexGenSrc.Tex0, 12, 3);
                    texGenArg.SetBits(texgen.Type - TexGenType.Bump0, 15, 3);
                    texGenArg.SetBits(5, 7, 3);
                    break;

                case TexGenType.SRTG:
                    texGenArg.SetBits(2, 7, 3);
                    if (texgen.Source == TexGenSrc.Color0)
                    {
                        texGenArg.SetBits(2, 4, 2);
                    }
                    else if (texgen.Source == TexGenSrc.Color1)
                    {
                        texGenArg.SetBits(3, 4, 2);
                    }
                    break;

                default:
                    texGenArg.SetBits(0, 4, 2);
                    if (texgen.Source == TexGenSrc.Position || texgen.Source == TexGenSrc.Normal)
                    {
                        texGenArg.SetBits((int)texgen.Source, 7, 3);
                    }
                    else
                    {
                        texGenArg.SetBits((int)texgen.Source + 1, 7, 3);
                    }
                    break;
                }

                XFCommandArgument dtTexGenArg = new XFCommandArgument();

                dtTexGenArg.SetFlag(false, 8);
                dtTexGenArg.SetBits(61, 0, 6);

                texGensCommand.Args.Add(texGenArg);
                dtTexGensCommand.Args.Add(dtTexGenArg);
            }

            if (texGensCommand.Args.Count > 0)
            {
                XFCommands.Add(texGensCommand);
                XFCommands.Add(dtTexGensCommand);
            }
        }