Ejemplo n.º 1
0
        public override void updateRenderState(Material m, RenderState state)
        {
            if (myLightVisualizer == null)
            {
                myLightVisualizer = Renderer.visualizers["light"] as LightVisualizer;
            }

            state.setUniformBuffer(m.myMaterialUniformBuffer.id, 2);
            state.setUniformBuffer(myLightVisualizer.myLightUniforBuffer.id, 1);

            //setup diffuse map, it should exists
            Texture tex = m.myTextures[(int)Material.TextureId.Diffuse].value();

            state.setTexture((int)tex.id(), 0, TextureTarget.Texture2D);
            state.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));

            //setup specular map if it exists
            if (m.myTextures[(int)Material.TextureId.Specular] != null)
            {
                tex = m.myTextures[(int)Material.TextureId.Specular].value();
                state.setTexture((int)tex.id(), 1, TextureTarget.Texture2D);
                state.setUniform(new UniformData(21, Uniform.UniformType.Int, 1));
            }

            //setup normal map if it exists
            if (m.myTextures[(int)Material.TextureId.Normal] != null)
            {
                tex = m.myTextures[(int)Material.TextureId.Normal].value();
                state.setTexture((int)tex.id(), 2, TextureTarget.Texture2D);
                state.setUniform(new UniformData(22, Uniform.UniformType.Int, 2));
            }
        }
Ejemplo n.º 2
0
        public override void updateRenderState(Material m, RenderState state)
        {
            if (m.myTextures[(int)Material.TextureId.Diffuse] != null)
            {
                Texture tex = m.myTextures[(int)Material.TextureId.Diffuse].value();
                state.setTexture((int)tex.id(), 0, TextureTarget.Texture2D);
                state.setUniform(new UniformData(20, Uniform.UniformType.Bool, true));
                state.setUniform(new UniformData(21, Uniform.UniformType.Int, 0));
            }
            else
            {
                state.setUniform(new UniformData(20, Uniform.UniformType.Bool, false));
            }

            state.setUniform(new UniformData(22, Uniform.UniformType.Color4, m.diffuse));
            state.setUniform(new UniformData(23, Uniform.UniformType.Float, m.alpha));
        }
Ejemplo n.º 3
0
        public override void updateRenderState(Material m, RenderState rs)
        {
            CubemapTexture cubemap = m.myTextures[(int)Material.TextureId.Skybox].value() as CubemapTexture;

            rs.setTexture((int)cubemap.id(), 0, TextureTarget.TextureCubeMap);
            rs.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));             // we know this location from the shader
            rs.setVertexBuffer(SkyBox.theVbo.id, 0, 0, V3.stride);
            rs.setIndexBuffer(SkyBox.theIbo.id);
        }
Ejemplo n.º 4
0
        public override void updateRenderState(Material m, RenderState rs)
        {
            Texture tint1   = (m.findAttribute("tint1") as TextureAttribute).value();
            Texture tint2   = (m.findAttribute("tint2") as TextureAttribute).value();
            Texture sun     = (m.findAttribute("sun") as TextureAttribute).value();
            Texture moon    = (m.findAttribute("moon") as TextureAttribute).value();
            Texture clouds1 = (m.findAttribute("clouds1") as TextureAttribute).value();
            Texture clouds2 = (m.findAttribute("clouds2") as TextureAttribute).value();


            rs.setTexture((int)tint1.id(), 0, TextureTarget.Texture2D);
            rs.setTexture((int)tint2.id(), 1, TextureTarget.Texture2D);
            rs.setTexture((int)sun.id(), 2, TextureTarget.Texture2D);
            rs.setTexture((int)moon.id(), 3, TextureTarget.Texture2D);
            rs.setTexture((int)clouds1.id(), 4, TextureTarget.Texture2D);
            rs.setTexture((int)clouds2.id(), 5, TextureTarget.Texture2D);

            rs.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));
            rs.setUniform(new UniformData(21, Uniform.UniformType.Int, 1));
            rs.setUniform(new UniformData(22, Uniform.UniformType.Int, 2));
            rs.setUniform(new UniformData(23, Uniform.UniformType.Int, 3));
            rs.setUniform(new UniformData(24, Uniform.UniformType.Int, 4));
            rs.setUniform(new UniformData(25, Uniform.UniformType.Int, 5));
        }
Ejemplo n.º 5
0
        public override void updateRenderState(Material m, RenderState state)
        {
            if (myLightVisualizer == null)
            {
                myLightVisualizer = Renderer.visualizers["light"] as LightVisualizer;
            }

            //material properties
            PerPixelUniformData matData = new PerPixelUniformData
            {
                ambientReflectivity  = m.ambient,
                diffuseReflectivity  = m.diffuse,
                specularReflectivity = m.spec,
                emmission            = m.emission,
                shininess            = m.shininess,
                alpha     = m.alpha,
                alphaTest = m.alphaTest
            };

            //setup diffuse map, it should exists
            Texture tex = m.myTextures[(int)Material.TextureId.Diffuse].value();

            state.setTexture((int)tex.id(), 0, TextureTarget.Texture2D);
            state.setUniform(new UniformData(20, Uniform.UniformType.Int, 0));

            //setup specular map if it exists
            if (m.myTextures[(int)Material.TextureId.Specular] != null)
            {
                tex = m.myTextures[(int)Material.TextureId.Specular].value();
                state.setTexture((int)tex.id(), 1, TextureTarget.Texture2D);
                state.setUniform(new UniformData(21, Uniform.UniformType.Int, 1));
                matData.hasSpecularMap = 1;
            }
            else
            {
                matData.hasSpecularMap = 0;
            }

            //setup normal map if it exists
            if (m.myTextures[(int)Material.TextureId.Normal] != null)
            {
                tex = m.myTextures[(int)Material.TextureId.Normal].value();
                state.setTexture((int)tex.id(), 2, TextureTarget.Texture2D);
                state.setUniform(new UniformData(22, Uniform.UniformType.Int, 2));
                matData.hasNormalMap = 1;
                if (tex.hasAlpha == true)
                {
                    matData.hasParallaxMap = 1;
                    matData.parallaxScale  = 0.04f;
                }
            }
            else
            {
                matData.hasNormalMap = 0;
            }


            byte[] data = matData.toBytes();
            state.setUniformUpload(myMaterialUniform, data);
            state.setUniformBuffer(myMaterialUniform.id, 2);
            state.setUniformBuffer(myLightVisualizer.myLightUniforBuffer.id, 1);
        }