Exemplo n.º 1
0
        public static void SetMaterials(BxlytShader shader, GCBLO.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;

            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", 0);
            shader.SetBool("AlphaInterpolation", material.AlphaInterpolation);
            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);

            LoadTextureUniforms(shader, material, textures);
            LoadDefaultBlending();
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
0
        public static void SetMaterials(BxlytShader shader, CTR.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.WhiteColor.Color);
            shader.SetColor("blackColor", material.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.SetBool("AlphaInterpolation", material.AlphaInterpolation);
            shader.SetInt($"texCoords0GenType", 0);
            shader.SetInt($"texCoords0Source", 0);

            LoadTextureUniforms(shader, material, textures);
            LoadDefaultBlending();
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public static void SetMaterials(BxlytShader shader, Revolution.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("AlphaInterpolation", material.AlphaInterpolation);
            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);
        }
Exemplo n.º 6
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);
        }