示例#1
0
 private bool Compare(AlphaCompare obj)
 {
     if (Comp0 == obj.Comp0 && Reference0 == obj.Reference0 && Operation == obj.Operation &&
         Comp1 == obj.Comp1 && Reference1 == obj.Reference1)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#2
0
 public Material()
 {
     Name           = "";
     Flag           = 1;
     IndTexEntry    = new IndirectTexturing();
     CullMode       = GXCullMode.Back;
     MaterialColors = new Color?[2] {
         new Color(1, 1, 1, 1), new Color(1, 1, 1, 1)
     };
     ChannelControls = new ChannelControl[4]
     {
         new ChannelControl(false, (GXColorSrc)0, (GXLightId)0, (GXDiffuseFn)2, (GXAttenuationFn)1, (GXColorSrc)0),
         new ChannelControl(true, (GXColorSrc)0, (GXLightId)0, (GXDiffuseFn)1, (GXAttenuationFn)0, (GXColorSrc)0),
         new ChannelControl(false, (GXColorSrc)0, (GXLightId)0, (GXDiffuseFn)0, (GXAttenuationFn)2, (GXColorSrc)0),
         new ChannelControl(false, (GXColorSrc)1, (GXLightId)0, (GXDiffuseFn)2, (GXAttenuationFn)1, (GXColorSrc)0)
     };
     AmbientColors = new Color?[2] {
         new Color(0.1960f, 0.1960f, 0.1960f, 0.1960f), new Color(0, 0, 0, 0)
     };
     LightingColors = new Color?[8];
     TexCoord1Gens  = new TexCoordGen[8];
     TexCoord2Gens  = new TexCoordGen[8];
     TexMatrix1     = new TexMatrix[10];
     TexMatrix2     = new TexMatrix[20];
     Textures       = new BinaryTextureImage[8];
     TevOrders      = new TevOrder[16];
     ColorSels      = new GXKonstColorSel[16];
     AlphaSels      = new GXKonstAlphaSel[16];
     for (int i = 0; i < 16; i++)
     {
         ColorSels[i] = (GXKonstColorSel)0x0C;
         AlphaSels[i] = (GXKonstAlphaSel)0x1C;
     }
     TevColors = new Color?[4] {
         new Color(), new Color(), new Color(), new Color()
     };
     KonstColors = new Color?[4] {
         new Color(), new Color(), new Color(), new Color()
     };
     TevStages    = new TevStage[16];
     TevStages[0] = new TevStage();
     SwapModes    = new TevSwapMode[16];
     SwapModes[0] = new TevSwapMode();
     SwapTables   = new TevSwapModeTable[4] {
         new TevSwapModeTable(), new TevSwapModeTable(), new TevSwapModeTable(), new TevSwapModeTable()
     };
     FogInfo     = new Fog();
     AlphCompare = new AlphaCompare();
     BMode       = new BlendMode();
     ZMode       = new ZMode();
 }
示例#3
0
        public Material(Grendgine_Collada_Material source, string modelPath, Batch srcBatch)
        {
            Name           = source.Name;
            Flag           = 1;
            IndTexEntry    = new IndirectTexturing();
            CullMode       = GXCullMode.Back;
            MaterialColors = new Color?[2] {
                new Color(1, 1, 1, 1), new Color(1, 1, 1, 1)
            };
            ChannelControls = new ChannelControl[4]
            {
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register),
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register),
            };
            AmbientColors = new Color?[2] {
                new Color(0.1960f, 0.1960f, 0.1960f, 0.1960f), new Color(0, 0, 0, 0)
            };
            LightingColors = new Color?[8];
            TexCoord1Gens  = new TexCoordGen[8];
            TexCoord2Gens  = new TexCoordGen[8];
            TexMatrix1     = new TexMatrix[10];
            TexMatrix2     = new TexMatrix[20];
            Textures       = new BinaryTextureImage[8];
            TevOrders      = new TevOrder[16];
            TevOrders[0]   = new TevOrder(GXTexCoordSlot.Null, 0, GXColorChannelId.Color0A0);
            ColorSels      = new GXKonstColorSel[16];
            AlphaSels      = new GXKonstAlphaSel[16];
            for (int i = 0; i < 16; i++)
            {
                ColorSels[i] = GXKonstColorSel.KCSel_K0;
                AlphaSels[i] = GXKonstAlphaSel.KASel_K0_A;
            }
            TevColors = new Color?[4] {
                new Color(0, 0, 0, 1), new Color(1, 1, 1, 1), new Color(0, 0, 0, 0), new Color(1, 1, 1, 1)
            };
            KonstColors = new Color?[4] {
                new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1)
            };
            TevStages    = new TevStage[16];
            TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero },
                                        GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.RasAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, },
                                        GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0);
            SwapModes    = new TevSwapMode[16];
            SwapModes[0] = new TevSwapMode();
            SwapModes[1] = new TevSwapMode();
            SwapTables   = new TevSwapModeTable[4] {
                new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3)
            };
            FogInfo     = new Fog();
            AlphCompare = new AlphaCompare(GXCompareType.Always, 0, GXAlphaOp.Or, GXCompareType.Always, 0);
            BMode       = new BlendMode(GXBlendMode.None, GXBlendModeControl.One, GXBlendModeControl.Zero, GXLogicOp.Copy);
            ZMode       = new ZMode(true, GXCompareType.LEqual, true);

            ZCompLoc = true;
            Dither   = true;

            // Add texture to TEV stage data if there is one

            /*
             * if (source.HasTextureDiffuse)
             * {
             *  string path = "";//source.TextureDiffuse.FilePath;
             *  if (!Path.IsPathRooted(path))
             *  {
             *      string modelDir = Path.GetDirectoryName(modelPath);
             *      string texPath = string.Format("{0}\\{1}", modelDir, path);
             *
             *      if (File.Exists(texPath))
             *          path = texPath;
             *      else
             *          throw new ArgumentException(string.Format("Could not fined texture \"{0}\" at \"{1}\"!", path, texPath));
             *  }
             *
             *  string imageExt = Path.GetExtension(path).ToLower();
             *  Bitmap imageData = null;
             *
             *  switch (imageExt)
             *  {
             *      case ".png":
             *      case ".bmp":
             *          imageData = new Bitmap(path);
             *          break;
             *      case ".tga":
             *          imageData = TgaReader.Load(path);
             *          break;
             *      default:
             *          throw new ArgumentException(string.Format("Texture {0} was a {1}. Only PNG, BMP, or TGA images are supported!", path, imageExt));
             *  }
             *
             *  if (imageData == null)
             *      throw new ArgumentException(string.Format("Texture {0} could not be loaded!", path));
             *
             *  SetTexture(Path.GetFileNameWithoutExtension(path), imageData);
             * }*/

            // Add vertex colors to the shader if there are any

            /*
             * if (srcBatch.VertexColors[0].Count > 0)
             * {
             *  ChannelControls = new ChannelControl[4]
             *  {
             *      new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
             *      new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
             *      new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register),
             *      new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register),
             *  };
             *
             *  TevStages[1] = TevStages[0];
             *  TevStages[1].ColorIn[2] = GXCombineColorInput.ColorPrev;
             *
             *  TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.RasColor, GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero },
             *  GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.RasAlpha, source.HasTextureDiffuse ? GXCombineAlphaInput.TexAlpha : GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, },
             *  GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0);
             *
             *  TevOrders[1] = new TevOrder(GXTexCoordSlot.TexCoord0, 0, GXColorChannelId.Color0A0);
             * }*/

            foreach (ChannelControl chan in ChannelControls)
            {
                if (chan != null)
                {
                    ColorChannelControlsCount++;
                }
            }

            foreach (TexCoordGen gen in TexCoord1Gens)
            {
                if (gen != null)
                {
                    NumTexGensCount++;
                }
            }

            foreach (TevStage stage in TevStages)
            {
                if (stage != null)
                {
                    NumTevStagesCount++;
                }
            }
        }
示例#4
0
        public Material(Grendgine_Collada_Phong source, Batch batch, string modelPath, Grendgine_Collada_Image[] textures)
        {
            MatBatch = batch;

            Name           = batch.MaterialName;
            Flag           = 1;
            IndTexEntry    = new IndirectTexturing();
            CullMode       = GXCullMode.Back;
            MaterialColors = new Color?[2] {
                new Color(1, 1, 1, 1), new Color(1, 1, 1, 1)
            };
            ChannelControls = new ChannelControl[4]
            {
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register),
                new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register),
            };
            AmbientColors = new Color?[2] {
                new Color(0.1960f, 0.1960f, 0.1960f, 0.1960f), new Color(0, 0, 0, 0)
            };
            LightingColors = new Color?[8];
            TexCoord1Gens  = new TexCoordGen[8];
            TexCoord2Gens  = new TexCoordGen[8];
            TexMatrix1     = new TexMatrix[10];
            TexMatrix2     = new TexMatrix[20];
            Textures       = new BinaryTextureImage[8];
            TevOrders      = new TevOrder[16];
            TevOrders[0]   = new TevOrder(GXTexCoordSlot.Null, 0, GXColorChannelId.Color0A0);
            ColorSels      = new GXKonstColorSel[16];
            AlphaSels      = new GXKonstAlphaSel[16];
            for (int i = 0; i < 16; i++)
            {
                ColorSels[i] = GXKonstColorSel.KCSel_K0;
                AlphaSels[i] = GXKonstAlphaSel.KASel_K0_A;
            }
            TevColors = new Color?[4] {
                new Color(0, 0, 0, 1), new Color(1, 1, 1, 1), new Color(0, 0, 0, 0), new Color(1, 1, 1, 1)
            };
            KonstColors = new Color?[4] {
                new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1)
            };
            TevStages    = new TevStage[16];
            TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero },
                                        GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.RasAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, },
                                        GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0);
            SwapModes    = new TevSwapMode[16];
            SwapModes[0] = new TevSwapMode();
            SwapModes[1] = new TevSwapMode();
            SwapTables   = new TevSwapModeTable[4] {
                new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3)
            };
            FogInfo     = new Fog();
            AlphCompare = new AlphaCompare(GXCompareType.Always, 0, GXAlphaOp.Or, GXCompareType.Always, 0);
            BMode       = new BlendMode(GXBlendMode.None, GXBlendModeControl.One, GXBlendModeControl.Zero, GXLogicOp.Copy);
            ZMode       = new ZMode(true, GXCompareType.LEqual, true);

            ZCompLoc = true;
            Dither   = true;

            // Add texture to TEV stage data if there is one

            if (source.Diffuse.Texture != null)
            {
                string texName = source.Diffuse.Texture.Texture;
                string path    = textures.First(x => x.ID == texName).Init_From.Replace("file://", "");

                if (!Path.IsPathRooted(path))
                {
                    string modelDir = Path.GetDirectoryName(modelPath);
                    string texPath  = string.Format("{0}\\{1}", modelDir, path);

                    if (File.Exists(texPath))
                    {
                        path = texPath;
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("Could not find texture \"{0}\" at \"{1}\"!", path, texPath));
                    }
                }

                string imageExt  = Path.GetExtension(path).ToLower();
                Bitmap imageData = null;

                switch (imageExt)
                {
                case ".png":
                case ".bmp":
                    imageData = new Bitmap(path);
                    break;

                case ".tga":
                    imageData = TgaReader.Load(path);
                    break;

                default:
                    throw new ArgumentException(string.Format("Texture {0} was a {1}. Only PNG, BMP, or TGA images are supported!", path, imageExt));
                }

                if (imageData == null)
                {
                    throw new ArgumentException(string.Format("Texture {0} could not be loaded!", path));
                }

                SetTexture(source.Diffuse.Texture, Path.GetFileNameWithoutExtension(path), imageData);
            }

            // Add vertex colors to the shader if there are any

            if (batch.Attributes.Contains(VertexAttributes.Color0))
            {
                ChannelControls = new ChannelControl[4]
                {
                    new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
                    new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register),
                    new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register),
                    new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register),
                };

                TevStages[1]            = TevStages[0];
                TevStages[1].ColorIn[0] = GXCombineColorInput.ColorPrev;

                TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.C0, GXCombineColorInput.TexColor, GXCombineColorInput.RasColor, GXCombineColorInput.Zero },
                                            GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.A0, GXCombineAlphaInput.TexAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, },
                                            GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0);

                TevOrders[1] = new TevOrder(GXTexCoordSlot.TexCoord0, 0, GXColorChannelId.Color0A0);
            }

            foreach (ChannelControl chan in ChannelControls)
            {
                if (chan != null)
                {
                    ColorChannelControlsCount++;
                }
            }

            foreach (TexCoordGen gen in TexCoord1Gens)
            {
                if (gen != null)
                {
                    NumTexGensCount++;
                }
            }

            foreach (TevStage stage in TevStages)
            {
                if (stage != null)
                {
                    NumTevStagesCount++;
                }
            }
        }