public override void SetTextureUniforms(GLContext control, ShaderProgram shader, STGenericMaterial mat)
        {
            var bfresMaterial = (FMAT)mat;

            GL.ActiveTexture(TextureUnit.Texture0 + 1);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.ID);

            List <string> shaderSamplers = new List <string>();

            foreach (var sampler in ShaderModel.SamplerVariables.symbols)
            {
                if (bfresMaterial.Samplers.Contains(sampler.SymbolName))
                {
                    shaderSamplers.Add(sampler.SymbolName);
                }
            }

            int id = 1;

            for (int i = 0; i < bfresMaterial.TextureMaps?.Count; i++)
            {
                var name    = mat.TextureMaps[i].Name;
                var sampler = mat.TextureMaps[i].Sampler;
                //Lookup samplers targeted via animations and use that texture instead if possible
                if (bfresMaterial.AnimatedSamplers.ContainsKey(sampler))
                {
                    name = bfresMaterial.AnimatedSamplers[sampler];
                }

                var location = this.GetSamplerLocation(bfresMaterial.Samplers[i]);
                if (location == -1)
                {
                    continue;
                }

                GL.ActiveTexture(TextureUnit.Texture0 + id);
                var tex = BindTexture(shader, GetTextures(), mat.TextureMaps[i], name, id);
                shader.SetInt(ConvertSamplerName(location), id++);

                GL.ActiveTexture(TextureUnit.Texture0 + id);
                tex.Bind();
                shader.SetInt(ConvertSamplerFetchName(location), id++);
            }

            var pixelShader = ShaderModel.GetGX2PixelShader(this.BinaryIndex);

            foreach (var sampler in pixelShader.Samplers)
            {
                if (sampler.Name == "cShadowMap")
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    ShadowMapTexture.Bind();
                    shader.SetInt(ConvertSamplerName((int)sampler.Location), id++);
                }

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, 0);
            }
        }
Ejemplo n.º 2
0
        public override void SetTextureUniforms(GLContext control, ShaderProgram shader, STGenericMaterial mat)
        {
            var bfresMaterial = (FMAT)mat;

            GL.ActiveTexture(TextureUnit.Texture0 + 1);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.ID);

            int id = 1;

            var pixelShader = ShaderModel.GetGX2PixelShader(BinaryIndex);

            foreach (var sampler in pixelShader.Samplers)
            {
                GL.ActiveTexture(TextureUnit.Texture0 + id);

                switch (sampler.Name)
                {
                case "ice_cube": IceCubeTexture.Bind(); break;

                case "ice_toon": IceToonTexture.Bind(); break;

                case "light_pre_pass": LightPPTexture.Bind(); break;

                case "linear_depth": LinearDepthTexture.Bind(); break;

                case "shadow_pre_pass": ShadowTexture.Bind(); break;

                case "projection_map": ProjectionTexture.Bind(); break;

                default:
                    ProjectionTexture.Bind(); break;
                }
                this.SetSampler(shader, (int)sampler.Location, ref id);
            }

            for (int i = 0; i < bfresMaterial.TextureMaps?.Count; i++)
            {
                var name    = mat.TextureMaps[i].Name;
                var sampler = mat.TextureMaps[i].Sampler;
                //Lookup samplers targeted via animations and use that texture instead if possible
                if (bfresMaterial.AnimatedSamplers.ContainsKey(sampler))
                {
                    name = bfresMaterial.AnimatedSamplers[sampler];
                }

                var location = this.GetSamplerLocation(bfresMaterial.Samplers[i]);
                if (location == -1)
                {
                    continue;
                }

                if (name == "ZBtoonEX")
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    ToonTexture.Bind();
                    this.SetSampler(shader, (int)location, ref id);
                    continue;
                }

                var binded = BindTexture(shader, GetTextures(), mat.TextureMaps[i], name, id);
                this.SetSampler(shader, (int)location, ref id);
            }

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }