Beispiel #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));
            }
        }
Beispiel #2
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);
        }
        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);
        }