Пример #1
0
        private static ShaderAssign ConvertShaderAssign(ShaderAssignStruct shader)
        {
            ShaderAssign shaderAssign = new ShaderAssign();

            shaderAssign.ShaderArchiveName = shader.ShaderArchive;
            shaderAssign.ShadingModelName  = shader.ShaderModel;

            foreach (var param in shader.SamplerAssign)
            {
                shaderAssign.SamplerAssigns.Add(param.Key, param.Value);
            }
            foreach (var param in shader.AttributeAssign)
            {
                shaderAssign.AttribAssigns.Add(param.Key, param.Value);
            }
            foreach (var param in shader.Options)
            {
                shaderAssign.ShaderOptions.Add(param.Key, param.Value);
            }

            return(shaderAssign);
        }
Пример #2
0
        public static Material CreateSwitchMaterial(this BFRES.MaterialData mat)
        {
            Material m = new Material();

            m.Flags            = (MaterialFlags)mat.IsVisable;
            m.Name             = mat.Name;
            m.TextureRefs      = new List <TextureRef>();
            m.RenderInfos      = new List <RenderInfo>();
            m.Samplers         = new List <Sampler>();
            m.VolatileFlags    = new byte[0];
            m.UserDatas        = new List <UserData>();
            m.ShaderParams     = new List <ShaderParam>();
            m.SamplerDict      = new ResDict();
            m.RenderInfoDict   = new ResDict();
            m.ShaderParamDict  = new ResDict();
            m.UserDataDict     = new ResDict();
            m.VolatileFlags    = new byte[0];
            m.TextureSlotArray = new long[mat.textures.Count];
            m.SamplerSlotArray = new long[mat.textures.Count];
            m.ShaderParamData  = WriteShaderParams(mat);

            int CurTex = 0;

            foreach (BFRES.MatTexture tex in mat.textures)
            {
                TextureRef texture = new TextureRef();
                texture.Name = tex.Name;
                m.TextureRefs.Add(texture);

                Sampler samp = new Sampler();
                samp.BorderColorType = tex.BorderColorType;
                samp.CompareFunc     = tex.CompareFunc;
                samp.FilterMode      = tex.FilterMode;
                samp.LODBias         = tex.LODBias;
                samp.MaxAnisotropic  = tex.MaxAnisotropic;
                samp.MaxLOD          = tex.magFilter;
                samp.MinLOD          = tex.minFilter;
                samp.WrapModeU       = (TexClamp)tex.wrapModeS;
                samp.WrapModeV       = (TexClamp)tex.wrapModeT;
                samp.WrapModeW       = (TexClamp)tex.wrapModeW;

                m.Samplers.Add(samp);

                m.SamplerDict.Add(tex.SamplerName);

                m.TextureSlotArray[CurTex] = -1;
                m.SamplerSlotArray[CurTex] = -1;

                CurTex++;
            }

            int CurParam = 0;

            foreach (var prm in mat.matparam)
            {
                ShaderParam shaderParam = new ShaderParam();
                shaderParam.Name          = prm.Key;
                shaderParam.Type          = (ShaderParamType)prm.Value.Type;
                shaderParam.DependIndex   = (ushort)CurParam;
                shaderParam.DependedIndex = (ushort)CurParam;
                shaderParam.DataOffset    = (ushort)prm.Value.DataOffset;
                CurParam++;
            }
            foreach (BFRES.RenderInfoData rnd in mat.renderinfo)
            {
                RenderInfo renderInfo = new RenderInfo();
                renderInfo.Name = rnd.Name;

                if (rnd.Type == Syroot.NintenTools.Bfres.RenderInfoType.Int32)
                {
                    renderInfo.SetValue(rnd.Value_Ints);
                }
                if (rnd.Type == Syroot.NintenTools.Bfres.RenderInfoType.Single)
                {
                    renderInfo.SetValue(rnd.Value_Floats);
                }
                if (rnd.Type == Syroot.NintenTools.Bfres.RenderInfoType.String)
                {
                    renderInfo.SetValue(rnd.Value_Strings);
                }

                m.RenderInfos.Add(renderInfo);
            }

            ShaderAssign shaderAssign = new ShaderAssign();

            shaderAssign.ShaderArchiveName = mat.shaderassign.ShaderArchive;
            shaderAssign.ShadingModelName  = mat.shaderassign.ShaderModel;

            shaderAssign.ShaderOptionDict  = new ResDict();
            shaderAssign.AttribAssignDict  = new ResDict();
            shaderAssign.SamplerAssignDict = new ResDict();
            shaderAssign.ShaderOptions     = new List <string>();
            shaderAssign.AttribAssigns     = new List <string>();
            shaderAssign.SamplerAssigns    = new List <string>();

            foreach (var op in mat.shaderassign.options)
            {
                shaderAssign.ShaderOptionDict.Add(op.Key);
                shaderAssign.ShaderOptions.Add(op.Value);
            }
            foreach (var att in mat.shaderassign.attributes)
            {
                shaderAssign.AttribAssignDict.Add(att.Key);
                shaderAssign.AttribAssigns.Add(att.Value);
            }
            foreach (var smp in mat.shaderassign.samplers)
            {
                shaderAssign.SamplerAssignDict.Add(smp.Key);
                shaderAssign.SamplerAssigns.Add(smp.Value);
            }

            m.ShaderAssign = shaderAssign;

            return(m);
        }