Ejemplo n.º 1
0
        public Material()
        {
            CullMode       = CullMode.Back;
            MaterialColors = new Color?[2] {
                new Color(1, 1, 1, 1), null
            };

            ChannelControls = new ChannelControl?[4];

            IndTexEntry = new IndirectTexturing();

            AmbientColors = new Color?[2] {
                new Color(50f / 255f, 50f / 255f, 50f / 255f, 50f / 255f), null
            };
            LightingColors = new Color?[8];

            TexCoord1Gens    = new TexCoordGen?[8];
            PostTexCoordGens = new TexCoordGen?[8];

            TexMatrix1    = new TexMatrix?[10];
            PostTexMatrix = new TexMatrix?[20];

            TextureIndices = new int[8] {
                -1, -1, -1, -1, -1, -1, -1, -1
            };
            TextureNames = new string[8] {
                "", "", "", "", "", "", "", ""
            };

            KonstColors    = new Color?[4];
            KonstColors[0] = new Color(1, 1, 1, 1);

            ColorSels = new KonstColorSel[16];
            AlphaSels = new KonstAlphaSel[16];

            TevOrders = new TevOrder?[16];
            //TevOrders[0] = new TevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, GXColorChannelId.Color0);

            TevColors    = new Color?[4];
            TevColors[0] = new Color(1, 1, 1, 1);

            TevStages = new TevStage?[16];

            SwapModes    = new TevSwapMode?[16];
            SwapModes[0] = new TevSwapMode(0, 0);

            SwapTables    = new TevSwapModeTable?[16];
            SwapTables[0] = new TevSwapModeTable(0, 1, 2, 3);

            AlphCompare = new AlphaCompare(CompareType.Greater, 127, AlphaOp.And, CompareType.Always, 0);
            ZMode       = new ZMode(true, CompareType.LEqual, true);
            BMode       = new BlendMode(Enums.BlendMode.Blend, BlendModeControl.SrcAlpha, BlendModeControl.InverseSrcAlpha, LogicOp.NoOp);
            NBTScale    = new NBTScale(0, Vector3.Zero);
            FogInfo     = new Fog(0, false, 0, 0, 0, 0, 0, new Color(0, 0, 0, 0), new float[10]);
        }
Ejemplo n.º 2
0
        public void SetUpTevForMaps(bool hasTexture, bool hasVtxColor, int texIndex, string texName, float opacity)
        {
            // We need both vertex colors and textures to do map lighting.
            if (!hasVtxColor || !hasTexture)
            {
                SetUpTev(hasTexture, hasVtxColor, texIndex, texName);
                return;
            }

            bool IsTranslucent = opacity < 1.0f;

            Flag = 1;
            if (IsTranslucent)
            {
                Flag = 4;
            }

            ChannelControls[0] = null;
            AddChannelControl(J3DColorChannelId.Color0, false, ColorSrc.Vertex, LightId.None, DiffuseFn.Clamp, J3DAttenuationFn.Spec, ColorSrc.Register);
            AddChannelControl(J3DColorChannelId.Alpha0, false, ColorSrc.Vertex, LightId.None, DiffuseFn.Clamp, J3DAttenuationFn.Spec, ColorSrc.Register);

            AddChannelControl(J3DColorChannelId.Color1, true, ColorSrc.Register, LightId.None, DiffuseFn.Signed, J3DAttenuationFn.None_0, ColorSrc.Register);
            AddChannelControl(J3DColorChannelId.Alpha1, false, ColorSrc.Register, LightId.None, DiffuseFn.Clamp, J3DAttenuationFn.None_2, ColorSrc.Register);

            AddChannelControl(J3DColorChannelId.Color1, true, ColorSrc.Register, LightId.None, DiffuseFn.Signed, J3DAttenuationFn.None_0, ColorSrc.Register);
            AddChannelControl(J3DColorChannelId.Alpha1, false, ColorSrc.Register, LightId.None, DiffuseFn.Clamp, J3DAttenuationFn.None_2, ColorSrc.Register);

            ColorChannelControlsCount = 1;
            TevStageParameters first_stage = new TevStageParameters
            {
                ColorInA = CombineColorInput.C0,
                ColorInB = CombineColorInput.Konst,
                ColorInC = CombineColorInput.RasColor,
                ColorInD = CombineColorInput.Zero,

                ColorOp    = TevOp.Add,
                ColorBias  = TevBias.Zero,
                ColorScale = TevScale.Scale_1,
                ColorClamp = true,
                ColorRegId = TevRegisterId.TevPrev,

                AlphaInA = CombineAlphaInput.Zero,
                AlphaInB = CombineAlphaInput.TexAlpha,
                AlphaInC = CombineAlphaInput.RasAlpha,
                AlphaInD = CombineAlphaInput.Zero,

                AlphaOp    = TevOp.Add,
                AlphaBias  = TevBias.Zero,
                AlphaScale = TevScale.Scale_1,
                AlphaClamp = true,
                AlphaRegId = TevRegisterId.TevPrev,
            };

            TevStageParameters second_stage = new TevStageParameters
            {
                ColorInA = CombineColorInput.Zero,
                ColorInB = CombineColorInput.TexColor,
                ColorInC = CombineColorInput.ColorPrev,
                ColorInD = CombineColorInput.Zero,

                ColorOp    = TevOp.Add,
                ColorBias  = TevBias.Zero,
                ColorScale = TevScale.Scale_1,
                ColorClamp = true,
                ColorRegId = TevRegisterId.TevPrev,

                AlphaInA = CombineAlphaInput.Zero,
                AlphaInB = CombineAlphaInput.Konst,
                AlphaInC = CombineAlphaInput.AlphaPrev,
                AlphaInD = CombineAlphaInput.Zero,

                AlphaOp    = TevOp.Add,
                AlphaBias  = TevBias.Zero,
                AlphaScale = TevScale.Scale_1,
                AlphaClamp = true,
                AlphaRegId = TevRegisterId.TevPrev,
            };

            TevStageParameters third_stage = new TevStageParameters
            {
                ColorInA = CombineColorInput.Zero,
                ColorInB = CombineColorInput.Zero,
                ColorInC = CombineColorInput.Zero,
                ColorInD = CombineColorInput.ColorPrev,

                ColorOp    = TevOp.Add,
                ColorBias  = TevBias.Zero,
                ColorScale = TevScale.Scale_1,
                ColorClamp = true,
                ColorRegId = TevRegisterId.TevPrev,

                AlphaInA = CombineAlphaInput.Zero,
                AlphaInB = CombineAlphaInput.Konst,
                AlphaInC = CombineAlphaInput.AlphaPrev,
                AlphaInD = CombineAlphaInput.Zero,

                AlphaOp    = TevOp.Add,
                AlphaBias  = TevBias.Zero,
                AlphaScale = TevScale.Scale_1,
                AlphaClamp = true,
                AlphaRegId = TevRegisterId.TevPrev,
            };

            AddTevStage(first_stage);
            AddTevStage(second_stage);
            AddTevStage(third_stage);

            TevOrders[0] = null;
            AddTevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, GXColorChannelId.Color0A0);
            AddTevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, GXColorChannelId.ColorNull);
            AddTevOrder(TexCoordId.TexCoord0, TexMapId.TexMap0, GXColorChannelId.ColorNull);

            AddTexGen(TexGenType.Matrix2x4, TexGenSrc.Tex0, Enums.TexMatrix.Identity);
            AddTexMatrix(TexGenType.Matrix2x4, 0, new Vector3(0.5f, 0.5f, 0.5f), OpenTK.Vector2.One, 0, OpenTK.Vector2.Zero, OpenTK.Matrix4.Identity);
            AddTexIndex(texIndex);

            TextureNames[0] = texName;

            SwapModes[0] = new TevSwapMode(0, 0);
            SwapModes[1] = new TevSwapMode(0, 0);
            SwapModes[2] = new TevSwapMode(0, 0);

            SwapTables[0] = new TevSwapModeTable(0, 1, 2, 3);
            SwapTables[1] = new TevSwapModeTable(0, 1, 2, 3);
            SwapTables[2] = new TevSwapModeTable(0, 1, 2, 3);

            ColorSels[0] = KonstColorSel.KCSel_K0;
            ColorSels[1] = KonstColorSel.KCSel_K0;
            ColorSels[2] = KonstColorSel.KCSel_K0;

            AlphaSels[0] = KonstAlphaSel.KASel_K0_A;
            AlphaSels[1] = KonstAlphaSel.KASel_K3_A;
            AlphaSels[2] = KonstAlphaSel.KASel_K2_A;

            TevColors[0] = new Color(0, 0, 0, 1);
            TevColors[1] = new Color(1, 1, 1, 1);
            TevColors[2] = new Color(1, 1, 1, 1);
            TevColors[3] = new Color(0, 0, 0, 0);

            KonstColors[0] = new Color(1, 1, 1, 1);
            KonstColors[1] = new Color(1, 1, 1, 1);
            KonstColors[2] = new Color(1, 1, 1, opacity);
            KonstColors[3] = new Color(1, 1, 1, 1);

            MaterialColors[0] = new Color(0.8f, 0.8f, 0.8f, 1.0f);
            MaterialColors[1] = new Color(0.8f, 0.8f, 0.8f, 1.0f);

            AmbientColors[0] = new Color(0.196078435f, 0.196078435f, 0.196078435f, 0.196078435f);
            AmbientColors[1] = new Color(0, 0, 0, 0);

            ZMode = new ZMode(true, CompareType.LEqual, !IsTranslucent);

            if (IsTranslucent)
            {
                BMode       = new BlendMode(Enums.BlendMode.Blend, BlendModeControl.SrcAlpha, BlendModeControl.InverseSrcAlpha, LogicOp.Copy);
                AlphCompare = new AlphaCompare(CompareType.Always, 0, AlphaOp.Or, CompareType.Always, 0);
            }
            else
            {
                BMode       = new BlendMode(Enums.BlendMode.Blend, BlendModeControl.SrcAlpha, BlendModeControl.InverseSrcAlpha, LogicOp.NoOp);
                AlphCompare = new AlphaCompare(CompareType.GEqual, 128, AlphaOp.And, CompareType.LEqual, 255);
            }

            CullMode = CullMode.Back;
            ZCompLoc = false;
            Dither   = true;

            FogInfo = new Fog()
            {
                Type   = 2,
                Enable = false,
                Center = 320,
                StartZ = 10000.0f,
                EndZ   = 20000.0f,
                NearZ  = 5.0f,
                FarZ   = 50000.0f,
                Color  = new Color(1, 1, 1, 1),
                RangeAdjustmentTable = new float[]
                {
                    1.0f,
                    1.00390625f,
                    1.01171875f,
                    1.0234375f,
                    1.03515625f,
                    1.05078125f,
                    1.0703125f,
                    1.08984375f,
                    1.11328125f,
                    1.140625f
                }
            };
        }