コード例 #1
0
        public override void Render(Window window)
        {
            base.Render(window);

            gBuffer.Use(clear: true);
            shaders.deferred.Use((uniforms) =>
            {
                uniforms._mvp = camera.MVP;
                uniforms._tex = texRemilia;
            });
            // Draw the triangle.
            foreach (var va in teapotVertexArrays)
            {
                va.Draw();
            }

            FrameBuffer.UseDefault(window, clear: true);
            shaders.rect.Use(uniforms => uniforms._tex = gBuffer.TexColor); viewRects[0].Draw();
            shaders.rect.Use(uniforms => uniforms._tex = gBuffer.TexNormal); viewRects[1].Draw();
            shaders.rect.Use(uniforms => uniforms._tex = gBuffer.TexPosition); viewRects[2].Draw();
            shaders.rect.Use(uniforms => uniforms._tex = gBuffer.TexTexcoord); viewRects[3].Draw();
            //progRect.Use(config => config.SetUniform(OglProgram.UniformID._tex, frameBuffer.depth)); viewRects[1].Draw();
        }
コード例 #2
0
        public void Draw(Camera camera, Action <ShaderProgram> draw, Viewport viewport = null)
        {
            var vp = viewport ?? game.MainViewport;

            GBuffer.Use(shader => {
                shader.Use(draw);
            });


            Framebuffer.Bind();
            GBuffer.fbo.BufferTextures[FboAttachment.DiffuseAttachment].Bind(TextureUnit.Texture0);
            GBuffer.fbo.BufferTextures[FboAttachment.NormalAttachment].Bind(TextureUnit.Texture1);
            GBuffer.fbo.BufferTextures[FboAttachment.SpecularAttachment].Bind(TextureUnit.Texture2);
            GBuffer.fbo.BufferTextures[FboAttachment.DepthAttachment].Bind(TextureUnit.Texture3);

            this.AmbientShader["u_diffuse"] = 0;

            this.AmbientShader["ambient_color"] = this.AmbientColor;
            vp.Draw(this.AmbientShader);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);

            if (DirectionalLights.Count >= 1)
            {
                this.DeferredDirectional["u_diffuse"]     = 0;
                this.DeferredDirectional["u_normal"]      = 1;
                this.DeferredDirectional["u_specular"]    = 2;
                this.DeferredDirectional["u_depth"]       = 3;
                this.DeferredDirectional["inverseCamera"] = camera.ViewProjectionMatrix.Inverted();
                this.DeferredDirectional["eye_pos"]       = camera.Position;

                foreach (DirectionalLight light in this.DirectionalLights)
                {
                    this.DeferredDirectional.SetDirectionalLight("directionalLight", light);

                    vp.Draw(this.DeferredDirectional);
                }
            }

            if (PointLights.Count >= 1)
            {
                this.DeferredPoint["u_diffuse"]     = 0;
                this.DeferredPoint["u_normal"]      = 1;
                this.DeferredPoint["u_specular"]    = 2;
                this.DeferredPoint["u_depth"]       = 3;
                this.DeferredPoint["inverseCamera"] = camera.ViewProjectionMatrix.Inverted();
                this.DeferredPoint["eye_pos"]       = camera.Position;

                foreach (PointLight light in this.PointLights)
                {
                    this.DeferredPoint.SetPointLight("pointLight", light);

                    vp.Draw(this.DeferredPoint);
                }
            }

            GL.Disable(EnableCap.Blend);
            this.Framebuffer.Unbind();

            vp.DrawTexture(Framebuffer.BufferTextures[FboAttachment.DiffuseAttachment]);
        }