Ejemplo n.º 1
0
        public static void SetMaterials(BxlytShader shader, BCLYT.Material material, BasePane pane, Dictionary <string, STGenericTexture> textures)
        {
            Matrix4 rotationX      = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pane.Rotate.X));
            Matrix4 rotationY      = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(pane.Rotate.Y));
            Matrix4 rotationZ      = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(pane.Rotate.Z));
            var     rotationMatrix = rotationX * rotationY * rotationZ;

            shader.SetMatrix("rotationMatrix", ref rotationMatrix);

            shader.SetColor("whiteColor", material.TevConstantColors[0].Color);
            shader.SetColor("blackColor", material.TevColor.Color);
            shader.SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
            shader.SetInt("numTextureMaps", material.TextureMaps.Length);
            shader.SetVec2("uvScale0", new Vector2(1, 1));
            shader.SetFloat("uvRotate0", 0);
            shader.SetVec2("uvTranslate0", new Vector2(0, 0));
            shader.SetInt("flipTexture", 0);
            shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
            shader.SetInt($"texCoords0GenType", 0);
            shader.SetInt($"texCoords0Source", 0);

            BindTextureUniforms(shader, material);

            string textureMap0 = "";

            if (material.TextureMaps.Length > 0)
            {
                textureMap0 = material.GetTexture(0);
            }

            if (textures.ContainsKey(textureMap0))
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                shader.SetInt("textures0", 0);
                bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[0], textures[textureMap0]);
                if (isBinded)
                {
                    shader.SetInt("hasTexture0", 1);
                }
            }

            if (material.TextureTransforms.Length > 0)
            {
                var transform = material.TextureTransforms[0];
                shader.SetVec2("uvScale0", new Vector2(transform.Scale.X, transform.Scale.Y));
                shader.SetFloat("uvRotate0", transform.Rotate);
                shader.SetVec2("uvTranslate0", new Vector2(transform.Translate.X, transform.Translate.Y));
            }
        }
Ejemplo n.º 2
0
        public static void SetMaterials(BxlytShader shader, BFLYT.Material material, BasePane pane, Dictionary <string, STGenericTexture> textures)
        {
            var rotationMatrix = pane.GetRotationMatrix();

            shader.SetMatrix("rotationMatrix", ref rotationMatrix);

            STColor8 WhiteColor = material.WhiteColor;
            STColor8 BlackColor = material.BlackColor;

            foreach (var animItem in material.animController.MaterialColors)
            {
                switch (animItem.Key)
                {
                case LMCTarget.WhiteColorRed:
                    WhiteColor.R = (byte)animItem.Value; break;

                case LMCTarget.WhiteColorGreen:
                    WhiteColor.G = (byte)animItem.Value; break;

                case LMCTarget.WhiteColorBlue:
                    WhiteColor.B = (byte)animItem.Value; break;

                case LMCTarget.WhiteColorAlpha:
                    WhiteColor.A = (byte)animItem.Value; break;

                case LMCTarget.BlackColorRed:
                    BlackColor.R = (byte)animItem.Value; break;

                case LMCTarget.BlackColorGreen:
                    BlackColor.G = (byte)animItem.Value; break;

                case LMCTarget.BlackColorBlue:
                    BlackColor.B = (byte)animItem.Value; break;

                case LMCTarget.BlackColorAlpha:
                    BlackColor.A = (byte)animItem.Value; break;
                }
            }

            shader.SetColor("whiteColor", WhiteColor.Color);
            shader.SetColor("blackColor", BlackColor.Color);
            shader.SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
            shader.SetInt("numTextureMaps", material.TextureMaps.Length);
            shader.SetVec2("uvScale0", new Vector2(1, 1));
            shader.SetFloat("uvRotate0", 0);
            shader.SetVec2("uvTranslate0", new Vector2(0, 0));
            shader.SetInt("flipTexture", 0);
            shader.SetInt("numTevStages", material.TevStages.Length);
            shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
            shader.SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0));
            shader.SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0));
            shader.SetInt("tevTexMode", 0);
            shader.SetInt($"texCoords0GenType", 0);
            shader.SetInt($"texCoords0Source", 0);
            shader.SetInt("hasTexture0", 0);
            shader.SetInt("hasTexture1", 0);
            shader.SetInt("hasTexture2", 0);
            shader.SetInt("textures0", 0);
            shader.SetInt("textures1", 0);
            shader.SetInt("textures2", 0);

            BindTextureUniforms(shader, material);

            if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern)
            {
                GL.Enable(EnableCap.Texture2D);
            }

            int id = 1;

            for (int i = 0; i < material.TextureMaps.Length; i++)
            {
                string TexName = material.TextureMaps[i].Name;

                if (material.animController.TexturePatterns.ContainsKey((LTPTarget)i))
                {
                    TexName = material.animController.TexturePatterns[(LTPTarget)i];
                }

                if (textures.ContainsKey(TexName))
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    shader.SetInt($"textures{i}", id);
                    bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[TexName]);
                    if (isBinded)
                    {
                        shader.SetInt($"hasTexture{i}", 1);
                    }

                    id++;
                }
            }

            for (int i = 0; i < material.TexCoords?.Length; i++)
            {
                shader.SetInt($"texCoords{i}GenType", (int)material.TexCoords[i].GenType);
                shader.SetInt($"texCoords{i}Source", (int)material.TexCoords[i].Source);
            }

            for (int i = 0; i < material.TevStages?.Length; i++)
            {
                shader.SetInt($"tevStage{i}RGB", (int)material.TevStages[i].ColorMode);
                shader.SetInt($"tevStage{i}A", (int)material.TevStages[i].AlphaMode);
            }

            if (material.TextureTransforms.Length > 0)
            {
                var transform = material.TextureTransforms[0];
                var scale     = transform.Scale;
                var rotate    = transform.Rotate;
                var translate = transform.Translate;

                foreach (var animItem in material.animController.TextureSRTS)
                {
                    switch (animItem.Key)
                    {
                    case LTSTarget.ScaleS: scale.X = animItem.Value; break;

                    case LTSTarget.ScaleT: scale.Y = animItem.Value; break;

                    case LTSTarget.Rotate: rotate = animItem.Value; break;

                    case LTSTarget.TranslateS: translate.X = animItem.Value; break;

                    case LTSTarget.TranslateT: translate.Y = animItem.Value; break;
                    }
                }

                shader.SetVec2("uvScale0", new Vector2(scale.X, scale.Y));
                shader.SetFloat("uvRotate0", rotate);
                shader.SetVec2("uvTranslate0", new Vector2(translate.X, translate.Y));
            }


            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Always, 0f);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.Disable(EnableCap.ColorLogicOp);
            GL.LogicOp(LogicOp.Noop);

            if (material.BlendMode != null && material.EnableBlend)
            {
                var srcFactor  = BxlytToGL.ConvertBlendFactor(material.BlendMode.SourceFactor);
                var destFactor = BxlytToGL.ConvertBlendFactor(material.BlendMode.DestFactor);
                var blendOp    = BxlytToGL.ConvertBlendOperation(material.BlendMode.BlendOp);
                var logicOp    = BxlytToGL.ConvertLogicOperation(material.BlendMode.LogicOp);
                if (logicOp != LogicOp.Noop)
                {
                    GL.Enable(EnableCap.ColorLogicOp);
                }

                GL.BlendFunc(srcFactor, destFactor);
                GL.BlendEquation(blendOp);
                GL.LogicOp(logicOp);
            }
            if (material.BlendModeLogic != null && material.EnableBlendLogic)
            {
                var srcFactor  = BxlytToGL.ConvertBlendFactor(material.BlendModeLogic.SourceFactor);
                var destFactor = BxlytToGL.ConvertBlendFactor(material.BlendModeLogic.DestFactor);
                var blendOp    = BxlytToGL.ConvertBlendOperation(material.BlendModeLogic.BlendOp);
                var logicOp    = BxlytToGL.ConvertLogicOperation(material.BlendModeLogic.LogicOp);
                if (logicOp != LogicOp.Noop)
                {
                    GL.Enable(EnableCap.ColorLogicOp);
                }

                GL.BlendFunc(srcFactor, destFactor);
                GL.BlendEquation(blendOp);
                GL.LogicOp(logicOp);
            }

            if (material.AlphaCompare != null && material.EnableAlphaCompare)
            {
                var alphaFunc = BxlytToGL.ConvertAlphaFunc(material.AlphaCompare.CompareMode);
                GL.AlphaFunc(alphaFunc, material.AlphaCompare.Value);
            }
        }
Ejemplo n.º 3
0
        private static void BindTextureUniforms(BxlytShader shader, BxlytMaterial material)
        {
            //Do uv test pattern
            GL.ActiveTexture(TextureUnit.Texture10);
            GL.Uniform1(GL.GetUniformLocation(shader.program, "uvTestPattern"), 10);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID);

            if (material.TextureMaps.Length > 0)
            {
                var tex = material.TextureMaps[0];
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, BxlytToGL.ConvertTextureWrap(tex.WrapModeU));
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, BxlytToGL.ConvertTextureWrap(tex.WrapModeV));
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, BxlytToGL.ConvertMagFilterMode(tex.MaxFilterMode));
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, BxlytToGL.ConvertMinFilterMode(tex.MinFilterMode));
            }
            else
            {
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureParameterName.ClampToEdge);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureParameterName.ClampToEdge);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            }
        }
Ejemplo n.º 4
0
        public static void SetMaterials(BxlytShader shader, BRLYT.Material material, BasePane pane, Dictionary <string, STGenericTexture> textures)
        {
            var paneRotate = pane.Rotate;

            if (pane.animController.PaneSRT?.Count > 0)
            {
                foreach (var animItem in pane.animController.PaneSRT)
                {
                    switch (animItem.Key)
                    {
                    case LPATarget.RotateX:
                        paneRotate.X = animItem.Value; break;

                    case LPATarget.RotateY:
                        paneRotate.Y = animItem.Value; break;

                    case LPATarget.RotateZ:
                        paneRotate.Z = animItem.Value; break;
                    }
                }
            }

            Matrix4 rotationX      = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(paneRotate.X));
            Matrix4 rotationY      = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(paneRotate.Y));
            Matrix4 rotationZ      = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(paneRotate.Z));
            var     rotationMatrix = rotationX * rotationY * rotationZ;

            shader.SetMatrix("rotationMatrix", ref rotationMatrix);

            var WhiteColor = material.WhiteColor;
            var BlackColor = material.BlackColor;

            foreach (var animItem in material.animController.MaterialColors)
            {
                switch (animItem.Key)
                {
                case LMCTarget.WhiteColorRed:
                    WhiteColor.R = (byte)animItem.Value; break;

                case LMCTarget.WhiteColorGreen:
                    WhiteColor.G = (byte)animItem.Value; break;

                case LMCTarget.WhiteColorBlue:
                    WhiteColor.B = (byte)animItem.Value; break;

                case LMCTarget.WhiteColorAlpha:
                    WhiteColor.A = (byte)animItem.Value; break;

                case LMCTarget.BlackColorRed:
                    BlackColor.R = (byte)animItem.Value; break;

                case LMCTarget.BlackColorGreen:
                    BlackColor.G = (byte)animItem.Value; break;

                case LMCTarget.BlackColorBlue:
                    BlackColor.B = (byte)animItem.Value; break;

                case LMCTarget.BlackColorAlpha:
                    BlackColor.A = (byte)animItem.Value; break;
                }
            }

            shader.SetColor("whiteColor", Color.FromArgb(255, WhiteColor.R, WhiteColor.G, WhiteColor.B));
            shader.SetColor("blackColor", BlackColor.Color);
            shader.SetInt("debugShading", (int)Runtime.LayoutEditor.Shading);
            shader.SetInt("numTextureMaps", material.TextureMaps.Length);
            shader.SetVec2("uvScale0", new Vector2(1, 1));
            shader.SetFloat("uvRotate0", 0);
            shader.SetVec2("uvTranslate0", new Vector2(0, 0));
            shader.SetInt("flipTexture", 0);
            shader.SetInt("numTevStages", 0);
            shader.SetBool("ThresholdingAlphaInterpolation", material.ThresholdingAlphaInterpolation);
            shader.SetVec4("IndirectMat0", new Vector4(1, 1, 0, 0));
            shader.SetVec4("IndirectMat1", new Vector4(1, 1, 0, 0));
            shader.SetInt("tevTexMode", 0);
            shader.SetInt($"texCoords0GenType", 0);
            shader.SetInt($"texCoords0Source", 0);

            BindTextureUniforms(shader, material);

            int id = 1;

            for (int i = 0; i < material.TextureMaps.Length; i++)
            {
                string TexName = material.TextureMaps[i].Name;

                if (material.animController.TexturePatterns.ContainsKey((LTPTarget)i))
                {
                    TexName = material.animController.TexturePatterns[(LTPTarget)i];
                }

                if (textures.ContainsKey(TexName))
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    shader.SetInt($"textures{i}", id);
                    bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[TexName]);
                    if (isBinded)
                    {
                        shader.SetInt($"hasTexture{i}", 1);
                    }

                    id++;
                }
            }

            if (material.TextureTransforms.Count > 0)
            {
                var transform = material.TextureTransforms[0];
                var scale     = transform.Scale;
                var rotate    = transform.Rotate;
                var translate = transform.Translate;

                foreach (var animItem in material.animController.TextureSRTS)
                {
                    switch (animItem.Key)
                    {
                    case LTSTarget.ScaleS: scale.X = animItem.Value; break;

                    case LTSTarget.ScaleT: scale.Y = animItem.Value; break;

                    case LTSTarget.Rotate: rotate = animItem.Value; break;

                    case LTSTarget.TranslateS: translate.X = animItem.Value; break;

                    case LTSTarget.TranslateT: translate.Y = animItem.Value; break;
                    }
                }

                shader.SetVec2("uvScale0", new Vector2(scale.X, scale.Y));
                shader.SetFloat("uvRotate0", rotate);
                shader.SetVec2("uvTranslate0", new Vector2(translate.X, translate.Y));
            }

            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Always, 0f);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.BlendEquation(BlendEquationMode.FuncAdd);
            GL.Disable(EnableCap.ColorLogicOp);
            GL.LogicOp(LogicOp.Noop);
        }
Ejemplo n.º 5
0
        public static void LoadTextureUniforms(BxlytShader shader, BxlytMaterial material,
                                               Dictionary <string, STGenericTexture> textures)
        {
            shader.SetInt("hasTexture0", 0);
            shader.SetInt("hasTexture1", 0);
            shader.SetInt("hasTexture2", 0);
            shader.SetInt("textures0", 0);
            shader.SetInt("textures1", 0);
            shader.SetInt("textures2", 0);

            BindTextureUniforms(shader, material);

            if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern)
            {
                GL.Enable(EnableCap.Texture2D);
            }

            for (int i = 0; i < 3; i++)
            {
                //Default UVs as centered
                var matTranslate = Matrix4.CreateTranslation(0 / 1 - 0.5f, 0 / 1 - 0.5f, 0);
                shader.SetMatrix(String.Format("textureTransforms[{0}]", i), ref matTranslate);
            }

            int id = 1;

            for (int i = 0; i < material.TextureMaps.Length; i++)
            {
                string TexName = material.TextureMaps[i].Name;

                if (material.animController.TexturePatterns.ContainsKey((LTPTarget)i))
                {
                    TexName = material.animController.TexturePatterns[(LTPTarget)i];
                }

                if (textures.ContainsKey(TexName))
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    shader.SetInt($"textures{i}", id);
                    bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[TexName]);
                    if (isBinded)
                    {
                        shader.SetInt($"hasTexture{i}", 1);
                    }

                    var   scale     = new Syroot.Maths.Vector2F(1, 1);
                    float rotate    = 0;
                    var   translate = new Syroot.Maths.Vector2F(0, 0);

                    int index = i;

                    if (material.TextureTransforms.Length > index)
                    {
                        var transform = material.TextureTransforms[index];
                        scale     = transform.Scale;
                        rotate    = transform.Rotate;
                        translate = transform.Translate;

                        foreach (var animItem in material.animController.TextureSRTS)
                        {
                            switch (animItem.Key)
                            {
                            case LTSTarget.ScaleS: scale.X = animItem.Value; break;

                            case LTSTarget.ScaleT: scale.Y = animItem.Value; break;

                            case LTSTarget.Rotate: rotate = animItem.Value; break;

                            case LTSTarget.TranslateS: translate.X = animItem.Value; break;

                            case LTSTarget.TranslateT: translate.Y = animItem.Value; break;
                            }
                        }
                    }


                    var matScale     = Matrix4.CreateScale(scale.X, scale.Y, 1.0f);
                    var matRotate    = Matrix4.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.DegreesToRadians(rotate));
                    var matTranslate = Matrix4.CreateTranslation(
                        translate.X / scale.X - 0.5f,
                        translate.Y / scale.Y - 0.5f, 0);

                    Matrix4 matTransform = matRotate * matTranslate * matScale;
                    shader.SetMatrix(String.Format("textureTransforms[{0}]", i), ref matTransform);

                    id++;
                }
            }
        }