示例#1
0
        protected override void OnLoad(EventArgs e)
        {
            CheckFboExtension();

            // the scene can be create after the GL context is prepared
            scene = new Scene();

            Keyboard.KeyUp += KeyUp;
            Keyboard.KeyRepeat = true;
            Mouse.Move += MouseMove;
            Mouse.ButtonDown += MouseButtonHandler;
            Mouse.ButtonUp += MouseButtonHandler;
            Mouse.WheelChanged += MouseWheelChanged;

            modules.Add(multiViewAccum);
            modules.Add(depthPeeler);
            modules.Add(nBuffers);
            modules.Add(ibrt);
            modules.Add(layerVisualizer);
            modules.Add(nBuffersVisualizer);
            //modules.Add(transparency);
            // also the modules can be initialized after the GL context is prepared
            foreach (var module in modules)
            {
                module.Initialize(Width, Height);
            }
            ibrt.DepthPeeler = depthPeeler;
            //transparency.DepthPeeler = depthPeeler;
            layerVisualizer.DepthPeeler = depthPeeler;
            nBuffersVisualizer.NBuffers = nBuffers;
            ibrt.NBuffers = nBuffers;
            ibrt.Navigation = navigation;
            multiViewAccum.Navigation = navigation;

            GL.Enable(EnableCap.DepthTest);
            GL.ClearDepth(1.0f);

            //GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest);

            //GL.Light(LightName.Light0, LightParameter.Position, new float[] { 3.0f, 3.0f, 3.0f });
            //GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
            //GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
            //GL.Light(LightName.Light0, LightParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
            //GL.Light(LightName.Light0, LightParameter.SpotExponent, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
            //GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });
            //GL.LightModel(LightModelParameter.LightModelTwoSide, 1);
            //GL.LightModel(LightModelParameter.LightModelLocalViewer, 1);
            //GL.Enable(EnableCap.Lighting);
            //GL.Enable(EnableCap.Light0);

            //GL.Material(MaterialFace.Front, MaterialParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
            //GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
            //GL.Material(MaterialFace.Front, MaterialParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
            //GL.Material(MaterialFace.Front, MaterialParameter.Emission, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });

            //GL.ShadeModel(ShadingModel.Smooth);

            GL.Enable(EnableCap.Texture2D);

            OnResize(new EventArgs());
        }
示例#2
0
 public void DrawSingleFrame(Scene scene, Navigation navigation)
 {
     DrawSingleFrame(0, scene, navigation);
 }
示例#3
0
        protected override void DrawSingleFrame(int iteration, Scene scene, Navigation navigation)
        {
            Debug.Assert(DepthPeeler != null);

            Camera camera = navigation.Camera;

            ComputeSensorTransform(camera);

            GL.ClearColor(0f, 0f, 0f, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // bind color and depth textures
            GL.ActiveTexture(TextureUnit.Texture0);
            int lensSampleTex = IncrementalModeEnabled
                ? incrementalLensSampleTexture
                : previewLensSampleTexture;
            GL.BindTexture(TextureTarget.Texture3D, lensSampleTex);
            //GL.ActiveTexture(TextureUnit.Texture1);
            //GL.BindTexture(TextureTarget.Texture1D, pixelSampleTexture);
            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2DArray, DepthPeeler.PackedDepthTextures);
            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2DArray, DepthPeeler.ColorTextures);
            GL.ActiveTexture(TextureUnit.Texture4);
            GL.BindTexture(TextureTarget.Texture2DArray, NBuffers.NBuffersTextures);

            // enable IBRT shader
            GL.UseProgram(shaderProgram);

            // set shader parameters (textures, lens model, ...)
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "lensSamplesTexture"), 0);
            //GL.Uniform1(GL.GetUniformLocation(shaderProgram, "pixelSamplesTexture"), 1);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "packedDepthTexture"), 2);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "colorTexture"), 3);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "nBuffersTexture"), 4);

            GL.Uniform2(GL.GetUniformLocation(shaderProgram, "nBuffersSize"), NBuffers.Size);

            GL.Uniform2(GL.GetUniformLocation(shaderProgram, "sensorSize"), camera.SensorSize);
            //GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sensorZ"), camera.SensorZ);
            GL.Uniform3(GL.GetUniformLocation(shaderProgram, "sensorShift"), camera.SensorShift3);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "near"), camera.Near);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "far"), camera.Far);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "lensFocalLength"), camera.Lens.FocalLength);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "lensApertureRadius"), camera.Lens.ApertureRadius);
            //Matrix4 perspective = camera.Perspective;
            //GL.UniformMatrix4(GL.GetUniformLocation(shaderProgram, "perspective"), false, ref perspective);
            GL.Uniform4(GL.GetUniformLocation(shaderProgram, "frustumBounds"), camera.FrustumBounds);

            // jittering
            GL.Uniform2(GL.GetUniformLocation(shaderProgram, "screenSize"), new Vector2(Width, Height));
            GL.Uniform2(GL.GetUniformLocation(shaderProgram, "screenSizeInv"), new Vector2(1.0f / Width, 1.0f / Height));
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sampleCount"), (IncrementalModeEnabled ? SampleCount : PreviewSampleCount));
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sampleCountInv"), 1.0f / (IncrementalModeEnabled ? SampleCount : PreviewSampleCount));
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sampleIndexOffset"), IncrementalModeEnabled ? SampleCount * iteration : 0);
            GL.Uniform1(GL.GetUniformLocation(shaderProgram, "totalSampleCount"), IncrementalModeEnabled ? MaxTotalSampleCount : PreviewSampleCount);
            //GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sampleCount"), SampleCount);
            //GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sampleCountInv"), 1.0f / SampleCount);
            //GL.Uniform1(GL.GetUniformLocation(shaderProgram, "sampleIndexOffset"), SampleCount * iteration);
            //GL.Uniform1(GL.GetUniformLocation(shaderProgram, "totalSampleCount"), TotalSampleCount);

            GL.Uniform2(GL.GetUniformLocation(shaderProgram, "cameraShift"), camera.LensShift);
            GL.UniformMatrix3(GL.GetUniformLocation(shaderProgram, "sensorTransform"), 1, false, sensorTransform3x3);

            // draw the quad
            LayerHelper.DrawQuad();

            // disable shader
            GL.UseProgram(0);

            // unbind textures
            GL.ActiveTexture(TextureUnit.Texture4);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
示例#4
0
        public void PeelLayers(Scene scene)
        {
            // put the results into color and depth textures via FBO
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboHandle);

            AttachLayerTextures(0);

            GL.Enable(EnableCap.Texture2D);

            // draw the first layer without the depth peeling shader
            // (there is no previous depth layer to compare)
            scene.ShaderManager.DepthPeelingData.Enabled = false;

            scene.Draw();

            // draw the rest of layers with depth peeling
            scene.ShaderManager.DepthPeelingData.Enabled = true;

            // Use an other texture unit than 0 as drawing the scene with
            // fixed-function pipeline might use it by default.
            GL.ActiveTexture(TextureUnit.Texture8);
            // Use the previous depth layer for manual depth comparisons.
            GL.BindTexture(TextureTarget.Texture2DArray, depthTextures);
            scene.ShaderManager.DepthPeelingData.DepthTexture = 8; // TextureUnit.Texture8
            scene.ShaderManager.DepthPeelingData.DepthTextureSizeInv = depthTextureSizeInv;

            for (int i = 1; i < LayerCount; i++)
            {
                AttachLayerTextures(i);
                scene.ShaderManager.DepthPeelingData.PreviousLayerIndex = i - 1;

                scene.Draw();
            }
            GL.ActiveTexture(TextureUnit.Texture8);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.ActiveTexture(TextureUnit.Texture0);

            GL.Ext.FramebufferTextureLayer(
                FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt,
                0, 0, 0);
            GL.Ext.FramebufferTextureLayer(
                FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext,
                0, 0, 0);

            //GL.BindTexture(TextureTarget.Texture2DArray, colorTextures);
            //GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2DArray);

            PackDepthImages();
        }