Exemplo n.º 1
0
        public void ComputeCoverage(RenderableMesh mesh, AABBf meshBounds, out long sideCoverage, out long topCoverage)
        {
            float longestSide = Math.Max(Math.Max(meshBounds.MaxX - meshBounds.MinX, meshBounds.MaxY - meshBounds.MinY), meshBounds.MaxZ - meshBounds.MinZ);
            float farPlane    = longestSide * 2.0f;

            float   x      = (meshBounds.MinX + meshBounds.MaxX) / 2.0f;
            float   y      = meshBounds.MinY;
            float   z      = (meshBounds.MinZ + meshBounds.MaxZ) / 2.0f;
            Vector3 origin = new Vector3(x, y, z);
            Vector3 up     = Vector3.UnitY;
            Vector3 look   = -Vector3.UnitX;

            for (int i = 0; i < m_occlusionQueries.Length; i++)
            {
                Matrix4 orbit = Matrix4.CreateRotationY(MathHelper.DegreesToRadians((365 / 64.0f) * i));

                Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), 1.0f, 0.1f, farPlane);
                Matrix4 view       = Matrix4.LookAt(origin + Vector3.Transform(new Vector3(longestSide, 0, 0), orbit), origin, Vector3.TransformNormal(up, orbit));

                RenderView(view, projection, mesh, m_occlusionQueries[i]);

                //Bitmap bmp = GLEx.BitmapColorBuffer(m_pixelWidth, m_pixelHeight);
                //bmp.Save("C:\\test_" + i + ".bmp");
            }

            // Gather all the occlusion queries we performed
            long[] m_occlusionQueryResults = new long[64];
            for (int i = 0; i < m_occlusionQueries.Length; i++)
            {
                int ready = 0;
                while (ready == 0)
                {
                    GL.GetQueryObject(m_occlusionQueries[i], GetQueryObjectParam.QueryResultAvailable, out ready);
                }

                GL.GetQueryObject(m_occlusionQueries[i], GetQueryObjectParam.QueryResult, out m_occlusionQueryResults[i]);
            }

            // Reset the current frame buffer.
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

            long totalSidePixels = 0;
            long totalTopPixels  = 0;

            for (int i = 0; i < m_occlusionQueries.Length; i++)
            {
                totalSidePixels += m_occlusionQueryResults[i];
            }

            sideCoverage = totalSidePixels;
            topCoverage  = totalTopPixels;
        }
Exemplo n.º 2
0
        long MeasureOccluderOcclusion(SilhouetteOcclusionValidator sov, VoxelizationInput input, List <AABBi> occluderBounds)
        {
            Mesh           mesh       = BuildMeshFromBoxes(input, occluderBounds);
            RenderableMesh renderable = new RenderableMesh(mesh, true);

            long sideCoverage, topCoverage;

            sov.ComputeCoverage(renderable, input.Octree.MeshBounds, out sideCoverage, out topCoverage);

            renderable.Dispose();

            return(sideCoverage + topCoverage);
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            GC.SuppressFinalize(this);

            if (OriginalMesh != null)
            {
                OriginalMesh.Dispose();
                OriginalMesh = null;
            }

            if (OccluderMesh != null)
            {
                OccluderMesh.Dispose();
                OccluderMesh = null;
            }
        }
Exemplo n.º 4
0
        private void DrawOverlay(RenderableMesh orignalMesh, RenderableMesh occluderMesh)
        {
            GL.PushAttrib(AttribMask.AllAttribBits);

            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.DepthFunc(DepthFunction.Lequal);

            QFont.Begin();

            float yOffset = 5;

            if (orignalMesh != null)
            {
                PrintCode(String.Format("Orignal Triangles   : {0,5}", orignalMesh.Triangles), ref yOffset);
            }
            if (occluderMesh != null)
            {
                PrintCode(String.Format("Occluder Triangles  : {0,5}", occluderMesh.Triangles), ref yOffset);
            }

            PrintCode(String.Format("Occluder Levels     : {0,5}", m_visualizedMaxLevel), ref yOffset);
            if (m_operations.Context.VoxelizationOutput != null)
            {
                PrintCode(String.Format("Volume Coverage     : {0,5:0.##}%", (100 * m_operations.Context.VoxelizationOutput.VolumeCoverage)), ref yOffset);
                PrintCode(String.Format("Silhouette Coverage : {0,5:0.##}%", (100 * m_operations.Context.VoxelizationOutput.SilhouetteCoverage)), ref yOffset);
                PrintCode(String.Format("Time Taken          : {0,5:0.##} seconds", m_operations.Context.VoxelizationOutput.TimeTaken.TotalSeconds), ref yOffset);
            }

            QFont.End();

            GL.PopAttrib();
        }
Exemplo n.º 5
0
        private void RenderView(Matrix4 worldViewMatrix, Matrix4 projMatrix, RenderableMesh mesh, int occlusionQueryHandle)
        {
            // Setup VBO state
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.IndexArray);

            GL.Enable(EnableCap.StencilTest);
            GL.StencilFunc(StencilFunction.Always, 1, 1);
            GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace);

            GL.PushAttrib(AttribMask.ViewportBit);
            GL.Viewport(0, 0, m_pixelWidth, m_pixelHeight);

            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, m_fboHandle);

            // since there's only 1 Color buffer attached this is not explicitly required
            GL.DrawBuffer((DrawBufferMode)FramebufferAttachment.ColorAttachment0Ext);
            GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, m_colorTextureHandle, 0);
            GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, m_renderbufferHandle);
            GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.StencilAttachmentExt, RenderbufferTarget.RenderbufferExt, m_renderbufferHandle);

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

            GL.PushMatrix();

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref worldViewMatrix);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref projMatrix);

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);

            var effect = new Material();

            effect.ShaderHandle = 0;
            effect.ShowLines    = false;

            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            mesh.Render(effect);

            GL.PopMatrix();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // Render a quad with stencil test turned on, this will give me an accurate number of pixels rendered for
            // the object.

            GL.StencilFunc(StencilFunction.Equal, 1, 1);
            GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            GL.Ortho(0, 1, 1, 0, -1, 1);

            GL.Disable(EnableCap.DepthTest);

            GL.BeginQuery(QueryTarget.SamplesPassed, occlusionQueryHandle);

            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(0f, 1f); GL.Vertex2(0f, 0f);
            GL.TexCoord2(1f, 1f); GL.Vertex2(1f, 0f);
            GL.TexCoord2(1f, 0f); GL.Vertex2(1f, 1f);
            GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 1f);
            GL.End();

            GL.EndQuery(QueryTarget.SamplesPassed);

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.StencilTest);

            GL.PopAttrib();
        }