Exemplo n.º 1
0
        protected override void InitializeService()
        {
            if (RenderStack.Graphics.Configuration.canUseFramebufferObject)
            {
                framebuffer = FramebufferFactory.Create(size, size);
                framebuffer.AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Red,
                    PixelInternalFormat.Rgb8
                    //PixelInternalFormat.R8
                    //PixelInternalFormat.Rgb32f
                    );
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent24,
                    0
                    );
                framebuffer.Begin();
                framebuffer.Check();
                framebuffer.End();
            }

            camera.Projection.ProjectionType  = ProjectionType.Other;
            camera.Projection.NearParameter.X = 0.01f;
        }
Exemplo n.º 2
0
 private void CreateFramebuffers()
 {
     framebuffer = FramebufferFactory.Create(renderer.Width, renderer.Height);
     framebuffer.AttachRenderBuffer(
         FramebufferAttachment.ColorAttachment0,
         //PixelFormat.RedInteger,
         RenderbufferStorage.R16f,
         0
         );
     framebuffer.AttachRenderBuffer(
         FramebufferAttachment.DepthAttachment,
         //PixelFormat.DepthComponent,
         RenderbufferStorage.DepthComponent32,
         0
         );
     framebuffer.Begin();
     framebuffer.Check();
     framebuffer.End();
 }
Exemplo n.º 3
0
        public void CreateWindowSizeResources()
        {
            System.Diagnostics.Debug.WriteLine("CreateWindowSizeResources()");
            @default = FramebufferFactory.Create(window);

            if (Configuration.gammaCorrect)
            {
                bool sRgbEnable = GL.IsEnabled(EnableCap.FramebufferSrgb);

                linear = FramebufferFactory.Create(window.Width, window.Height);

                int samples = 4;

                linear.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Rgb,
                    RenderbufferStorage.Rgb32f,
                    samples
                    );
                linear.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    samples
                    );
                linear.Begin();
                linear.Check();
                linear.End();

                multisampleResolve = FramebufferFactory.Create(window.Width, window.Height);
                multisampleResolve.AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    PixelFormat.Rgb,
                    PixelInternalFormat.Rgb32f
                    );
                multisampleResolve.Begin();
                multisampleResolve.Check();
                multisampleResolve.End();
            }
            System.Diagnostics.Debug.WriteLine("CreateWindowSizeResources() done");
        }
Exemplo n.º 4
0
 void CreateViews()
 {
     for (int i = 0; i < views.Length; ++i)
     {
         views[i] = FramebufferFactory.Create(window.Width, window.Height);
         views[i].AttachTexture(
             FramebufferAttachment.ColorAttachment0,
             PixelFormat.Rgba,
             PixelInternalFormat.Rgb8
             );
         views[i].AttachRenderBuffer(
             FramebufferAttachment.DepthAttachment,
             //PixelFormat.DepthComponent,
             RenderbufferStorage.Depth24Stencil8,
             0
             );
         views[i].Begin();
         views[i].Check();
         views[i].End();
     }
 }
Exemplo n.º 5
0
        private void CreateFramebuffers()
        {
            if (useFramebuffer == false)
            {
                return;
            }

            framebuffer = FramebufferFactory.Create(renderer.Width, renderer.Height);
            if (RenderStack.Graphics.Configuration.useIntegerPolygonIDs)
            {
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    //PixelFormat.RedInteger,
                    RenderbufferStorage.R32ui,
                    0
                    );
            }
            else
            {
                framebuffer.AttachRenderBuffer(
                    FramebufferAttachment.ColorAttachment0,
                    //PixelFormat.Rgb,
                    RenderbufferStorage.Rgb8,
                    0
                    );
            }
            framebuffer.AttachRenderBuffer(
                FramebufferAttachment.DepthAttachment,
                //PixelFormat.DepthComponent,
                RenderbufferStorage.DepthComponent32,
                0
                );
            framebuffer.Begin();
            framebuffer.Check();
            framebuffer.End();
        }
Exemplo n.º 6
0
        public void SetLightCount(int n)
        {
            if (n == currentLightCount)
            {
                return;
            }

            currentLightCount = n;

            // \todo if n < currentLightCount ?

            if (RenderStack.Graphics.Configuration.useGl1 == true)
            {
                return;
            }

            if (shadow != null)
            {
                shadow.Dispose();
            }
            shadow = FramebufferFactory.Create(Configuration.shadowResolution, Configuration.shadowResolution);

            if (example.Renderer.Configuration.hardwareShadowPCF)
            {
                shadowAttachment = FramebufferAttachment.DepthAttachment;
                var texture = shadow.AttachTextureArray(
                    FramebufferAttachment.DepthAttachment,
                    PixelFormat.DepthComponent,
                    PixelInternalFormat.DepthComponent,
                    n
                    );
            }
            else
            {
                shadowAttachment = FramebufferAttachment.ColorAttachment0;
                if (
                    (RenderStack.Graphics.Configuration.canUseTextureArrays) &&
                    (RenderStack.Graphics.Configuration.glslVersion >= 330)
                    )
                {
                    shadow.AttachTextureArray(
                        FramebufferAttachment.ColorAttachment0,
                        PixelFormat.Red,
                        //PixelInternalFormat.R16f,
                        PixelInternalFormat.R32f,
                        n
                        );
                }
                else
                {
                    shadow.AttachTexture(
                        FramebufferAttachment.ColorAttachment0,
                        PixelFormat.Red,
                        //PixelInternalFormat.R16f,
                        PixelInternalFormat.R32f
                        );
                }
                shadow.AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    0
                    );
            }
            shadow.Begin();
            shadow.Check();
            shadow.End();

            var noShadow = materialManager.Textures["NoShadow"] = new TextureGL(
                1, 1, PixelFormat.Red, PixelInternalFormat.R16f, n
                );

            System.Single[] whiteData = new System.Single[n];
            for (int i = 0; i < n; ++i)
            {
                whiteData[i] = 1.0f;
            }
            noShadow.Upload(whiteData, 0);
        }
Exemplo n.º 7
0
        protected override void InitializeService()
        {
            Size     = size;
            halfSize = size / 2;
            int i;

            smallestMipmapLevel = 0;
            int mipmapSize = size;

            while (mipmapSize > 1)
            {
                mipmapSize /= 2;
                ++smallestMipmapLevel;
            }

            for (i = 0; i < 3; ++i)
            {
                framebuffer[i] = FramebufferFactory.Create(size, size);

                framebuffer[i].AttachTexture(
                    FramebufferAttachment.ColorAttachment0,
                    pixelFormat,
                    pixelInternalFormat
                    );
                framebuffer[i].AttachRenderBuffer(
                    FramebufferAttachment.DepthAttachment,
                    //PixelFormat.DepthComponent,
                    RenderbufferStorage.DepthComponent32,
                    0
                    );
                framebuffer[i].Begin();
                framebuffer[i].Check();
                framebuffer[i].End();
            }

            for (i = 0; i < 5; ++i)
            {
                // posx, negx, posy, negy, negz
                camera[i] = new Camera();
                camera[i].Projection.ProjectionType = ProjectionType.GenericFrustum;
                camera[i].Projection.FovXRadians    = (float)Math.PI * 0.5f;
                camera[i].Projection.FovYRadians    = (float)Math.PI * 0.5f;
                camera[i].Projection.Near           = Near;
                camera[i].Name = "Hemeicube camera " + i.ToString();
            }

            /*  Scale frustums                                        left   right bottom top  */
            SetupCameraFrustum(camera[(int)HemicubeOrientation.PosX], 0.0f, 0.5f, -0.5f, 0.5f);
            SetupCameraFrustum(camera[(int)HemicubeOrientation.NegX], -0.5f, 0.0f, -0.5f, 0.5f);
            SetupCameraFrustum(camera[(int)HemicubeOrientation.NegY], -0.5f, 0.5f, 0.0f, 0.5f);
            SetupCameraFrustum(camera[(int)HemicubeOrientation.PosY], -0.5f, 0.5f, -0.5f, 0.0f);
            SetupCameraFrustum(camera[(int)HemicubeOrientation.NegZ], -0.5f, 0.5f, -0.5f, 0.5f);

            //  I figured out these experimentally. I do not fully understand why
            //  X and Z is inverted from what would be expected while Y is not.
            //  Possibly this has to do something with the fact that camera is
            //  looking at the negative Z. Figure out.
            Matrix4.CreateLookAt(Vector3.Zero, new Vector3(-1.0f, 0.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), out faceOrientation[0]);   // posx
            Matrix4.CreateLookAt(Vector3.Zero, new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), out faceOrientation[1]);    // negx
            Matrix4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, -1.0f), out faceOrientation[2]);    // posy
            Matrix4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, -1.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), out faceOrientation[3]);    // negy
            Matrix4.CreateLookAt(Vector3.Zero, new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, -1.0f, 0.0f), out faceOrientation[4]);    // negz


            viewport[0] = new Viewport(halfSize, 0, halfSize, size);                    // posx
            viewport[1] = new Viewport(0, 0, halfSize, size);                           // negx
            viewport[2] = new Viewport(0, halfSize, size, halfSize);                    // posy
            viewport[3] = new Viewport(0, 0, size, halfSize);                           // negy
            viewport[4] = new Viewport(0, 0, size, size);                               // negz
        }