Beispiel #1
0
        protected unsafe override void DoInitialize()
        {
            base.DoInitialize();
            // pbr: generate a 2D LUT from the BRDF equations used.
            // then re-configure capture framebuffer object and render screen-space quad with BRDF shader.
            // pbr: setup framebuffer
            var captureFBO = new Framebuffer(512, 512);

            captureFBO.Bind();
            var captureRBO = new Renderbuffer(512, 512, GL.GL_DEPTH_COMPONENT24);

            captureFBO.Attach(FramebufferTarget.Framebuffer, captureRBO, AttachmentLocation.Depth);
            captureFBO.Attach(FramebufferTarget.Framebuffer, this.texBRDF, 0u);
            captureFBO.CheckCompleteness();
            captureFBO.Unbind();

            RenderMethod   method         = this.RenderUnit.Methods[0];
            ViewportSwitch viewportSwitch = new ViewportSwitch(0, 0, 512, 512);

            viewportSwitch.On();
            captureFBO.Bind();
            GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            method.Render();
            captureFBO.Unbind();
            viewportSwitch.Off();
            captureFBO.Dispose();

            this.texBRDF.GetImage(512, 512).Save(string.Format("texBRDF.png"));
        }
Beispiel #2
0
        protected override void OnLoad()
        {
            base.OnLoad();

            // initialize and bind framebuffer
            _framebuffer = new Framebuffer();
            _framebuffer.Bind(FramebufferTarget.Framebuffer);

            // initialize a renderbuffer and bind it to the depth attachment
            // to support depth testing while rendering to the texture
            _depthBuffer = new Renderbuffer();
            _depthBuffer.Init(RenderbufferStorage.DepthComponent, FramebufferWidth, FramebufferHeight);
            _framebuffer.Attach(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, _depthBuffer);

            // initialize texture and bind it to the color attachment
            _texture = new Texture2D(SizedInternalFormat.Rgba8, FramebufferWidth, FramebufferHeight, 1);
            _framebuffer.Attach(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _texture);
            Framebuffer.Unbind(FramebufferTarget.Framebuffer);

            // initialize shaders
            _colorProgram   = ProgramFactory.Create <SimpleColorProgram>();
            _textureProgram = ProgramFactory.Create <SimpleTextureProgram>();

            // initialize demonstration geometry
            _cube = ShapeBuilder.CreateColoredCube(_colorProgram.InPosition, _colorProgram.InColor);
            _quad = ShapeBuilder.CreateTexturedQuad(_textureProgram.InPosition, _textureProgram.InTexCoord);

            // set camera position
            ActiveCamera.Position = new Vector3(0, 0, 3);

            // enable depth testing
            GL.Enable(EnableCap.DepthTest);
        }
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            {
                var texture = new Texture(new TexImageBitmap(width, height),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
                                          new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
                texture.Initialize();
                framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 0u);// 0
                this.texture = texture;
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth); // special
            }
            framebuffer.SetDrawBuffer(GL.GL_COLOR_ATTACHMENT0);                                            // as in 0 in framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 0u);// 0
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
Beispiel #4
0
        private void SetUpRboDepth(int width, int height)
        {
            // Render buffer for the depth attachment, which is necessary for depth testing.
            Renderbuffer rboDepth = new Renderbuffer(width, height, RenderbufferStorage.DepthComponent);

            AddAttachment(FramebufferAttachment.DepthAttachment, rboDepth);
        }
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            for (uint location = 0; location < 4; location++)
            {
                var texture = new Texture(new TexImageBitmap(width, height),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
                                          new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
                texture.Initialize();
                framebuffer.Attach(FramebufferTarget.Framebuffer, texture, location);
                this.outTextures[location] = texture;
            }
            {
                this.BindingTexture = this.outTextures[0];
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            //framebuffer.SetDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + 1);// as in 1 in framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 1u);// 1
            framebuffer.SetDrawBuffers(
                GL.GL_COLOR_ATTACHMENT0, GL.GL_COLOR_ATTACHMENT0 + 1, GL.GL_COLOR_ATTACHMENT0 + 2, GL.GL_COLOR_ATTACHMENT0 + 3);
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
Beispiel #6
0
        protected unsafe override void DoInitialize()
        {
            base.DoInitialize();
            // pbr: run a quasi monte-carlo simulation on the environment lighting to create a prefilter (cube)map.
            const uint maxMipLevels = 5;
            var        viewport     = new ViewportSwitch();

            for (int mip = 0; mip < maxMipLevels; ++mip)
            {
                // reisze framebuffer according to mip-level size.
                int mipWidth   = (int)(128 * Math.Pow(0.5, mip));
                int mipHeight  = (int)(128 * Math.Pow(0.5, mip));
                var captureFBO = new Framebuffer(mipWidth, mipHeight);
                captureFBO.Bind();
                var captureRBO = new Renderbuffer(mipWidth, mipHeight, GL.GL_DEPTH_COMPONENT24);
                captureFBO.Attach(FramebufferTarget.Framebuffer, captureRBO, AttachmentLocation.Depth);
                captureFBO.CheckCompleteness();
                captureFBO.Unbind();
                viewport.Width = mipWidth; viewport.Height = mipHeight;
                viewport.On();
                // NOTE: I added '/ 10' to make it a clearer visual effect.
                float         roughness = (float)mip / (float)(maxMipLevels - 1) / 5;
                RenderMethod  method    = this.RenderUnit.Methods[0];
                ShaderProgram program   = method.Program;
                program.SetUniform("roughness", roughness);
                program.SetUniform("projection", captureProjection);
                program.SetUniform("environmentMap", this.envCubemap);
                for (uint i = 0; i < 6; ++i)
                {
                    program.SetUniform("view", captureViews[i]);
                    CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
                    uint        location = 0;
                    //int level = 0;
                    captureFBO.Bind();
                    captureFBO.Attach(FramebufferTarget.Framebuffer, location, face, this.prefilterMap, mip);
                    captureFBO.CheckCompleteness();
                    captureFBO.Unbind();

                    captureFBO.Bind();
                    GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                    method.Render();
                    captureFBO.Unbind();

                    this.prefilterMap.GetImage(face, mipWidth, mipHeight, mip).Save(string.Format("prefilter.{0}.mip{1}.png", face, mip));
                }

                viewport.Off();
                captureFBO.Dispose();
            }
        }
Beispiel #7
0
        public UIRender(Renderbuffer renderBuffer)
        {
            this._screenSize = renderBuffer.Size;

            _context      = GL.GetCurrent(true);
            _shader       = new UIShader();
            _renderBuffer = renderBuffer;

            _framebuffer = new Framebuffer(_screenSize);

            _framebuffer.AttachRenderbuffer(FramebufferAttachment.ColorAttachment0, renderBuffer);
            _idTexture = _framebuffer.AddColorTexture(Core.FramebufferAttachment.ColorAttachment1, PixelInternalFormat.R32ui, PixelFormat.Red);

            _framebuffer.CheckStatus(true);
        }
        private Framebuffer InitFramebuffer(int width, int height, Texture texture)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 0u);
            {
                var depthBuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, depthBuffer, AttachmentLocation.Depth);
            }
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
Beispiel #9
0
        private Framebuffer InitFramebuffer(int texWidth, int texHeight)
        {
            var framebuffer = new Framebuffer();

            framebuffer.Bind();
            Texture texture = this.backface2DTexture;

            framebuffer.Attach(texture);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(texWidth, texHeight, DepthComponentType.DepthComponent);

            framebuffer.Attach(depthBuffer);
            framebuffer.Unbind();

            return(framebuffer);
        }
        private void OnLoad(object sender, EventArgs e)
        {
            // initialize and bind framebuffer
            _framebuffer = new Framebuffer();
            _framebuffer.Bind(FramebufferTarget.Framebuffer);

            // initialize a renderbuffer and bind it to the depth attachment
            // to support depth testing while rendering to the texture
            _depthBuffer = new Renderbuffer();
            _depthBuffer.Init(RenderbufferStorage.DepthComponent, FramebufferWidth, FramebufferHeight);
            _framebuffer.Attach(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, _depthBuffer);

            // initialize texture and bind it to the color attachment
            _texture = new Texture2D(SizedInternalFormat.Rgba8, FramebufferWidth, FramebufferHeight, 1);
            _framebuffer.Attach(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _texture);
            Framebuffer.Unbind(FramebufferTarget.Framebuffer);

            // initialize demonstration geometry
            _cube = new ColorCube();
            _cube.UpdateBuffers();
            _quad = new TexturedQuad();
            _quad.UpdateBuffers();

            // initialize shaders
            _colorProgram   = ProgramFactory.Create <SimpleColorProgram>();
            _textureProgram = ProgramFactory.Create <SimpleTextureProgram>();

            // set up vertex attributes for the cube
            _cubeVao = new VertexArray();
            _cubeVao.Bind();
            _cubeVao.BindAttribute(_colorProgram.InPosition, _cube.VertexBuffer);
            _cubeVao.BindAttribute(_colorProgram.InColor, _cube.ColorBuffer);
            _cubeVao.BindElementBuffer(_cube.IndexBuffer);

            // set up vertex attributes for the quad
            _quadVao = new VertexArray();
            _quadVao.Bind();
            _quadVao.BindAttribute(_textureProgram.InPosition, _quad.VertexBuffer);
            _quadVao.BindAttribute(_textureProgram.InTexCoord, _quad.TexCoordBuffer);

            // set camera position
            Camera.DefaultState.Position = new Vector3(0, 0, 3);
            Camera.ResetToDefault();

            // enable depth testing
            GL.Enable(EnableCap.DepthTest);
        }
Beispiel #11
0
        protected unsafe override void DoInitialize()
        {
            base.DoInitialize();
            ViewportSwitch viewportSwitch = new ViewportSwitch(0, 0, 512, 512);
            // pbr: setup framebuffer
            var captureFBO = new Framebuffer(512, 512);

            captureFBO.Bind();
            var captureRBO = new Renderbuffer(512, 512, GL.GL_DEPTH_COMPONENT24);

            captureFBO.Attach(FramebufferTarget.Framebuffer, captureRBO, AttachmentLocation.Depth);
            captureFBO.CheckCompleteness();
            captureFBO.Unbind();

            // pbr: convert HDR equirectangular environment map to cubemap equivalent
            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("equirectangularMap", this.texHDR);
            program.SetUniform("projection", captureProjection);
            viewportSwitch.On();
            for (uint i = 0; i < 6; ++i)
            {
                program.SetUniform("view", captureViews[i]);
                CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
                uint        location = 0;
                int         level    = 0;
                captureFBO.Bind();
                captureFBO.Attach(FramebufferTarget.Framebuffer, location, face, this.environmentMap, level);
                captureFBO.CheckCompleteness();
                captureFBO.Unbind();

                captureFBO.Bind();
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                method.Render();
                captureFBO.Unbind();

                this.environmentMap.GetImage(face, 512, 512).Save(string.Format("texEnvCubemap.{0}.mip{1}.png", face, 0));
            }
            viewportSwitch.Off();
            captureFBO.Dispose();

            this.environmentMap.Bind();
            glGenerateMipmap(GL.GL_TEXTURE_CUBE_MAP);
            this.environmentMap.Unbind();
        }
        internal void ReinitializeImageBuffers()
        {
            if (image_effect_fbo != null)
            {
                image_effect_fbo.Dispose();
                image_effect_depthbuffer.Dispose();
                image_effect_colorbuffer.Dispose();
                image_effect_brigthnessbuffer.Dispose();
            }

            // image effect stuff:
            image_effect_fbo = new Framebuffer();

            // depth buffer
            image_effect_depthbuffer = new Renderbuffer(RenderbufferStorage.DepthComponent, Game.window.Width, Game.window.Height);
            image_effect_fbo.attach(FramebufferAttachment.DepthAttachment, image_effect_depthbuffer);

            // color buffer
            image_effect_colorbuffer = new Texture2D(Game.window.Width, Game.window.Height)
            {
                filter          = Filter.Linear,
                wrap            = WrapMode.ClampToEdge,
                internal_format = PixelInternalFormat.Rgba16f
            };
            image_effect_colorbuffer.apply(genMipMap: false);
            image_effect_fbo.attach(FramebufferAttachment.ColorAttachment0, image_effect_colorbuffer);

            // brightness buffer
            image_effect_brigthnessbuffer = new Texture2D(Game.window.Width, Game.window.Height)
            {
                filter          = Filter.Linear,
                wrap            = WrapMode.ClampToEdge,
                internal_format = PixelInternalFormat.Rgba16f
            };
            image_effect_brigthnessbuffer.apply(genMipMap: false);
            image_effect_fbo.attach(FramebufferAttachment.ColorAttachment1, image_effect_brigthnessbuffer);

            image_effect_fbo.draw_buffers(DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1);

            Console.WriteLine("reinit of main framebuffer " + Game.window.Width + ", " + Game.window.Height + " status: " + image_effect_fbo.status);
        }
Beispiel #13
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            {
                var texture = new Texture(TextureTarget.Texture2D,
                                          new NullImageFiller(TEXTURE_SIZE, TEXTURE_SIZE, OpenGL.GL_RGB, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE),
                                          new SamplerParameters(
                                              TextureWrapping.Repeat,
                                              TextureWrapping.Repeat,
                                              TextureWrapping.Repeat,
                                              TextureFilter.Linear,
                                              TextureFilter.Linear));
                texture.ActiveTextureIndex = 1;
                texture.Initialize();
                this.mirrorTexture = texture;
            }
            {
                Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(TEXTURE_SIZE, TEXTURE_SIZE, DepthComponentType.DepthComponent);
                var          framebuffer = new Framebuffer();
                framebuffer.Bind();
                framebuffer.Attach(this.mirrorTexture);
                framebuffer.Attach(depthBuffer);
                framebuffer.CheckCompleteness();
                this.framebuffer = framebuffer;
            }

            {
                mat4 view = glm.lookAt(new vec3(0.0f, 0.0f, 5.0f), new vec3(0.0f, 0.0f, 0.0f), new vec3(0.0f, 1.0f, 0.0f));
                this.SetUniform("u_modelViewMatrix", view);
                mat4 projection = glm.ortho(-(float)TEXTURE_SIZE / 2, (float)TEXTURE_SIZE / 2, -(float)TEXTURE_SIZE / 2, (float)TEXTURE_SIZE / 2, 1.0f, 100.0f);
                this.SetUniform("u_projectionMatrix", projection);
                this.SetUniform("u_waterPlaneLength", (float)this.waterPlaneLength);
            }

            this.viewportSwitch = new ViewportSwitch(0, 0, TEXTURE_SIZE, TEXTURE_SIZE);
        }
Beispiel #14
0
        protected override void DoInitialize()
        {
            // init textures.
            this.envCubeMap     = LoadEnvCubeMap();
            this.irradianceMap  = LoadIrradianceMap();
            this.prefliterMap   = LoadPrefliterMap();
            this.brdfLUTTexture = LoadBRDFTexture();
            //this.hdrTexture = LoadHdrEnvironmentMap(@"Texture\hdr\newport_loft.hdr");
            this.hdrTexture = LoadHDRTexture(@"Texture\hdr\newport_loft.hdr");
            //{
            //    Bitmap bitmap = LoadHdrFormFreeImage(@"Texture\hdr\newport_loft.hdr");
            //    var storage = new TexImageBitmap(bitmap, GL.GL_RGB16F);
            //    var texture = new Texture(storage,
            //        new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE),
            //        new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE),
            //        new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
            //        new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
            //    texture.Initialize();
            //    this.hdrTexture = texture;
            //}

            this.albedoMap = LoadTexture(@"Texture\agedplanks1-albedo.png");
            this.albedoMap.TextureUnitIndex = 3;
            this.normalMap = LoadTexture(@"Texture\agedplanks1-normal4-ue.png");
            this.normalMap.TextureUnitIndex = 4;
            this.metallicMap = LoadTexture(@"Texture\agedplanks1-ao.png");
            this.metallicMap.TextureUnitIndex = 5;
            this.roughnessMap = LoadTexture(@"Texture\agedplanks1-roughness.png");
            this.roughnessMap.TextureUnitIndex = 6;
            this.aoMap = LoadTexture(@"Texture\agedplanks1-ao.png");
            this.aoMap.TextureUnitIndex = 7;

            this.pbrProgram.SetUniform("albedoMap", this.albedoMap);
            this.pbrProgram.SetUniform("normalMap", this.normalMap);
            this.pbrProgram.SetUniform("metallicMap", this.metallicMap);
            this.pbrProgram.SetUniform("roughnessMap", this.roughnessMap);
            this.pbrProgram.SetUniform("aoMap", this.aoMap);

            //设置投影矩阵
            mat4 captureProjection = glm.perspective((float)(Math.PI / 2), 1.0f, 0.1f, 20.0f);

            mat4[] captureView =
            {
                glm.lookAt(new vec3(0, 0, 0), new vec3(1.0f,   0.0f,  0.0f), new vec3(0.0f, -1.0f,  0.0f)),
                glm.lookAt(new vec3(0, 0, 0), new vec3(-1.0f,  0.0f,  0.0f), new vec3(0.0f, -1.0f,  0.0f)),
                glm.lookAt(new vec3(0, 0, 0), new vec3(0.0f,   1.0f,  0.0f), new vec3(0.0f,  0.0f,  1.0f)),
                glm.lookAt(new vec3(0, 0, 0), new vec3(0.0f,  -1.0f,  0.0f), new vec3(0.0f,  0.0f, -1.0f)),
                glm.lookAt(new vec3(0, 0, 0), new vec3(0.0f,   0.0f,  1.0f), new vec3(0.0f, -1.0f,  0.0f)),
                glm.lookAt(new vec3(0, 0, 0), new vec3(0.0f,   0.0f, -1.0f), new vec3(0.0f, -1.0f,  0.0f)),
            };

            ViewportSwitch viewportSwitch = new ViewportSwitch(0, 0, 512, 512);
            //转换HDR Equirectangular environmentMap 为 HDR cubeMap
            {
                //创建渲染到CubeMap的FBO
                var fbo = new Framebuffer(512, 512);
                fbo.Bind();
                var rbo = new Renderbuffer(512, 512, GL.GL_DEPTH_COMPONENT24);
                fbo.Attach(FramebufferTarget.Framebuffer, rbo, AttachmentLocation.Depth);
                fbo.CheckCompleteness();
                fbo.Unbind();

                viewportSwitch.On();
                ShaderProgram program = this.equiRectangular2CubemapProgram;
                program.SetUniform("equirectangularMap", this.hdrTexture);
                program.SetUniform("ProjMatrix", captureProjection);
                for (uint i = 0; i < 6; ++i)
                {
                    fbo.Bind();
                    CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
                    uint        location = 0;
                    int         level    = 0;
                    fbo.Attach(FramebufferTarget.Framebuffer, location, face, envCubeMap, level);
                    fbo.CheckCompleteness();
                    fbo.Unbind();

                    fbo.Bind();
                    program.Bind();
                    program.SetUniform("ViewMatrix", captureView[i]);
                    program.PushUniforms();
                    GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                    renderCube();
                    program.Unbind();
                    fbo.Unbind();

                    envCubeMap.GetImage(face, fbo.Width, fbo.Height).Save(
                        string.Format("envCubeMap.{0}.png", face));
                }
                viewportSwitch.Off();
                fbo.Dispose();
            }
            //创建一个irradianceMap
            {
                var fbo = new Framebuffer(irradianceMapLength, irradianceMapLength);
                fbo.Bind();
                var rbo = new Renderbuffer(irradianceMapLength, irradianceMapLength, GL.GL_DEPTH_COMPONENT24);
                fbo.Attach(FramebufferTarget.Framebuffer, rbo, AttachmentLocation.Depth);
                fbo.CheckCompleteness();
                fbo.Unbind();

                //pbr:通过卷积来创建一张irradianceMap来解决diffueIntegral
                viewportSwitch.Width = irradianceMapLength; viewportSwitch.Height = irradianceMapLength;
                viewportSwitch.On();
                ShaderProgram program = this.irradianceProgram;
                program.SetUniform("environmentMap", envCubeMap);
                program.SetUniform("ProjMatrix", captureProjection);
                for (uint i = 0; i < 6; ++i)
                {
                    fbo.Bind();
                    CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
                    uint        location = 0;
                    int         level    = 0;
                    fbo.Attach(FramebufferTarget.Framebuffer, location, face, irradianceMap, level);
                    fbo.CheckCompleteness();
                    fbo.Unbind();

                    //vec3 color = System.Drawing.Color.SkyBlue.ToVec3();
                    vec3 color = System.Drawing.Color.Black.ToVec3();

                    fbo.Bind();
                    program.Bind();
                    program.SetUniform("ViewMatrix", captureView[i]);
                    program.PushUniforms();
                    GL.Instance.ClearColor(color.x, color.y, color.z, 1);
                    GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                    renderCube();
                    program.Unbind();
                    fbo.Unbind();

                    irradianceMap.GetImage(face, fbo.Width, fbo.Height).Save(
                        string.Format("irradianceMap.fill.{0}.png", face));
                }
                viewportSwitch.Off();
                fbo.Dispose();
            }
            //对环境光用蒙特卡洛积分来创建一个prefliterMap贴图
            {
                ShaderProgram program = this.prefliterProgram;
                program.SetUniform("environmentMap", envCubeMap);
                program.SetUniform("ProjMatrix", captureProjection);
                const int maxMipLevels = 5;
                for (int level = 0; level < maxMipLevels; level++)
                {
                    int mipWidth  = (int)(128 * Math.Pow(0.5, level));
                    int mipHeight = (int)(128 * Math.Pow(0.5, level));
                    var fbo       = new Framebuffer(mipWidth, mipHeight);
                    fbo.Bind();
                    var rbo = new Renderbuffer(mipWidth, mipHeight, GL.GL_DEPTH_COMPONENT24);
                    fbo.Attach(FramebufferTarget.Framebuffer, rbo, AttachmentLocation.Depth);
                    fbo.CheckCompleteness();
                    fbo.Unbind();

                    viewportSwitch.Width = mipWidth; viewportSwitch.Height = mipHeight;
                    viewportSwitch.On();
                    float roughness = (float)level / (float)(maxMipLevels - 1);
                    program.SetUniform("roughness", roughness);
                    for (uint j = 0; j < 6; j++)
                    {
                        program.SetUniform("ViewMatrix", captureView[level]);

                        fbo.Bind();
                        CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + j);
                        uint        location = 0;
                        fbo.Attach(FramebufferTarget.Framebuffer, location, face, prefliterMap, level);
                        fbo.CheckCompleteness();
                        fbo.Unbind();

                        fbo.Bind();
                        program.Bind();
                        program.PushUniforms();
                        GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                        renderCube();
                        program.Unbind();
                        fbo.Unbind();

                        prefliterMap.GetImage(face, fbo.Width, fbo.Height, level).Save(
                            string.Format("prefliterMap.{0}.{1}.png", level, face));
                    }
                    viewportSwitch.Off();
                    fbo.Dispose();
                }
                program.Unbind();
            }
            {
                var fbo = new Framebuffer(512, 512);
                fbo.Bind();
                var rbo = new Renderbuffer(512, 512, GL.GL_DEPTH_COMPONENT24);
                fbo.Attach(FramebufferTarget.Framebuffer, rbo, AttachmentLocation.Depth);
                fbo.Attach(FramebufferTarget.Framebuffer, brdfLUTTexture, 0u);
                fbo.CheckCompleteness();
                fbo.Unbind();

                fbo.Bind();
                viewportSwitch.Width = 512; viewportSwitch.Height = 512;
                viewportSwitch.On();
                ShaderProgram program = this.brdfProgram;
                program.Bind();
                program.PushUniforms();
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                renderQuad();
                program.Unbind();
                viewportSwitch.Off();
                fbo.Unbind();
                fbo.Dispose();

                brdfLUTTexture.GetImage(fbo.Width, fbo.Height).Save(
                    string.Format("BRDF.GetImage.png"));
            }
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="internalFormat"></param>
        /// <returns></returns>
        public static Renderbuffer CreateColorbuffer(int width, int height, uint internalFormat = GL.GL_RGBA)
        {
            var renderbuffer = new Renderbuffer(width, height, internalFormat);

            return(renderbuffer);
        }
Beispiel #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="internalFormat"></param>
        /// <returns></returns>
        public static Renderbuffer CreateDepthbuffer(int width, int height, uint internalFormat = GL.GL_DEPTH_COMPONENT)
        {
            var renderbuffer = new Renderbuffer(width, height, internalFormat);

            return(renderbuffer);
        }
 public partial void ExtGetRenderbuffers([Count(Parameter = "maxRenderbuffers"), Flow(FlowDirection.Out)] out Renderbuffer renderbuffers, [Flow(FlowDirection.In)] int maxRenderbuffers, [Count(Count = 1), Flow(FlowDirection.Out)] out int numRenderbuffers);
        /// <summary>
        ///
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="internalFormat"></param>
        /// <returns></returns>
        public static Renderbuffer CreateDepthbuffer(int width, int height, uint internalFormat = OpenGL.GL_DEPTH_COMPONENT)
        {
            var renderbuffer = new Renderbuffer(width, height, internalFormat, RenderbufferType.DepthBuffer);

            return renderbuffer;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="internalFormat"></param>
        /// <returns></returns>
        public static Renderbuffer CreateColorbuffer(int width, int height, uint internalFormat = OpenGL.GL_RGBA)
        {
            var renderbuffer = new Renderbuffer(width, height, internalFormat, RenderbufferType.ColorBuffer);

            return renderbuffer;
        }
Beispiel #20
0
        public void RenderbufferObject()
        {
            Renderbuffer glObject = new Renderbuffer(1, 1, RenderbufferStorage.Rgba16);

            Assert.AreEqual($"RenderbufferObject ID: {glObject.Id}", glObject.ToString());
        }