Пример #1
0
        public static void ReadShaderAssign(this FMAT m, Material mat)
        {
            m.shaderassign = new FMAT.ShaderAssign();

            if (mat.ShaderAssign == null)
            {
                mat.ShaderAssign = new ShaderAssign();
            }
            if (mat.ShaderAssign.ShaderOptions == null)
            {
                mat.ShaderAssign.ShaderOptions = new ResDict <ResString>();
            }
            if (mat.ShaderAssign.AttribAssigns == null)
            {
                mat.ShaderAssign.AttribAssigns = new ResDict <ResString>();
            }
            if (mat.ShaderAssign.SamplerAssigns == null)
            {
                mat.ShaderAssign.SamplerAssigns = new ResDict <ResString>();
            }

            m.shaderassign.options.Clear();
            m.shaderassign.samplers.Clear();
            m.shaderassign.attributes.Clear();

            m.shaderassign = new FMAT.ShaderAssign();
            m.shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;
            m.shaderassign.ShaderModel   = mat.ShaderAssign.ShadingModelName;

            foreach (var op in mat.ShaderAssign.ShaderOptions)
            {
                m.shaderassign.options.Add(op.Key, op.Value);
            }

            if (mat.ShaderAssign.SamplerAssigns != null)
            {
                foreach (var op in mat.ShaderAssign.SamplerAssigns)
                {
                    m.shaderassign.samplers.Add(op.Key, op.Value);
                }
            }
            if (mat.ShaderAssign.AttribAssigns != null)
            {
                foreach (var op in mat.ShaderAssign.AttribAssigns)
                {
                    m.shaderassign.attributes.Add(op.Key, op.Value);
                }
            }
        }
Пример #2
0
        public static void ReadShaderAssign(this FMAT m, Material mat)
        {
            m.shaderassign = new FMAT.ShaderAssign();

            if (mat.ShaderAssign == null)
            {
                mat.ShaderAssign = new ShaderAssign();
            }
            if (mat.ShaderAssign.ShaderOptions == null)
            {
                mat.ShaderAssign.ShaderOptions = new List <string>();
            }
            if (mat.ShaderAssign.AttribAssigns == null)
            {
                mat.ShaderAssign.AttribAssigns = new List <string>();
            }
            if (mat.ShaderAssign.SamplerAssigns == null)
            {
                mat.ShaderAssign.SamplerAssigns = new List <string>();
            }

            m.shaderassign.options.Clear();
            m.shaderassign.samplers.Clear();
            m.shaderassign.attributes.Clear();

            m.shaderassign = new FMAT.ShaderAssign();
            m.shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;
            m.shaderassign.ShaderModel   = mat.ShaderAssign.ShadingModelName;

            for (int op = 0; op < mat.ShaderAssign.ShaderOptions.Count; op++)
            {
                m.shaderassign.options.Add(mat.ShaderAssign.ShaderOptionDict.GetKey(op), mat.ShaderAssign.ShaderOptions[op]);
            }

            if (mat.ShaderAssign.SamplerAssigns != null)
            {
                for (int op = 0; op < mat.ShaderAssign.SamplerAssigns.Count; op++)
                {
                    m.shaderassign.samplers.Add(mat.ShaderAssign.SamplerAssignDict.GetKey(op), mat.ShaderAssign.SamplerAssigns[op]);
                }
            }
            if (mat.ShaderAssign.AttribAssigns != null)
            {
                for (int op = 0; op < mat.ShaderAssign.AttribAssigns.Count; op++)
                {
                    m.shaderassign.attributes.Add(mat.ShaderAssign.AttribAssignDict.GetKey(op), mat.ShaderAssign.AttribAssigns[op]);
                }
            }
        }
Пример #3
0
        public static void WriteTextureRefs(this FMAT m, Material mat)
        {
            mat.TextureRefs = new List <TextureRef>();
            mat.TextureRefs.Clear();

            foreach (var textu in m.textures)
            {
                TextureRef texref = new TextureRef();
                texref.Name = textu.Name;
                Texture texMapped = new Texture();
                m.BFRESRender.resFileU.Textures.TryGetValue(textu.Name, out texMapped);
                texref.Texture = texMapped;
                mat.TextureRefs.Add(texref);
            }
        }
Пример #4
0
        public void InitializeRenderInfoList(FMAT mat)
        {
            material = mat;

            renderInfoListView.BeginUpdate();
            renderInfoListView.Items.Clear();

            foreach (var rnd in material.renderinfo)
            {
                renderInfoListView.Items.Add(CreateRenderInfoItem(rnd));
            }

            renderInfoListView.FullRowSelect = true;
            renderInfoListView.EndUpdate();
        }
Пример #5
0
        private static void SetUniforms(FMAT mat, Shader shader, FSHP m, int id)
        {
            shader.SetVector4("gsys_bake_st0", new Vector4(1, 1, 0, 0));
            shader.SetVector4("gsys_bake_st1", new Vector4(1, 1, 0, 0));
            shader.SetVector4("const_color0", new Vector4(1, 1, 1, 1));
            shader.SetVector4("base_color_mul_color", new Vector4(1, 1, 1, 1));

            shader.SetInt("enableCellShading", 0);
            bool HasTans = m.vertexAttributes.Any(x => x.Name == "_t0");

            shader.SetBoolToInt("hasTangents", HasTans);

            SetUniformData(mat, shader, "gsys_bake_st0");
            SetUniformData(mat, shader, "gsys_bake_st1");
            SetUniformData(mat, shader, "const_color0");
            SetUniformData(mat, shader, "base_color_mul_color");
        }
Пример #6
0
        public static void Read(FMAT mat, string FileName, bool OnlyMatParams = false)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(FileName);

            foreach (XmlNode node in doc.ChildNodes)
            {
                foreach (XmlNode n in node.ChildNodes)
                {
                    if (n.Name == "MaterialParameters")
                    {
                        ReadShaderParams(doc, n, mat);
                    }
                }
            }
        }
Пример #7
0
        private static void CheckRenderPass(FMAT mat)
        {
            if (mat.ImageKey != "material")
            {
                mat.ImageKey         = "material";
                mat.SelectedImageKey = "material";
            }

            bool IsTranslucent     = false;
            bool IsTransparentMask = false;


            for (int i = 0; i < mat.renderinfo.Count; i++)
            {
                if (mat.renderinfo[i].Name == "gsys_render_state_mode")
                {
                    IsTranslucent     = mat.renderinfo[i].ValueString.Contains("translucent");
                    IsTransparentMask = mat.renderinfo[i].ValueString.Contains("mask");
                }
                if (mat.renderinfo[i].Name == "renderPass")
                {
                    IsTransparentMask = mat.renderinfo[i].ValueString.Contains("xlu");
                }
            }

            if (mat.shaderassign.options.ContainsKey("enable_translucent"))
            {
                IsTranslucent = mat.shaderassign.options["enable_translucent"] == "1";
            }
            if (mat.shaderassign.options.ContainsKey("enable_translucent"))
            {
                IsTransparentMask = mat.shaderassign.options["enable_transparent"] == "1";
            }

            if (mat.MaterialU != null)
            {
                IsTranslucent     = mat.MaterialU.RenderState.FlagsMode == ResU.RenderStateFlagsMode.Translucent;
                IsTransparentMask = mat.MaterialU.RenderState.FlagsMode == ResU.RenderStateFlagsMode.AlphaMask;
            }

            mat.isTransparent = IsTransparentMask || IsTranslucent;

            SetMaterialIcon(mat, IsTranslucent, "MaterialTranslucent");
            SetMaterialIcon(mat, IsTransparentMask, "MaterialTransparent");
        }
Пример #8
0
        public static void ReadMaterial(this FMAT m, Material mat)
        {
            if (mat.Flags == MaterialFlags.Visible)
            {
                m.Enabled = true;
            }
            else
            {
                m.Enabled = false;
            }

            m.ReadRenderInfo(mat);
            m.ReadShaderAssign(mat);
            m.SetActiveGame();
            m.ReadShaderParams(mat);
            m.MaterialU = mat;
            m.ReadTextureRefs(mat);
        }
Пример #9
0
        private static void SetDefaultTextureAttributes(FMAT mat, SF.Shader shader)
        {
            shader.SetBoolToInt("HasDiffuse", mat.HasDiffuseMap);
            shader.SetBoolToInt("HasDiffuseLayer", mat.HasDiffuseLayer);
            shader.SetBoolToInt("HasNormalMap", mat.HasNormalMap);
            shader.SetBoolToInt("HasEmissionMap", mat.HasEmissionMap);
            shader.SetBoolToInt("HasLightMap", mat.HasLightMap);
            shader.SetBoolToInt("HasShadowMap", mat.HasShadowMap);
            shader.SetBoolToInt("HasSpecularMap", mat.HasSpecularMap);
            shader.SetBoolToInt("HasTeamColorMap", mat.HasTeamColorMap);
            shader.SetBoolToInt("HasSphereMap", mat.HasSphereMap);
            shader.SetBoolToInt("HasSubSurfaceScatteringMap", mat.HasSubSurfaceScatteringMap);

            //Unused atm untill I do PBR shader
            shader.SetBoolToInt("HasMetalnessMap", mat.HasMetalnessMap);
            shader.SetBoolToInt("HasRoughnessMap", mat.HasRoughnessMap);
            shader.SetBoolToInt("HasMRA", mat.HasMRA);
        }
Пример #10
0
        public static void Save(FMAT mat, string FileName, bool OnlyMaterialParams = false)
        {
            XmlDocument doc      = new XmlDocument();
            XmlNode     mainNode = doc.CreateElement("FMAT");

            AddAttribute(doc, "Name", mat.Text, mainNode);
            doc.AppendChild(mainNode);

            if (OnlyMaterialParams)
            {
                AppendMaterialParams(mat, doc, mainNode);
            }
            else
            {
                AppendMaterialParams(mat, doc, mainNode);
            }
            doc.Save(FileName);
        }
Пример #11
0
        public static void Read(BFRESRender renderer, ResFile resFile, TreeNode ResFileNode)
        {
            int CurMdl = 0;

            foreach (Model mdl in resFile.Models.Values)
            {
                FMDL model = new FMDL();
                model.Text     = mdl.Name;
                model.Skeleton = new FSKL(mdl.Skeleton);
                model.Nodes.Add(model.Skeleton.node);
                model.Skeleton.reset();
                model.Skeleton.update();
                model.BFRESRender = renderer;
                model.Skeleton.node.BFRESRender = renderer;
                model.ModelU = mdl;
                foreach (Material mat in mdl.Materials.Values)
                {
                    FMAT FMAT = new FMAT();
                    FMAT.BFRESRender = renderer;
                    FMAT.Text        = mat.Name;
                    FMAT.ReadMaterial(mat);
                    model.Nodes[1].Nodes.Add(FMAT);
                    model.materials.Add(FMAT.Text, FMAT);
                }
                foreach (Shape shp in mdl.Shapes.Values)
                {
                    VertexBuffer vertexBuffer = mdl.VertexBuffers[shp.VertexBufferIndex];
                    Material     material     = mdl.Materials[shp.MaterialIndex];
                    FSHP         mesh         = new FSHP();
                    mesh.BFRESRender = renderer;
                    mesh.ModelIndex  = CurMdl;
                    ReadShapesVertices(mesh, shp, vertexBuffer, model);
                    mesh.MaterialIndex = shp.MaterialIndex;

                    model.Nodes[0].Nodes.Add(mesh);
                    model.shapes.Add(mesh);
                }
                ResFileNode.Nodes[0].Nodes.Add(model);
                renderer.models.Add(model);

                CurMdl++;
            }
        }
Пример #12
0
        public static void ReadRenderInfo(this FMAT m, Material mat)
        {
            m.renderinfo.Clear();

            foreach (RenderInfo rnd in mat.RenderInfos.Values)
            {
                BfresRenderInfo r = new BfresRenderInfo();
                r.Name = rnd.Name;
                r.Type = r.GetTypeWiiU(rnd.Type);
                switch (rnd.Type)
                {
                case RenderInfoType.Int32: r.ValueInt = rnd.GetValueInt32s(); break;

                case RenderInfoType.Single: r.ValueFloat = rnd.GetValueSingles(); break;

                case RenderInfoType.String: r.ValueString = rnd.GetValueStrings(); break;
                }
                m.renderinfo.Add(r);
            }
        }
Пример #13
0
        public void InitializeShaderParamList(FMAT mat)
        {
            material = mat;

            int CurParam = 0;

            shaderParamListView.Items.Clear();
            foreach (BfresShaderParam prm in mat.matparam.Values)
            {
                var item = new ListViewItem(prm.Name);
                ShaderParamToListItem(prm, item);

                shaderParamListView.View = View.Details;
                shaderParamListView.Items.Add(item);
                CurParam++;
            }
            il.ImageSize = new Size(10, 10);
            shaderParamListView.SmallImageList = il;
            shaderParamListView.FullRowSelect  = true;
        }
Пример #14
0
        public void UpdateSingleMaterialTextureMaps(FMAT mat)
        {
            if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized)
            {
                return;
            }

            foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
            {
                foreach (var t in mat.textures)
                {
                    if (bntx.Textures.ContainsKey(t.Name))
                    {
                        bntx.Textures[t.Name].LoadOpenGLTexture();
                    }
                }
            }

            Viewport.Instance.UpdateViewport();
        }
Пример #15
0
        public void LoadMaterial(FMAT mat)
        {
            if (mat.MaterialU != null)
            {
                TabPage tabPage = null;

                for (int i = 0; i < stTabControl1.TabPages.Count; i++)
                {
                    if (stTabControl1.TabPages[i].Text == "Render State")
                    {
                        tabPage = stTabControl1.TabPages[i];
                    }
                }

                if (tabPage == null)
                {
                    tabPage      = new TabPage();
                    tabPage.Text = "Render State";
                    stTabControl1.TabPages.Add(tabPage);
                    RenderStateEditor      = new RenderStateEditor();
                    RenderStateEditor.Dock = DockStyle.Fill;
                    RenderStateEditor.LoadRenderState(mat.MaterialU.RenderState);
                    tabPage.Controls.Add(RenderStateEditor);
                }
                else
                {
                    RenderStateEditor.LoadRenderState(mat.MaterialU.RenderState);
                }
            }

            material = mat;
            textBoxMaterialName.Text = material.Text;

            SetActiveGameByShader(material.shaderassign.ShaderArchive, material.shaderassign.ShaderModel);

            chkboxVisible.Bind(material, "Enabled");

            FillForm();
        }
Пример #16
0
        private static bool TextureUniform(SF.Shader shader, FMAT mat, string name, MatTexture mattex)
        {
            if (mattex.textureState == STGenericMatTexture.TextureState.Binded)
            {
                return(true);
            }

            // Bind the texture and create the uniform if the material has the right textures.
            bool IsBound = BindTexture(mattex, mat, shader, mat.GetResFileU() != null);
            int  texId   = mattex.textureUnit + 1;

            if (IsBound)
            {
                GL.Uniform1(shader.GetUniformLocation(name), texId);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Пример #17
0
        public static void ReadMaterial(this FMAT m, Material mat)
        {
            if (mat.Flags == MaterialFlags.Visible)
            {
                m.Enabled = true;
            }
            else
            {
                m.Enabled = false;
            }

            m.ReadRenderInfo(mat);
            m.ReadShaderAssign(mat);
            m.SetActiveGame();
            m.ReadShaderParams(mat);
            m.Material = mat;
            m.ReadTextureRefs(mat);

            if (Runtime.activeGame == Runtime.ActiveGame.KSA)
            {
                KsaShader.LoadRenderInfo(m, m.renderinfo);
            }
        }
Пример #18
0
        public void UpdateSingleMaterialTextureMaps(FMAT mat)
        {
            if (!Runtime.OpenTKInitialized)
            {
                return;
            }

            foreach (BNTX bntx in PluginRuntime.bntxContainers)
            {
                foreach (var t in mat.TextureMaps)
                {
                    if (bntx.Textures.ContainsKey(t.Name))
                    {
                        if (!bntx.Textures[t.Name].RenderableTex.GLInitialized)
                        {
                            bntx.Textures[t.Name].LoadOpenGLTexture();
                        }
                    }
                }
            }

            LibraryGUI.UpdateViewport();
        }
Пример #19
0
        public static void WriteRenderInfo(this FMAT m, Material mat)
        {
            if (mat.RenderInfos == null)
            {
                mat.RenderInfos = new List <RenderInfo>();
            }

            mat.RenderInfos.Clear();
            foreach (BfresRenderInfo rnd in m.renderinfo)
            {
                RenderInfo r = new RenderInfo();
                r.Name = rnd.Name;
                switch (rnd.Type)
                {
                case RenderInfoType.Int32: r.SetValue(rnd.ValueInt); break;

                case RenderInfoType.Single: r.SetValue(rnd.ValueFloat); break;

                case RenderInfoType.String: r.SetValue(rnd.ValueString); break;
                }
                mat.RenderInfos.Add(r);
            }
        }
Пример #20
0
        private static void SetRenderPass(FMAT mat)
        {
            bool NoCull    = false;
            bool CullBack  = false;
            bool CullFront = false;

            for (int i = 0; i < mat.renderinfo.Count; i++)
            {
                if (mat.renderinfo[i].Name == "display_face")
                {
                    NoCull    = mat.renderinfo[i].ValueString.Contains("both");
                    CullFront = mat.renderinfo[i].ValueString.Contains("back");
                    CullBack  = mat.renderinfo[i].ValueString.Contains("front");
                }

                if (mat.shaderassign.ShaderArchive == "Turbo_UBER")
                {
                    AglShaderTurbo aglShader = new AglShaderTurbo();
                    aglShader.LoadRenderInfo(mat.renderinfo[i]);
                }
            }

            if (NoCull)
            {
                GL.Disable(EnableCap.CullFace);
            }
            else if (CullFront)
            {
                GL.Enable(EnableCap.CullFace);
                GL.CullFace(CullFaceMode.Front);
            }
            else if (CullBack)
            {
                GL.Enable(EnableCap.CullFace);
                GL.CullFace(CullFaceMode.Back);
            }
        }
Пример #21
0
        public void InitializeShaderOptionList(FMAT mat)
        {
            material = mat;

            List <Options> options = new List <Options>();

            shaderOptionsListView.BeginUpdate();
            shaderOptionsListView.Items.Clear();
            shaderOptionsListView.BackColor = FormThemes.BaseTheme.FormBackColor;
            shaderOptionsListView.ForeColor = FormThemes.BaseTheme.FormForeColor;

            foreach (var option in material.shaderassign.options)
            {
                options.Add(new Options()
                {
                    Name = option.Key, Value = option.Value
                });
            }

            shaderOptionsListView.SetObjects(options);
            options.Clear();
            shaderOptionsListView.FillLastColumnSpace(true);
            shaderOptionsListView.EndUpdate();
        }
Пример #22
0
        public void InitializeTextureListView(FMAT fmat)
        {
            material = fmat;

            textureRefListView.Items.Clear();
            textureRefListView.SmallImageList = textureImageList;
            textureRefListView.FullRowSelect  = true;

            foreach (MatTexture tex in material.TextureMaps)
            {
                ListViewItem item = new ListViewItem();
                item.Text = tex.Name;
                item.SubItems.Add(tex.SamplerName);

                if (material.shaderassign.samplers.ContainsValue(tex.SamplerName))
                {
                    var FragSampler = material.shaderassign.samplers.FirstOrDefault(x => x.Value == tex.SamplerName).Key;
                    item.SubItems.Add(FragSampler.ToString());
                }

                textureRefListView.Items.Add(item);
            }

            int CurTex = 0;

            if (PluginRuntime.bntxContainers.Count == 0 &&
                PluginRuntime.ftexContainers.Count == 0)
            {
                foreach (ListViewItem item in textureRefListView.Items)
                {
                    AddBlankTexture(item, item.Text, CurTex++);
                }
            }
            //Still somewhat slower
            //   ReloadImageList();
        }
Пример #23
0
        public static void LoadMatEditor(FMAT mat)
        {
            foreach (Control control in FirstPlugin.MainF.Controls)
            {
                if (control is DockPanel)
                {
                    if (FirstPlugin.DockedEditorS == null)
                    {
                        FirstPlugin.DockedEditorS = new DockContent();
                        FirstPlugin.DockedEditorS.Show((DockPanel)control, PluginRuntime.FSHPDockState);
                    }
                }
            }

            if (!EditorIsActive(FirstPlugin.DockedEditorS))
            {
                FirstPlugin.DockedEditorS.Controls.Clear();
                FMATEditor editor = new FMATEditor();
                editor.Text = mat.Text;
                editor.Dock = DockStyle.Fill;
                editor.LoadMaterial(mat, mat.BFRESRender);
                FirstPlugin.DockedEditorS.Controls.Add(editor);
            }
            bool EditorIsActive(DockContent dock)
            {
                foreach (Control ctrl in dock.Controls)
                {
                    if (ctrl is FMATEditor)
                    {
                        ((FMATEditor)ctrl).LoadMaterial(mat, mat.BFRESRender);
                        return(true);
                    }
                }
                return(false);
            }
        }
Пример #24
0
        public static void ReadTextureRefs(this FMAT m, Material mat)
        {
            m.TextureMaps.Clear();

            int    AlbedoCount = 0;
            int    id          = 0;
            string TextureName = "";

            if (mat.TextureRefs == null)
            {
                mat.TextureRefs = new List <TextureRef>();
            }

            int textureUnit = 1;

            foreach (var tex in mat.TextureRefs)
            {
                TextureName = tex.Name;

                MatTexture texture = new MatTexture();
                texture.wiiUSampler = mat.Samplers[id].TexSampler;

                texture.MinLod  = mat.Samplers[id].TexSampler.MinLod;
                texture.MaxLod  = mat.Samplers[id].TexSampler.MaxLod;
                texture.BiasLod = mat.Samplers[id].TexSampler.LodBias;

                texture.wrapModeS = (int)mat.Samplers[id].TexSampler.ClampX;
                texture.wrapModeT = (int)mat.Samplers[id].TexSampler.ClampY;
                texture.wrapModeW = (int)mat.Samplers[id].TexSampler.ClampZ;
                mat.Samplers.TryGetKey(mat.Samplers[id], out texture.SamplerName);

                string useSampler = texture.SamplerName;

                //Use the fragment sampler in the shader assign section. It's usually more accurate this way
                if (mat.ShaderAssign.SamplerAssigns.ContainsKey(texture.SamplerName))
                {
                    useSampler = mat.ShaderAssign.SamplerAssigns[texture.SamplerName];
                }


                if (mat.Samplers[id].TexSampler.MinFilter == GX2TexXYFilterType.Point)
                {
                    texture.minFilter = 1;
                }
                if (mat.Samplers[id].TexSampler.MagFilter == GX2TexXYFilterType.Point)
                {
                    texture.magFilter = 1;
                }
                if (mat.Samplers[id].TexSampler.MinFilter == GX2TexXYFilterType.Bilinear)
                {
                    texture.minFilter = 0;
                }
                if (mat.Samplers[id].TexSampler.MagFilter == GX2TexXYFilterType.Bilinear)
                {
                    texture.magFilter = 0;
                }

                if (Runtime.activeGame == Runtime.ActiveGame.MK8D)
                {
                    if (useSampler == "_a0")
                    {
                        if (AlbedoCount == 0)
                        {
                            m.HasDiffuseMap = true;
                            AlbedoCount++;
                            texture.Type = MatTexture.TextureType.Diffuse;
                        }
                    }
                    if (useSampler == "_n0")
                    {
                        m.HasNormalMap = true;
                        texture.Type   = MatTexture.TextureType.Normal;
                    }
                    if (useSampler == "_e0")
                    {
                        m.HasEmissionMap = true;
                        texture.Type     = MatTexture.TextureType.Emission;
                    }
                    if (useSampler == "_s0")
                    {
                        m.HasSpecularMap = true;
                        texture.Type     = MatTexture.TextureType.Specular;
                    }
                    if (useSampler == "_x0")
                    {
                        m.HasSphereMap = true;
                        texture.Type   = MatTexture.TextureType.SphereMap;
                    }
                    if (useSampler == "_b0")
                    {
                        m.HasShadowMap = true;
                        texture.Type   = MatTexture.TextureType.Shadow;
                    }
                    if (useSampler == "_b1")
                    {
                        m.HasLightMap = true;
                        texture.Type  = MatTexture.TextureType.Light;
                    }
                }
                else if (Runtime.activeGame == Runtime.ActiveGame.SMO)
                {
                    if (useSampler == "_a0")
                    {
                        if (AlbedoCount == 0)
                        {
                            m.HasDiffuseMap = true;
                            AlbedoCount++;
                            texture.Type = MatTexture.TextureType.Diffuse;
                        }
                    }
                    if (useSampler == "_n0")
                    {
                        m.HasNormalMap = true;
                        texture.Type   = MatTexture.TextureType.Normal;
                    }
                    if (useSampler == "_e0")
                    {
                        m.HasEmissionMap = true;
                        texture.Type     = MatTexture.TextureType.Emission;
                    }
                    if (TextureName.Contains("mtl"))
                    {
                        m.HasMetalnessMap = true;
                        texture.Type      = MatTexture.TextureType.Metalness;
                    }
                    else if (TextureName.Contains("rgh"))
                    {
                        texture.Type      = MatTexture.TextureType.Roughness;
                        m.HasRoughnessMap = true;
                    }
                    else if (TextureName.Contains("sss"))
                    {
                        texture.Type = MatTexture.TextureType.SubSurfaceScattering;
                        m.HasSubSurfaceScatteringMap = true;
                    }
                }
                else
                {
                    if (texture.SamplerName == "_a0")
                    {
                        m.HasDiffuseMap = true;
                        AlbedoCount++;
                        texture.Type = MatTexture.TextureType.Diffuse;
                    }
                    if (texture.SamplerName == "_n0")
                    {
                        m.HasNormalMap = true;
                        texture.Type   = MatTexture.TextureType.Normal;
                    }
                    else if (TextureName.Contains("Emm"))
                    {
                        m.HasEmissionMap = true;
                        texture.Type     = MatTexture.TextureType.Emission;
                    }
                    else if (TextureName.Contains("Spm"))
                    {
                        m.HasSpecularMap = true;
                        texture.Type     = MatTexture.TextureType.Specular;
                    }
                    else if (TextureName.Contains("b00"))
                    {
                        m.HasShadowMap = true;
                        texture.Type   = MatTexture.TextureType.Shadow;
                    }
                    else if (TextureName.Contains("Moc") || TextureName.Contains("AO"))
                    {
                        m.HasAmbientOcclusionMap = true;
                        texture.Type             = MatTexture.TextureType.AO;
                    }
                    else if (TextureName.Contains("b01"))
                    {
                        m.HasLightMap = true;
                        texture.Type  = MatTexture.TextureType.Light;
                    }
                    else if (TextureName.Contains("MRA")) //Metalness, Roughness, and Cavity Map in one
                    {
                        m.HasRoughnessMap = true;
                        texture.Type      = MatTexture.TextureType.MRA;
                    }
                    else if (TextureName.Contains("mtl"))
                    {
                        m.HasMetalnessMap = true;
                        texture.Type      = MatTexture.TextureType.Metalness;
                    }
                    else if (TextureName.Contains("rgh"))
                    {
                        texture.Type      = MatTexture.TextureType.Roughness;
                        m.HasRoughnessMap = true;
                    }
                    else if (TextureName.Contains("sss"))
                    {
                        texture.Type = MatTexture.TextureType.SubSurfaceScattering;
                        m.HasSubSurfaceScatteringMap = true;
                    }
                }

                texture.textureUnit = textureUnit++;

                texture.Name = TextureName;
                m.TextureMaps.Add(texture);

                id++;
            }
        }
Пример #25
0
 public static void ReadRenderState(this FMAT m, RenderState renderState)
 {
 }
Пример #26
0
 public static void ReadTextureRefs(XmlDocument doc, XmlNode parentNode, FMAT mat)
 {
 }
Пример #27
0
        public void InitializeShaderParamList(FMAT mat)
        {
            material = mat;

            stFlowLayoutPanel1.SuspendLayout();
            stFlowLayoutPanel1.Controls.Clear();


            foreach (BfresShaderParam param in mat.matparam.Values)
            {
                if (param.Type == ShaderParamType.Bool ||
                    param.Type == ShaderParamType.Bool2 ||
                    param.Type == ShaderParamType.Bool3 ||
                    param.Type == ShaderParamType.Bool4)
                {
                    booleanPanel panel = new booleanPanel(param.ValueBool, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.TexSrt)
                {
                    TexSrtPanel panel = new TexSrtPanel(param.ValueTexSrt, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Float)
                {
                    vector1SliderPanel panel = new vector1SliderPanel(param.ValueFloat, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Float2)
                {
                    vector2SliderPanel panel = new vector2SliderPanel(param.ValueFloat, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Float3)
                {
                    vector3SliderPanel panel = new vector3SliderPanel(param.Name, param.ValueFloat, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Float4)
                {
                    vector4SliderPanel panel = new vector4SliderPanel(param.Name, param.ValueFloat, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.UInt)
                {
                    vector1SliderPanel panel = new vector1SliderPanel(param.ValueUint, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.UInt2)
                {
                    vector2SliderPanel panel = new vector2SliderPanel(param.ValueUint, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.UInt3)
                {
                    vector3SliderPanel panel = new vector3SliderPanel(param.Name, param.ValueUint, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.UInt4)
                {
                    vector4SliderPanel panel = new vector4SliderPanel(param.Name, param.ValueUint, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Int)
                {
                    vector1SliderPanel panel = new vector1SliderPanel(param.ValueInt, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Int2)
                {
                    vector2SliderPanel panel = new vector2SliderPanel(param.ValueInt, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Int3)
                {
                    vector3SliderPanel panel = new vector3SliderPanel(param.Name, param.ValueInt, param);
                    LoadDropPanel(panel, param);
                }
                if (param.Type == ShaderParamType.Int4)
                {
                    vector4SliderPanel panel = new vector4SliderPanel(param.Name, param.ValueInt, param);
                    LoadDropPanel(panel, param);
                }
            }

            stFlowLayoutPanel1.ResumeLayout();
        }
Пример #28
0
        private static void WriteTextureRefs(FMAT mat, XmlDocument doc, XmlNode parentNode)
        {
            XmlNode matParamsNode = doc.CreateElement("TextureRefs");

            parentNode.AppendChild(matParamsNode);
        }
Пример #29
0
        public void InitializeTextureListView(FMAT fmat)
        {
            material = fmat;

            textureRefListView.Items.Clear();
            textureRefListView.SmallImageList = textureImageList;
            textureRefListView.FullRowSelect  = true;

            foreach (MatTexture tex in material.TextureMaps)
            {
                ListViewItem item = new ListViewItem();
                item.Text = tex.Name;
                item.SubItems.Add(tex.SamplerName);

                if (material.shaderassign.samplers.ContainsValue(tex.SamplerName))
                {
                    var FragSampler = material.shaderassign.samplers.FirstOrDefault(x => x.Value == tex.SamplerName).Key;
                    item.SubItems.Add(FragSampler.ToString());
                }

                textureRefListView.Items.Add(item);
            }

            textureImageList.Images.Clear();

            int CurTex = 0;

            if (PluginRuntime.bntxContainers.Count == 0 &&
                PluginRuntime.ftexContainers.Count == 0)
            {
                foreach (ListViewItem item in textureRefListView.Items)
                {
                    AddBlankTexture(item, item.Text, CurTex++);
                }
            }
            return;


            bool FoundTexture = false;

            foreach (ListViewItem item in textureRefListView.Items)
            {
                foreach (BNTX bntx in PluginRuntime.bntxContainers)
                {
                    if (bntx.Textures.ContainsKey(item.Text))
                    {
                        FoundTexture = true;

                        Thread Thread = new Thread((ThreadStart)(() =>
                        {
                            Bitmap temp = bntx.Textures[item.Text].GetBitmap();

                            textureRefListView.Invoke(new Action(() =>
                            {
                                textureImageList.Images.Add(item.Text, temp);
                            }));

                            temp.Dispose();
                        }));
                        Thread.Start();

                        item.ImageIndex = CurTex++;
                    }
                }
                foreach (BFRESGroupNode ftexCont in PluginRuntime.ftexContainers)
                {
                    if (ftexCont.ResourceNodes.ContainsKey(item.Text))
                    {
                        FoundTexture = true;

                        FTEX   tex         = (FTEX)ftexCont.ResourceNodes[item.Text];
                        var    renderedTex = tex.RenderableTex;
                        Bitmap temp        = tex.GetBitmap();

                        textureImageList.Images.Add(tex.Text, temp);

                        item.ImageIndex = CurTex++;

                        var dummy = textureImageList.Handle;
                        temp.Dispose();
                    }
                }
                if (FoundTexture == false)
                {
                    AddBlankTexture(item, item.Text, CurTex++);
                }
            }
        }
Пример #30
0
        public static void ReadShaderParams(XmlDocument doc, XmlNode parentNode, FMAT mat)
        {
            mat.matparam.Clear();
            foreach (XmlNode node in parentNode.ChildNodes)
            {
                string           Value = node.Attributes[0].Value;
                BfresShaderParam param = new BfresShaderParam();
                param.Name = node.Name;
                Console.WriteLine(node.Name);

                foreach (XmlAttribute att in node.Attributes)
                {
                    Console.WriteLine(att);

                    if (att.Name == "Format")
                    {
                        string Format = att.Value;

                        ShaderParamType type;
                        if (Enum.TryParse(Format, out type))
                        {
                            param.Type = type;
                            switch (type)
                            {
                            case ShaderParamType.Bool:
                            case ShaderParamType.Bool2:
                            case ShaderParamType.Bool3:
                            case ShaderParamType.Bool4:
                                param.ValueBool = Array.ConvertAll(Value.Split(','), bool.Parse);
                                break;

                            case ShaderParamType.Float:
                            case ShaderParamType.Float2:
                            case ShaderParamType.Float3:
                            case ShaderParamType.Float4:
                            case ShaderParamType.Float2x2:
                            case ShaderParamType.Float2x3:
                            case ShaderParamType.Float2x4:
                            case ShaderParamType.Float3x2:
                            case ShaderParamType.Float3x3:
                            case ShaderParamType.Float3x4:
                            case ShaderParamType.Float4x2:
                            case ShaderParamType.Float4x3:
                            case ShaderParamType.Float4x4:
                                param.ValueFloat = Array.ConvertAll(Value.Split(','), float.Parse);
                                break;

                            case ShaderParamType.Int:
                            case ShaderParamType.Int2:
                            case ShaderParamType.Int3:
                            case ShaderParamType.Int4:
                                param.ValueInt = Array.ConvertAll(Value.Split(','), int.Parse);
                                break;

                            case ShaderParamType.Reserved2:
                            case ShaderParamType.Reserved3:
                            case ShaderParamType.Reserved4:
                                param.ValueReserved = Array.ConvertAll(Value.Split(','), byte.Parse);
                                break;

                            case ShaderParamType.Srt2D:
                                param.ValueSrt2D = SetSrt2D(node);
                                break;

                            case ShaderParamType.Srt3D:
                                param.ValueSrt3D = SetSrt3D(node);
                                break;

                            case ShaderParamType.TexSrt:
                                param.ValueTexSrt = SetTexSRT(node);
                                break;

                            case ShaderParamType.TexSrtEx:
                                param.ValueTexSrtEx = SetTexSRTEx(node);
                                break;

                            case ShaderParamType.UInt:
                            case ShaderParamType.UInt2:
                            case ShaderParamType.UInt3:
                            case ShaderParamType.UInt4:
                                param.ValueUint = Array.ConvertAll(Value.Split(','), uint.Parse);
                                break;
                            }
                        }
                    }
                }

                mat.matparam.Add(param.Name, param);
            }
        }