Ejemplo n.º 1
0
        public virtual void SetBlendState(FMAT material)
        {
            var blend = material.BlendState;

            blend.RenderDepthTest();

            if (blend.State == GLMaterialBlendState.BlendState.Opaque)
            {
                GL.Disable(EnableCap.AlphaTest);
                GL.Disable(EnableCap.Blend);
                return;
            }

            blend.RenderBlendState();
        }
Ejemplo n.º 2
0
 public override bool UseRenderer(FMAT material, string archive, string model)
 {
     return(archive == "RenderMaterial" ||
            archive == "RenderMaterialAlphaMask" ||
            archive == "RenderMaterialGrass" ||
            archive == "RenderMaterialCloud" ||
            archive == "RenderMaterialCrystal" ||
            archive == "RenderMaterialEcho" ||
            archive == "RenderMaterialEmission" ||
            archive == "RenderMaterialGodRay" ||
            archive == "RenderMaterialIndirect" ||
            archive == "RenderMaterialMirror" ||
            archive == "RenderMaterialNoiseSpecular" ||
            archive == "RenderMaterialMultiTex");
 }
 public static string[] FindRenderInfoPresets(FMAT material, string targetInfoName)
 {
     foreach (var info in InfoItemDump)
     {
         //Check for shader mapping
         if (!info.ShaderTarget.Contains(material.ShaderArchive) &&
             !info.ShaderTarget.Contains(material.ShaderModel))
         {
             continue;
         }
         //Find the enum with the current info target
         return(FindEnums(info.GetType(), targetInfoName));
     }
     //Default to the entry defaults with common render info values.
     return(FindEnums(typeof(DefaultEntry), targetInfoName));
 }
Ejemplo n.º 4
0
        private void ParseSamplerTrack(FMAT material, SamplerTrack track)
        {
            if (TextureList.Count == 0)
            {
                return;
            }

            if (material.AnimatedSamplers.ContainsKey(track.Sampler))
            {
                material.AnimatedSamplers.Remove(track.Sampler);
            }

            var value   = (int)track.GetFrameValue(this.Frame);
            var texture = TextureList[value];

            material.AnimatedSamplers.Add(track.Sampler, texture);
        }
        public static void Render(FMAT material)
        {
            RenderHeader();

            if (ImGui.BeginChild("RENDER_INFO_LIST"))
            {
                int index = 0;
                foreach (var renderInfo in material.Material.RenderInfos.Values)
                {
                    ImGui.Columns(2);
                    if (ImGui.Selectable(renderInfo.Name, SelectedIndices.Contains(index)))
                    {
                        SelectedIndices.Clear();
                        SelectedIndices.Add(index);
                    }
                    ImGui.NextColumn();
                    ImGui.Text(GetDataString(renderInfo, ","));
                    ImGui.NextColumn();

                    if (dialogOpen && SelectedIndices.Contains(index))
                    {
                        ActiveDialog.LoadDialog(renderInfo, dialogOpen, (o, e) =>
                        {
                            material.UpdateRenderState();
                            foreach (FSHP mesh in material.GetMappedMeshes())
                            {
                                mesh.ReloadShader();
                            }
                        });
                    }

                    if (SelectedIndices.Contains(index) && ImGui.IsMouseDoubleClicked(0))
                    {
                        dialogOpen = true;
                        ActiveDialog.OnLoad(material, renderInfo);
                        ImGui.OpenPopup("##render_info_dialog");
                    }

                    index++;

                    ImGui.Columns(1);
                }
            }
            ImGui.EndChild();
        }
        static void SelectSampler(FMAT material, UVViewport UVViewport, int index, bool onLoad)
        {
            var materialData = material.Material;

            var sampler   = materialData.Samplers[index].TexSampler;
            var texMapSel = materialData.TextureRefs[index];

            //Texture map info
            if (ImGui.CollapsingHeader("Texture Info", ImGuiTreeNodeFlags.DefaultOpen))
            {
                ImGuiHelper.InputFromText("Name", texMapSel, "Name", 200);
            }

            var width = ImGui.GetWindowWidth();

            //A UV preview window drawn using opengl
            if (ImGui.CollapsingHeader("Preview", ImGuiTreeNodeFlags.DefaultOpen))
            {
                if (ImGui.BeginChild("uv_viewport1", new Vector2(width, 150)))
                {
                    if (onLoad)
                    {
                        var meshes = material.GetMappedMeshes();

                        UVViewport.ActiveObjects.Clear();
                        foreach (FSHP mesh in meshes)
                        {
                            UVViewport.ActiveObjects.Add(mesh);
                        }
                    }

                    UVViewport.ActiveTextureMap = material.TextureMaps[index];
                    UVViewport.Render((int)width, 150);
                }
                ImGui.EndChild();
            }

            if (ImGui.BeginChild("sampler_properties"))
            {
                LoadProperties(sampler);
                material.ReloadTextureMap(index);
                ImGui.EndChild();
            }
        }
Ejemplo n.º 7
0
        private void ParseAnimationTrack(STAnimGroup group, FMAT mat)
        {
            foreach (var track in group.GetTracks())
            {
                if (track is SamplerTrack)
                {
                    ParseSamplerTrack(mat, (SamplerTrack)track);
                }
                if (track is ParamTrack)
                {
                    ParseParamTrack(mat, group, (ParamTrack)track);
                }
            }

            foreach (var subGroup in group.SubAnimGroups)
            {
                ParseAnimationTrack(subGroup, mat);
            }
        }
Ejemplo n.º 8
0
        public virtual void SetRenderState(FMAT mat)
        {
            GL.Enable(EnableCap.CullFace);

            if (mat.CullFront && mat.CullBack)
            {
                GL.CullFace(CullFaceMode.FrontAndBack);
            }
            else if (mat.CullFront)
            {
                GL.CullFace(CullFaceMode.Front);
            }
            else if (mat.CullBack)
            {
                GL.CullFace(CullFaceMode.Back);
            }
            else
            {
                GL.Disable(EnableCap.CullFace);
            }
        }
Ejemplo n.º 9
0
        private NodeBase CreateGroupHierachy(FMAT material, STAnimGroup group)
        {
            if (group is ParamAnimGroup)
            {
                return(CreateParamNodeHierachy(material, (ParamAnimGroup)group));
            }

            var groupNode = new NodeBase(group.Name);

            groupNode.Tag = group;

            //Params have their own sub group for each parameter
            //The X, Y, Z values being individual tracks
            foreach (STAnimGroup subGroup in group.SubAnimGroups)
            {
                groupNode.AddChild(CreateGroupHierachy(material, subGroup));
            }

            var tracks = group.GetTracks();

            return(groupNode);
        }
Ejemplo n.º 10
0
 static void RenderHeader(FMAT material)
 {
     ImGui.Columns(2);
     if (ImGui.Selectable("Name"))
     {
         LoadedOptions.Clear();
         foreach (var op in material.ShaderOptions.OrderBy(x => x.Key))
         {
             LoadedOptions.Add(op.Key, op.Value);
         }
     }
     ImGui.NextColumn();
     if (ImGui.Selectable("Value"))
     {
         LoadedOptions.Clear();
         foreach (var op in material.ShaderOptions.OrderBy(x => x.Value))
         {
             LoadedOptions.Add(op.Key, op.Value);
         }
     }
     ImGui.Separator();
     ImGui.Columns(1);
 }
        /// <summary>
        /// A helper method to set a material parameter block layout.
        /// </summary>
        public virtual void SetMaterialBlock(FMAT mat, UniformBlock block)
        {
            //Fill the buffer by program offsets
            var mem = new System.IO.MemoryStream();

            using (var writer = new Toolbox.Core.IO.FileWriter(mem))
            {
                writer.SeekBegin(0);
                var matBlock = ShaderModel.UniformBlocks.Values.FirstOrDefault(x =>
                                                                               x.Type == BfshaLibrary.UniformBlock.BlockType.Material);

                int index = 0;
                foreach (var param in matBlock.Uniforms.Values)
                {
                    var uniformName = matBlock.Uniforms.GetKey(index++);

                    writer.SeekBegin(param.Offset - 1);
                    if (mat.ShaderParams.ContainsKey(uniformName))
                    {
                        var matParam = mat.ShaderParams[uniformName];
                        if (mat.AnimatedParams.ContainsKey(uniformName))
                        {
                            matParam = mat.AnimatedParams[uniformName];
                        }

                        if (matParam.Type == BfresLibrary.ShaderParamType.TexSrtEx) //Texture matrix (texmtx)
                        {
                            writer.Write(CalculateSRT3x4((BfresLibrary.TexSrt)matParam.DataValue));
                        }
                        else if (matParam.Type == BfresLibrary.ShaderParamType.TexSrt)
                        {
                            writer.Write(CalculateSRT2x3((BfresLibrary.TexSrt)matParam.DataValue));
                        }
                        else if (matParam.DataValue is BfresLibrary.Srt2D) //Indirect SRT (ind_texmtx)
                        {
                            writer.Write(CalculateSRT((BfresLibrary.Srt2D)matParam.DataValue));
                        }
                        else if (matParam.DataValue is float)
                        {
                            writer.Write((float)matParam.DataValue);
                        }
                        else if (matParam.DataValue is float[])
                        {
                            writer.Write((float[])matParam.DataValue);
                        }
                        else if (matParam.DataValue is int[])
                        {
                            writer.Write((int[])matParam.DataValue);
                        }
                        else if (matParam.DataValue is uint[])
                        {
                            writer.Write((uint[])matParam.DataValue);
                        }
                        else if (matParam.DataValue is int)
                        {
                            writer.Write((int)matParam.DataValue);
                        }
                        else if (matParam.DataValue is uint)
                        {
                            writer.Write((uint)matParam.DataValue);
                        }
                        else
                        {
                            throw new Exception($"Unsupported render type! {matParam.Type}");
                        }
                    }
                }
            }

            block.Buffer.Clear();
            block.Buffer.AddRange(mem.ToArray());
        }
 /// <summary>
 /// A helper method to auto map commonly used render info settings to options.
 /// Not all games use the same render info settings so this only works for certain games!
 /// </summary>
 public virtual void LoadRenderStateOptions(Dictionary <string, string> options, FMAT mat)
 {
     ShaderOptionHelper.LoadRenderStateOptions(options, mat);
 }
Ejemplo n.º 13
0
        static void LoadShaderInfo(FMAT material)
        {
            var shader  = material.MaterialAsset as SharcFBRenderer;
            var program = shader.ShaderModel;

            if (selectedStage == "Vertex")
            {
                var gx2Shader = (GX2VertexShader)program.GetGX2VertexShader(shader.BinaryIndex);

                if (ImGui.CollapsingHeader("Attributes", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < gx2Shader.Attributes.Count; i++)
                    {
                        ImGui.Text($"In {gx2Shader.Attributes[i].Name} Location {gx2Shader.Attributes[i].Location} Location {gx2Shader.Attributes[i].Type}");
                    }
                }

                if (ImGui.CollapsingHeader("Uniform Blocks", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < gx2Shader.UniformBlocks.Count; i++)
                    {
                        if (ImGui.CollapsingHeader($"Uniforms##{i}"))
                        {
                            ImGui.Text($"{gx2Shader.UniformBlocks[i].Name} Location {gx2Shader.UniformBlocks[i].Offset}");

                            var uniforms = gx2Shader.Uniforms.OrderBy(x => x.Offset).ToList();
                            for (int j = 0; j < uniforms.Count; j++)
                            {
                                if (uniforms[j].BlockIndex == i)
                                {
                                    ImGui.Text($"{uniforms[j].Name} Type {uniforms[j].Type} offset {uniforms[j].Offset}");
                                }
                            }
                        }
                    }
                }

                if (ImGui.CollapsingHeader("SHARCFB Attributes", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < program.AttributeVariables.symbols.Count; i++)
                    {
                        var symbol = program.AttributeVariables.symbols[i];
                        ImGui.Text($"Name {symbol.Name} Symbol { symbol.SymbolName} Usage: { symbol.flags[shader.VariationBaseIndex]}");
                    }
                }

                if (ImGui.CollapsingHeader("SHARCFB Uniform Blocks", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < program.UniformBlocks.symbols.Count; i++)
                    {
                        ImGui.Text($"Name {program.UniformBlocks.symbols[i].Name} Symbol { program.UniformBlocks.symbols[i].SymbolName}");
                    }
                }
            }
            if (selectedStage == "Pixel")
            {
                var gx2Shader = (GX2PixelShader)program.GetGX2PixelShader(shader.BinaryIndex);

                if (ImGui.CollapsingHeader("Uniform Blocks", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < gx2Shader.UniformBlocks.Count; i++)
                    {
                        ImGui.Text($"{gx2Shader.UniformBlocks[i].Name} Location {gx2Shader.UniformBlocks[i].Offset}");

                        if (ImGui.CollapsingHeader($"Uniforms##{i}"))
                        {
                            var uniforms = gx2Shader.Uniforms.OrderBy(x => x.Offset).ToList();
                            for (int j = 0; j < uniforms.Count; j++)
                            {
                                if (uniforms[j].BlockIndex == i)
                                {
                                    ImGui.Text($"{uniforms[j].Name} Type {uniforms[j].Type} offset {uniforms[j].Offset}");
                                }
                            }
                        }
                    }
                }

                if (ImGui.CollapsingHeader("Samplers", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < gx2Shader.Samplers.Count; i++)
                    {
                        ImGui.Text($"{gx2Shader.Samplers[i].Name} Location {gx2Shader.Samplers[i].Location} Type {gx2Shader.Samplers[i].Type}");
                    }
                }

                if (ImGui.CollapsingHeader("SHARCFB Samplers", ImGuiTreeNodeFlags.DefaultOpen))
                {
                    for (int i = 0; i < program.SamplerVariables.symbols.Count; i++)
                    {
                        ImGui.Text($"{program.SamplerVariables.symbols[i].Name} Symbol {program.SamplerVariables.symbols[i].SymbolName}");
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void LoadEditorMenus(FMAT material)
        {
            if (UVViewport == null)
            {
                Init();
            }

            if (activeMaterial != material)
            {
                onLoad = true;
                MaterialParameter.Reset();
                MaterialOptions.Reset();
                BfresTextureMapEditor.Reset();
                UVViewport.Reset();
            }

            activeMaterial = material;

            if (ImGui.CollapsingHeader("Material Info", ImGuiTreeNodeFlags.DefaultOpen))
            {
                ImGuiHelper.InputFromText("Name", material, "Name", 200);
                ImGuiHelper.InputFromText("ShaderArchive", material, "ShaderArchive", 200);
                ImGuiHelper.InputFromText("ShaderModel", material, "ShaderModel", 200);
                ImGuiHelper.InputFromBoolean("Visible", material.Material, "Visible");
            }

            if (ImGui.BeginChild("##MATERIAL_EDITOR"))
            {
                ImGui.BeginTabBar("Menu1");

                if (ImguiCustomWidgets.BeginTab("Menu1", "Texture Maps"))
                {
                    BfresTextureMapEditor.Render(material, UVViewport, onLoad);
                    ImGui.EndTabItem();
                }

                if (ImguiCustomWidgets.BeginTab("Menu1", "Parameters"))
                {
                    MaterialParameter.Render(material);
                    ImGui.EndTabItem();
                }
                if (ImguiCustomWidgets.BeginTab("Menu1", "Render Info"))
                {
                    RenderInfoEditor.Render(material);
                    ImGui.EndTabItem();
                }
                if (ImguiCustomWidgets.BeginTab("Menu1", "Options"))
                {
                    MaterialOptions.Render(material);
                    ImGui.EndTabItem();
                }

                if (!material.ParentFile.ResFile.IsPlatformSwitch)
                {
                    if (ImguiCustomWidgets.BeginTab("Menu1", "Render State"))
                    {
                        RenderStateEditor.Render(material);
                        ImGui.EndTabItem();
                    }
                }

                if (ImguiCustomWidgets.BeginTab("Menu1", "User Data"))
                {
                    UserDataInfoEditor.Render(material.Material.UserData);
                    ImGui.EndTabItem();
                }

                if (material.MaterialAsset is BfshaRenderer)
                {
                    if (ImguiCustomWidgets.BeginTab("Menu1", "Shader Data"))
                    {
                        BfshaShaderProgramViewer.Render(material);
                        ImGui.EndTabItem();
                    }
                }
                else if (material.MaterialAsset is SharcFBRenderer)
                {
                    if (ImguiCustomWidgets.BeginTab("Menu1", "Shader Data"))
                    {
                        SharcFBShaderProgramViewer.Render(material);
                        ImGui.EndTabItem();
                    }
                }


                if (material.MaterialAsset is KSANXRender)
                {
                    if (ImguiCustomWidgets.BeginTab("Menu1", "Lighting Data"))
                    {
                        ((KSANXRender)material.MaterialAsset).RenderUI();
                        ImGui.EndTabItem();
                    }
                }

                ImGui.EndTabBar();
            }
            ImGui.EndChild();

            onLoad = false;
        }
Ejemplo n.º 15
0
 public void LoadEditor(FMAT material)
 {
     LoadEditorMenus(material);
 }
Ejemplo n.º 16
0
 public override bool UseRenderer(FMAT material, string archive, string model)
 {
     return(archive == "alRenderMaterial");
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Determines when to use this renderer for the given material.
 /// This is typically done from the shader archive or shader model name.
 /// The material can also be used for shader specific render information to check.
 /// </summary>
 /// <returns></returns>
 public virtual bool UseRenderer(FMAT material, string archive, string model)
 {
     return(false);
 }
Ejemplo n.º 18
0
        public static void Render(FMAT material)
        {
            if (LoadedOptions.Count == 0)
            {
                foreach (var op in material.ShaderOptions)
                {
                    LoadedOptions.Add(op.Key, op.Value);
                }
            }

            bool isValid = true;

            var meshes = material.GetMappedMeshes();

            foreach (FSHP mesh in meshes)
            {
                if (!mesh.HasValidShader)
                {
                    isValid = false;
                }
            }

            if (!isValid)
            {
                ImGui.TextColored(new System.Numerics.Vector4(1f, 0, 0.0f, 1), "Invalid Option Combination!");
            }
            else
            {
                ImGui.Text("");
            }

            //ImGui.TextColored(new System.Numerics.Vector4(0.2f, 1, 0.3f, 1), "Valid Option Combination!");

            RenderHeader(material);

            if (ImGui.BeginChild("OPTION_LIST"))
            {
                ImGui.Columns(2);

                int index = 0;
                foreach (var option in LoadedOptions)
                {
                    if (SelectedIndices.Contains(index))
                    {
                        if (ImGui.CollapsingHeader(option.Key, ImGuiTreeNodeFlags.DefaultOpen))
                        {
                            string value = option.Value;
                            if (ImGui.InputText("", ref value, 100))
                            {
                                material.ShaderOptions[option.Key] = value;
                                foreach (FSHP mesh in meshes)
                                {
                                    mesh.ReloadShader();
                                }
                            }
                        }
                    }
                    else if (ImGui.Selectable(option.Key, SelectedIndices.Contains(index)))
                    {
                        SelectedIndices.Clear();
                        SelectedIndices.Add(index);
                    }
                    ImGui.NextColumn();
                    ImGui.Text(option.Value);
                    ImGui.NextColumn();
                    index++;
                }
            }
            ImGui.EndChild();

            ImGui.Columns(1);
        }
Ejemplo n.º 19
0
 public void OnLoad(FMAT material, RenderInfo renderInfo)
 {
     originalData = renderInfo.Data;
     originalName = renderInfo.Name;
     ValuePresets = RenderInfoEnums.FindRenderInfoPresets(material, renderInfo.Name).ToList();
 }
Ejemplo n.º 20
0
        static void ConvertSwitchRenderState(FMAT mat)
        {
            string blend = mat.GetRenderInfo("gsys_render_state_blend_mode");
            //Alpha test
            string alphaTest  = mat.GetRenderInfo("gsys_alpha_test_enable");
            string alphaFunc  = mat.GetRenderInfo("gsys_alpha_test_func");
            float  alphaValue = mat.GetRenderInfo("gsys_alpha_test_value");

            string colorOp  = mat.GetRenderInfo("gsys_color_blend_rgb_op");
            string colorDst = mat.GetRenderInfo("gsys_color_blend_rgb_dst_func");
            string colorSrc = mat.GetRenderInfo("gsys_color_blend_rgb_src_func");

            float[] blendColorF32 = mat.Material.RenderInfos["gsys_color_blend_const_color"].GetValueSingles();

            string alphaOp  = mat.GetRenderInfo("gsys_color_blend_alpha_op");
            string alphaDst = mat.GetRenderInfo("gsys_color_blend_alpha_dst_func");
            string alphaSrc = mat.GetRenderInfo("gsys_color_blend_alpha_src_func");

            string depthTest     = mat.GetRenderInfo("gsys_depth_test_enable");
            string depthTestFunc = mat.GetRenderInfo("gsys_depth_test_func");
            string depthWrite    = mat.GetRenderInfo("gsys_depth_test_write");
            string state         = mat.GetRenderInfo("gsys_render_state_mode");

            if (state == "opaque")
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Opaque;
            }
            else if (state == "translucent")
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Translucent;
            }
            else if (state == "mask")
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Mask;
            }
            else
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Custom;
            }

            string displayFace = mat.GetRenderInfo("gsys_render_state_display_face");

            if (displayFace == "front")
            {
                mat.CullFront = false;
                mat.CullBack  = true;
            }
            if (displayFace == "back")
            {
                mat.CullFront = true;
                mat.CullBack  = false;
            }
            if (displayFace == "both")
            {
                mat.CullFront = false;
                mat.CullBack  = false;
            }
            if (displayFace == "none")
            {
                mat.CullFront = true;
                mat.CullBack  = true;
            }

            if (!string.IsNullOrEmpty(state) && state != "opaque")
            {
                mat.IsTransparent = true;
            }

            mat.BlendState.Color      = new OpenTK.Vector4(blendColorF32[0], blendColorF32[1], blendColorF32[2], blendColorF32[3]);
            mat.BlendState.BlendColor = blend == "color";
            mat.BlendState.DepthTest  = depthTest == "true";
            mat.BlendState.DepthWrite = depthWrite == "true";
            mat.BlendState.AlphaTest  = alphaTest == "true";
            mat.BlendState.AlphaValue = alphaValue;

            if (alphaFunc == "always")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Always;
            }
            if (alphaFunc == "equal")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Equal;
            }
            if (alphaFunc == "lequal")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Lequal;
            }
            if (alphaFunc == "gequal")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Gequal;
            }
            if (alphaFunc == "less")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Less;
            }
            if (alphaFunc == "greater")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Greater;
            }
            if (alphaFunc == "never")
            {
                mat.BlendState.AlphaFunction = AlphaFunction.Never;
            }
        }
 public override bool UseRenderer(FMAT material, string archive, string model)
 {
     //Todo users may want to use multiple shader archives in a custom map.
     //May need to find a better way to detect this.
     return(archive == "Turbo_UBER");
 }
Ejemplo n.º 22
0
        private void ParseParamTrack(FMAT material, STAnimGroup group, ParamTrack track)
        {
            if (!material.ShaderParams.ContainsKey(group.Name))
            {
                return;
            }

            var value = track.GetFrameValue(this.Frame);

            //4 bytes per float or int value
            uint index = track.ValueOffset / 4;

            var targetParam = material.ShaderParams[group.Name];

            var param = new ShaderParam();

            if (!material.AnimatedParams.ContainsKey(group.Name))
            {
                if (targetParam.DataValue is float[])
                {
                    float[] values = (float[])targetParam.DataValue;
                    float[] dest   = new float[values.Length];
                    Array.Copy(values, dest, values.Length);
                    param.DataValue = dest;
                }
                else
                {
                    param.DataValue = targetParam.DataValue;
                }

                param.Type = targetParam.Type;
                param.Name = group.Name;

                material.AnimatedParams.Add(group.Name, param);
            }

            param = material.AnimatedParams[group.Name];

            switch (targetParam.Type)
            {
            case ShaderParamType.Float: param.DataValue = (float)value; break;

            case ShaderParamType.Float2:
            case ShaderParamType.Float3:
            case ShaderParamType.Float4:
                ((float[])param.DataValue)[index] = value;
                break;

            case ShaderParamType.Int: param.DataValue = value; break;

            case ShaderParamType.Int2:
            case ShaderParamType.Int3:
            case ShaderParamType.Int4:
                ((int[])param.DataValue)[index] = (int)value;
                break;

            case ShaderParamType.TexSrt:
            case ShaderParamType.TexSrtEx:
            {
                TexSrtMode mode       = ((TexSrt)param.DataValue).Mode;
                var        translateX = ((TexSrt)param.DataValue).Translation.X;
                var        translateY = ((TexSrt)param.DataValue).Translation.Y;
                var        rotate     = ((TexSrt)param.DataValue).Rotation;
                var        scaleX     = ((TexSrt)param.DataValue).Scaling.X;
                var        scaleY     = ((TexSrt)param.DataValue).Scaling.Y;

                // if (track.ValueOffset == 0) mode = (TexSrtMode)Convert.ToUInt32(value);
                if (track.ValueOffset == 4)
                {
                    scaleX = value;
                }
                if (track.ValueOffset == 8)
                {
                    scaleY = value;
                }
                if (track.ValueOffset == 12)
                {
                    rotate = value;
                }
                if (track.ValueOffset == 16)
                {
                    translateX = value;
                }
                if (track.ValueOffset == 20)
                {
                    translateY = value;
                }

                param.DataValue = new TexSrt()
                {
                    Mode        = mode,
                    Scaling     = new Syroot.Maths.Vector2F(scaleX, scaleY),
                    Translation = new Syroot.Maths.Vector2F(translateX, translateY),
                    Rotation    = rotate,
                };
            }
            break;

            case ShaderParamType.Srt2D:
            {
                var translateX = ((Srt2D)param.DataValue).Translation.X;
                var translateY = ((Srt2D)param.DataValue).Translation.Y;
                var rotate     = ((Srt2D)param.DataValue).Rotation;
                var scaleX     = ((Srt2D)param.DataValue).Scaling.X;
                var scaleY     = ((Srt2D)param.DataValue).Scaling.Y;

                if (track.ValueOffset == 0)
                {
                    scaleX = value;
                }
                if (track.ValueOffset == 4)
                {
                    scaleY = value;
                }
                if (track.ValueOffset == 8)
                {
                    rotate = value;
                }
                if (track.ValueOffset == 12)
                {
                    translateX = value;
                }
                if (track.ValueOffset == 16)
                {
                    translateY = value;
                }

                param.DataValue = new Srt2D()
                {
                    Scaling     = new Syroot.Maths.Vector2F(scaleX, scaleY),
                    Translation = new Syroot.Maths.Vector2F(translateX, translateY),
                    Rotation    = rotate,
                };
            }
            break;
            }
        }
 /// <summary>
 /// Determines when to use this renderer for the given material.
 /// This is typically done from the shader archive or shader model name.
 /// The material can also be used for shader specific render information to check.
 /// </summary>
 /// <returns></returns>
 public override bool UseRenderer(FMAT material, string archive, string model)
 {
     return(false);
 }
        public static void Render(FMAT material, UVViewport UVViewport, bool onLoad)
        {
            float width = ImGui.GetWindowWidth();

            if (ImGui.BeginChild("TEXTURE_MAP_LIST", new System.Numerics.Vector2(width, 100)))
            {
                int index = 0;
                foreach (var texMap in material.TextureMaps)
                {
                    var tex = SearchTextureInstance(texMap.Name);
                    if (tex != null)
                    {
                        if (tex.RenderableTex == null)
                        {
                            tex.LoadRenderableTexture();
                        }

                        if (tex.RenderableTex != null)
                        {
                            IconManager.LoadTexture(tex.Name, tex);
                        }
                        else
                        {
                            IconManager.LoadIcon("TEXTURE");
                        }
                    }
                    else
                    {
                        IconManager.LoadIcon("TEXTURE");
                    }
                    ImGui.SameLine();

                    if (dialogOpened && SelectedIndices.Contains(index))
                    {
                        if (TextureSelectionDialog.Render(texMap.Name, ref dialogOpened))
                        {
                            var input = TextureSelectionDialog.OutputName;
                            //Only undo matching textures, not typed names
                            if (tex != null)
                            {
                                UndoStack.Add(new UndoStringOperation($"Texture Map",
                                                                      texMap, "Name", input));
                            }

                            texMap.Name = input;
                        }
                    }
                    else
                    {
                        if (ImGui.Selectable(texMap.Name, SelectedIndices.Contains(index)))
                        {
                            SelectedIndices.Clear();
                            SelectedIndices.Add(index);
                        }
                        if (ImGui.IsItemClicked() && ImGui.IsMouseDoubleClicked(0))
                        {
                            dialogOpened = true;
                        }
                    }

                    index++;
                }
            }
            ImGui.EndChild();

            if (material.TextureMaps.Count == 0)
            {
                return;
            }

            //Make sure there is atleast 1 selection used
            if (SelectedIndices.Count == 0)
            {
                SelectedIndices.Add(0);
            }

            if (ImGui.BeginChild("SAMPLER_DATA"))
            {
                SelectSampler(material, UVViewport, SelectedIndices.FirstOrDefault(), onLoad);
            }
            ImGui.EndChild();
        }
Ejemplo n.º 25
0
        static void ConvertWiiURenderState(FMAT mat, RenderState renderState)
        {
            var alphaControl = renderState.AlphaControl;
            var depthControl = renderState.DepthControl;
            var blendControl = renderState.BlendControl;
            var blendColor   = renderState.BlendColor;

            mat.CullBack  = renderState.PolygonControl.CullBack;
            mat.CullFront = renderState.PolygonControl.CullFront;

            var mode = renderState.FlagsMode;

            if (mode == RenderStateFlagsMode.Opaque)
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Opaque;
            }
            else if (mode == RenderStateFlagsMode.Translucent)
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Translucent;
            }
            else if (mode == RenderStateFlagsMode.AlphaMask)
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Mask;
            }
            else
            {
                mat.BlendState.State = GLMaterialBlendState.BlendState.Custom;
            }

            mat.IsTransparent = mode != RenderStateFlagsMode.Opaque;

            mat.BlendState.ColorDst = (BlendingFactorDest)ConvertBlend(blendControl.ColorDestinationBlend);
            mat.BlendState.ColorSrc = (BlendingFactorSrc)ConvertBlend(blendControl.ColorSourceBlend);
            mat.BlendState.AlphaDst = (BlendingFactorDest)ConvertBlend(blendControl.AlphaDestinationBlend);
            mat.BlendState.AlphaSrc = (BlendingFactorSrc)ConvertBlend(blendControl.AlphaSourceBlend);
            mat.BlendState.AlphaOp  = ConvertOp(blendControl.AlphaCombine);
            mat.BlendState.ColorOp  = ConvertOp(blendControl.ColorCombine);

            mat.BlendState.Color      = new OpenTK.Vector4(blendColor[0], blendColor[1], blendColor[2], blendColor[3]);
            mat.BlendState.DepthTest  = depthControl.DepthTestEnabled;
            mat.BlendState.DepthWrite = depthControl.DepthWriteEnabled;
            mat.BlendState.AlphaTest  = alphaControl.AlphaTestEnabled;
            mat.BlendState.AlphaValue = renderState.AlphaRefValue;
            mat.BlendState.BlendMask  = renderState.ColorControl.BlendEnableMask == 1;
            //Todo the blend state flags seem off? This works for now.
            mat.BlendState.BlendColor = renderState.FlagsBlendMode != RenderStateFlagsBlendMode.None;
            switch (alphaControl.AlphaFunc)
            {
            case GX2CompareFunction.Always:
                mat.BlendState.AlphaFunction = AlphaFunction.Always;
                break;

            case GX2CompareFunction.Greater:
                mat.BlendState.AlphaFunction = AlphaFunction.Greater;
                break;

            case GX2CompareFunction.GreaterOrEqual:
                mat.BlendState.AlphaFunction = AlphaFunction.Gequal;
                break;

            case GX2CompareFunction.Equal:
                mat.BlendState.AlphaFunction = AlphaFunction.Equal;
                break;

            case GX2CompareFunction.LessOrEqual:
                mat.BlendState.AlphaFunction = AlphaFunction.Lequal;
                break;

            case GX2CompareFunction.NotEqual:
                mat.BlendState.AlphaFunction = AlphaFunction.Notequal;
                break;

            case GX2CompareFunction.Never:
                mat.BlendState.AlphaFunction = AlphaFunction.Never;
                break;
            }
        }
Ejemplo n.º 26
0
        private NodeBase CreateParamNodeHierachy(FMAT material, ParamAnimGroup group)
        {
            var groupNode = new NodeBase(group.Name);

            groupNode.Tag = group;
            var tracks = group.GetTracks();

            if (material != null)
            {
                List <ParamTrack> paramTracks = new List <ParamTrack>();

                var param = material.ShaderParams[group.Name];
                switch (param.Type)
                {
                case ShaderParamType.TexSrt:
                case ShaderParamType.TexSrtEx:
                    var texSrt = ((TexSrt)param.DataValue);
                    paramTracks.Add(new ParamTrack(0, (float)texSrt.Mode, "Mode"));
                    paramTracks.Add(new ParamTrack(4, (float)texSrt.Scaling.X, "Scale.X"));
                    paramTracks.Add(new ParamTrack(8, (float)texSrt.Scaling.Y, "Scale.Y"));
                    paramTracks.Add(new ParamTrack(12, (float)texSrt.Rotation, "Rotate"));
                    paramTracks.Add(new ParamTrack(16, (float)texSrt.Translation.X, "Position.X"));
                    paramTracks.Add(new ParamTrack(20, (float)texSrt.Translation.Y, "Position.X"));
                    break;

                case ShaderParamType.Float:
                    paramTracks.Add(new ParamTrack(0, (float)param.DataValue, "Value"));
                    break;

                case ShaderParamType.Float2:
                case ShaderParamType.Float3:
                case ShaderParamType.Float4:
                    var      values  = ((float[])param.DataValue);
                    string[] channel = new string[4] {
                        "X", "Y", "Z", "W"
                    };
                    for (int i = 0; i < values.Length; i++)
                    {
                        paramTracks.Add(new ParamTrack((uint)i * 4, values[i], channel[i]));
                    }
                    break;
                }

                for (int i = 0; i < paramTracks.Count; i++)
                {
                    var targetTrack = group.Tracks.FirstOrDefault(x => ((ParamTrack)x).ValueOffset == paramTracks[i].ValueOffset);
                    if (targetTrack == null)
                    {
                        group.Tracks.Add(paramTracks[i]);
                    }
                    else
                    {
                        targetTrack.Name = paramTracks[i].Name;
                    }
                }
            }

            foreach (ParamTrack track in group.Tracks.OrderBy(x => ((ParamTrack)x).ValueOffset))
            {
                track.ChannelIndex = ((int)track.ValueOffset / 4);

                var trackNode = new NodeBase(track.Name);
                trackNode.Tag = track;
                groupNode.AddChild(trackNode);
            }

            return(groupNode);
        }
Ejemplo n.º 27
0
 private void SetUniforms(ShaderProgram shader, FMAT mat)
 {
 }
 public override bool UseRenderer(FMAT material, string archive, string model)
 {
     return(archive == "Blitz_UBER");
 }
Ejemplo n.º 29
0
 public override bool UseRenderer(FMAT material, string archive, string model)
 {
     return(material.Material.RenderInfos.ContainsKey("shadingModel"));
 }
Ejemplo n.º 30
0
 public void DragDroppedOnEnter()
 {
     beforeDroppedMaterial = this.Material;
 }