Ejemplo n.º 1
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]);
        }
Ejemplo n.º 2
0
        public void PreInitialize()
        {
            // Initialize the viewport
            Viewport = new Viewport (new Resolution (this.Configuration.Width, this.Configuration.Height));
            MainViewport = Viewport;

            // Initialize the rendering pipeline
            RenderingPipeline = new RenderingPipeline (this);
        }