Ejemplo n.º 1
0
        public override void Loaded()
        {
            if (shader != null)
                shader = (Shader)Assets.find(shader.RES_ID);

            for (int i = 0; i < parameters.Count; i++)
            {
                KeyValuePair<string, object> val = parameters.ElementAt(i);

                switch (val.Value.GetType().Name)
                {
                    case "Sampler2D":
                        Sampler2D v = (Sampler2D)val.Value;
                        try
                        {
                            if (v._texture_id > -1)
                                v.texture = (Texture)Assets.find(v._texture_id, typeof(Texture));
                            if (v._sequence_id > -1)
                                v.sequence = (TextureSequence)Assets.find(v._sequence_id, typeof(TextureSequence));
                        }
                        catch { }
                        break;
                }
            }
        }
Ejemplo n.º 2
0
        public Shaders()
        {
            defaultShader = new Shader();
            defaultShader.compile();

            guiShader = new Shader();

            guiShader.vertexProgram =
                        "void main(void)" +
                        "{" +
                            "gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;" +
                            "gl_Position = ftransform();" +
                        "}";

            guiShader.fragmentProgram =
                        "uniform sampler2D texture;" +
                        "uniform vec4 color;" +
                        "void main(void)" +
                        "{" +
                            "vec4 col = texture2D(texture, gl_TexCoord[0].st);" +
                            "gl_FragColor = col * color;" +
                        "}";

            guiShader.compile();
        }
Ejemplo n.º 3
0
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);

                Engine.scene = new Scene();

                font = new Font("Assets/OpenSans-Bold.ttf");

                bump_test = new GameObject();
                bump_test.components.Add(new Sprite());

                bump_test.sprite.width = 512;
                bump_test.sprite.height = 512;

                bump_test.sprite.material = new Material();

                Shader bump = new Shader();

                bump.name = "Bump shader";
                bump.vertexProgram = File.ReadAllText("Assets/vertex.glsl");
                bump.fragmentProgram = File.ReadAllText("Assets/fragment.glsl");
                bump.fullRecompile();

                bump_test.sprite.material.shader = bump;

                Texture tex = new Texture("Assets/tex.png");
                Texture nrm = new Texture("Assets/tex_nrm.png");
                Sampler2D smp_tex = new Sampler2D(tex);
                Sampler2D smp_nrm = new Sampler2D(nrm);

                bump_test.sprite.material.parameters["light_c"] = (int)1;

                bump_test.sprite.material.parameters["texture"] = smp_tex;
                bump_test.sprite.material.parameters["normal"] = smp_nrm;
                bump_test.sprite.material.parameters["color"] = new Vec4(1.0f, 1.0f, 1.0f, 1.0f);
                bump_test.sprite.material.parameters["ambient"] = new Vec4(0.0f, 0.0f, 0.0f, 1.0f);
                bump_test.sprite.material.parameters["light_p[0]"] = new Vec4(256.0f, 256.0f, 150.0f, 1.0f);
                bump_test.sprite.material.parameters["light_col[0]"] = new Vec4(1.0f, 1.0f, 1.0f, 1.0f);
                bump_test.sprite.material.parameters["light_int[0]"] = (float)0.3f;

                bump_test.sprite.material.parameters["amount"] = (float)1.0f;
            }
Ejemplo n.º 4
0
        void setShader(Shader sh)
        {
            _shader = sh;

            if (_shader != null)
            {
                _shader.fullRecompile();
            }
            else
                parameters.Clear();
        }