コード例 #1
0
ファイル: BloShader.cs プロジェクト: week9/Switch-Toolbox
        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();
        }
コード例 #2
0
        //For non material panes
        public void SetBasic(BasePane pane, Color color)
        {
            var rotationMatrix = pane.GetRotationMatrix();

            SetMatrix("rotationMatrix", ref rotationMatrix);
            SetColor("color", color);
        }
コード例 #3
0
        //For non material panes
        public void SetBasic(BasePane pane)
        {
            var rotationMatrix = pane.GetRotationMatrix();

            SetMatrix("rotationMatrix", ref rotationMatrix);
        }
コード例 #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);
            }
        }