コード例 #1
0
        public void Execute(int index)
        {
            uint  currentDepthWidth  = 0;
            uint  currentDepthHeight = 0;
            float currentNearPlane   = 0;


            MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)mocBurstIntrinsicPtrArray[index];

            mocBurstIntrinsic->GetResolution(out currentDepthWidth, out currentDepthHeight);

            if (currentDepthWidth != (uint)wantedDepthWidth ||
                currentDepthHeight != (uint)wantedDepthHeight)
            {
                //This will free the buffer before allocating a new one
                mocBurstIntrinsic->SetResolution((uint)wantedDepthWidth, (uint)wantedDepthHeight);
            }


            currentNearPlane = mocBurstIntrinsic->GetNearClipPlane();
            if (currentNearPlane != wantedNearClipValue)
            {
                mocBurstIntrinsic->SetNearClipPlane(wantedNearClipValue);
            }
        }
コード例 #2
0
        public void Execute(int index)
        {
            MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)mocBurstIntrinsicPtrArray[index];
            Debug.Assert(mocBurstIntrinsic != null);


            mocBurstIntrinsic->ClearBuffer();
        }
コード例 #3
0
        private void Rasterize(void *mocBurstIntrinsicPtr, OcclusionMesh mesh)
        {
            MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)mocBurstIntrinsicPtr;
            Debug.Assert(mocBurstIntrinsic != null);

            // Testing before rendering generally give good result, but it's a lot better if we are rasterize front to back
            MOC.CullingResult cullingResult = mocBurstIntrinsic->TestRect(
                mesh.screenMin.x, mesh.screenMin.y,
                mesh.screenMax.x, mesh.screenMax.y, mesh.screenMin.w);

            if (cullingResult == MOC.CullingResult.VISIBLE)
            {
                float *vertices = (float *)mesh.transformedVertexData.GetUnsafePtr();
                uint * indices  = (uint *)mesh.indexData.GetUnsafePtr();

                Debug.Assert(mesh.indexCount % 3 == 0);

                cullingResult = mocBurstIntrinsic->RenderTriangles(vertices, indices, mesh.indexCount / 3);
            }
        }
コード例 #4
0
        public void Execute(int index)
        {
            MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)mocBurstIntrinsicPtrArray[indexMergingTo];

            uint tilesWidth;
            uint tilesHeight;

            mocBurstIntrinsic->GetResolutionTiles(out tilesWidth, out tilesHeight);

            int totalTiles      = (int)(tilesWidth * tilesHeight);
            int tileCountPerJob = totalTiles / totalJobCount;

            for (int i = 0; i < mocBurstIntrinsicPtrArray.Length; i++)
            {
                if (i == indexMergingTo)
                {
                    continue;
                }
                MOC.BurstIntrinsics *mocBurstIntrinsicToMerge = (MOC.BurstIntrinsics *)mocBurstIntrinsicPtrArray[i];
                mocBurstIntrinsic->MergeBufferTile(mocBurstIntrinsicToMerge, index * tileCountPerJob, tileCountPerJob);
            }
        }
コード例 #5
0
        unsafe protected void ShowDepth()
        {
            float *DepthBuffer = (float *)m_VisualizeDepthBuffer.GetUnsafePtr();


            if (m_MocOcclusionMode == OcclusionSettingsSystem.MOCOcclusionMode.Intrinsic)
            {
                MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)m_BurstIntrinsicsPtrArray[0];
                mocBurstIntrinsic->ComputePixelDepthBuffer(DepthBuffer, true);
            }
#if UNITY_MOC_NATIVE_AVAILABLE
            else if (m_MocOcclusionMode == OcclusionSettingsSystem.MOCOcclusionMode.Native)
            {
                void *mocNative = (void *)m_MocNativePtrArray[0];
                INTEL_MOC.MOCNative.VisualizeDepthBuffer(mocNative, DepthBuffer, true);
            }
#endif

            /* for (int i = 0; i < m_VisualizeDepthBuffer.Length; i++)
             * {
             *   m_VisualizeDepthBuffer[i] = -1.0f * m_VisualizeDepthBuffer[i];
             * }*/
        }
コード例 #6
0
        private void ShowBounds(bool showTest)
        {
            var OcclusionTest = GetComponentTypeHandle <OcclusionTest>();
            var chunks        = m_Occludees.CreateArchetypeChunkArray(Allocator.TempJob);



            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk = chunks[i];
                var tests = chunk.GetNativeArray(OcclusionTest);
                for (int k = 0; k < tests.Length; k++)
                {
                    var test = tests[k];

                    if (test.screenMax.z < 0)
                    {
                        continue;
                    }

                    int margin = showTest ? 0 : 1;

                    var min = math.clamp((int3)((test.screenMin.xyz * m_Size + m_Size) * 0.5f), -margin, m_Size + margin - 1);
                    var max = math.clamp((int3)((test.screenMax.xyz * m_Size + m_Size) * 0.5f), -margin, m_Size + margin - 1);


                    if (showTest)
                    {
                        float *ptr = (float *)m_VisualizeTestBuffer.GetUnsafePtr();

                        bool visible = false;

                        if (m_MocOcclusionMode == OcclusionSettingsSystem.MOCOcclusionMode.Intrinsic)
                        {
                            MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)m_BurstIntrinsicsPtrArray[0];

                            MOC.CullingResult cullingResult = MOC.CullingResult.VISIBLE;
                            cullingResult = mocBurstIntrinsic->TestRect(test.screenMin.x, test.screenMin.y, test.screenMax.x, test.screenMax.y, test.screenMin.w);
                            if (cullingResult == MOC.CullingResult.VISIBLE)
                            {
                                visible = true;
                            }
                        }
#if UNITY_MOC_NATIVE_AVAILABLE
                        else if (m_MocOcclusionMode == OcclusionSettingsSystem.MOCOcclusionMode.Native)
                        {
                            void *mocNative = (void *)m_MocNativePtrArray[0];

                            INTEL_MOC.CullingResult cullingResult = INTEL_MOC.CullingResult.VISIBLE;
                            cullingResult = INTEL_MOC.MOCNative.TestRect(mocNative, test.screenMin.x, test.screenMin.y, test.screenMax.x, test.screenMax.y, test.screenMin.w);
                            if (cullingResult == INTEL_MOC.CullingResult.VISIBLE)
                            {
                                visible = true;
                            }
                        }
#endif

                        if (!visible)
                        {
                            for (int y = min.y; y < max.y; y++)
                            {
                                var dst = ptr + min.x + y * m_Size;
                                for (int x = min.x; x < max.x; x++, dst++)
                                {
                                    *dst = 1.0f;// Math.Min(*dst + 0.5f, 1.0f); //new float4(1, dst->y, dst->z, 1);
                                }
                            }
                        }
                    }
                    else
                    {
                        float *ptr = (float *)m_VisualizeBoundsBuffer.GetUnsafePtr();

                        bool4 edges = new bool4(min.x >= 0 && min.x < m_Size, max.x >= 0 && max.x < m_Size,
                                                min.y >= 0 && min.y < m_Size, max.y >= 0 && max.y < m_Size);

                        for (int x = min.x; x <= max.x; x++)
                        {
                            if (x >= 0 && x < m_Size)
                            {
                                if (edges[2])
                                {
                                    ptr[x + min.y * m_Size] = 1;
                                }

                                if (edges[3])
                                {
                                    ptr[x + max.y * m_Size] = 1;
                                }
                            }
                        }

                        for (int y = min.y; y <= max.y; y++)
                        {
                            if (y >= 0 && y < m_Size)
                            {
                                if (edges[0])
                                {
                                    ptr[min.x + y * m_Size] = 1;
                                }

                                if (edges[1])
                                {
                                    ptr[max.x + y * m_Size] = 1;
                                }
                            }
                        }
                    }
                }
            }

            chunks.Dispose();
        }
コード例 #7
0
        public void InitDepthBoundTexture()
        {
            uint depthWidth  = 0;
            uint depthHeight = 0;

            if (m_MocOcclusionMode == OcclusionSettingsSystem.MOCOcclusionMode.Intrinsic)
            {
                MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)m_BurstIntrinsicsPtrArray[0];
                mocBurstIntrinsic->GetResolution(out depthWidth, out depthHeight);
            }
#if UNITY_MOC_NATIVE_AVAILABLE
            else if (m_MocOcclusionMode == OcclusionSettingsSystem.MOCOcclusionMode.Native)
            {
                void *mocNative = (void *)m_MocNativePtrArray[0];
                INTEL_MOC.MOCNative.GetResolution(mocNative, out depthWidth, out depthHeight);
            }
#endif

            if (depthWidth == 0 && depthHeight == 0)
            {
                Debug.LogError("moc instance not set up");
                return;
            }

            if (depthWidth != depthHeight)
            {
                Debug.LogError("Currently occlusion debug render system only support same size width and depth");
            }

            m_Size = (int)depthWidth;

            if (m_DepthTexture == null || m_DepthTexture.width != depthWidth || m_DepthTexture.height != depthHeight)
            {
                m_DepthTexture  = new Texture2D((int)depthWidth, (int)depthHeight, TextureFormat.RFloat, false);
                m_TestTexture   = new Texture2D((int)depthWidth, (int)depthHeight, TextureFormat.RFloat, false);
                m_BoundsTexture = new Texture2D((int)depthWidth, (int)depthHeight, TextureFormat.RFloat, false);
            }

            if (!m_VisualizeDepthBuffer.IsCreated || m_VisualizeDepthBuffer.Length != depthWidth * depthHeight)
            {
                if (m_VisualizeDepthBuffer.IsCreated)
                {
                    m_VisualizeDepthBuffer.Dispose();
                }

                if (m_VisualizeTestBuffer.IsCreated)
                {
                    m_VisualizeTestBuffer.Dispose();
                }

                if (m_VisualizeBoundsBuffer.IsCreated)
                {
                    m_VisualizeBoundsBuffer.Dispose();
                }


                m_VisualizeDepthBuffer  = new NativeArray <float>((int)(depthWidth * depthHeight), Allocator.Persistent);
                m_VisualizeTestBuffer   = new NativeArray <float>(m_VisualizeDepthBuffer.Length, Allocator.Persistent);
                m_VisualizeBoundsBuffer = new NativeArray <float>(m_VisualizeDepthBuffer.Length, Allocator.Persistent);
            }
        }
コード例 #8
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var chunkInfo = chunk.GetChunkComponentData(HybridChunkInfo);

            if (!chunkInfo.Valid)
            {
                return;
            }

            var occlusionTestArray = chunk.GetNativeArray(OcclusionTest);

            MOC.BurstIntrinsics *mocBurstIntrinsic = (MOC.BurstIntrinsics *)mocBurstIntrinsicPtrArray[burstIntrinsicIndexToUse];
            Debug.Assert(mocBurstIntrinsic != null);

#if MOC_JOB_STATS
            numTestRectCalls = 0;
#endif

            var chunkData = chunkInfo.CullingData;

            int internalBatchIndex = chunkInfo.InternalIndex;
            int externalBatchIndex = InternalToExternalRemappingTable[internalBatchIndex];

            var batch = Batches[externalBatchIndex];

            int batchOutputOffset = chunkData.StartIndex;
            int batchOutputCount  = 0;

            var indices = (int *)IndexList.GetUnsafeReadOnlyPtr() + chunkData.StartIndex;

            for (var entityIndex = 0; entityIndex < chunkData.Visible; entityIndex++)
            {
                // TODO:  we could reuse the HLOD logic from the frustum culling code here, but
                // this would require some supporting structures and components.  For now, we just
                // test what was written into the index list.
                var index = indices[entityIndex] - chunkData.BatchOffset;
                var test  = occlusionTestArray[index];

                if (!test.enabled)
                {
                    batchOutputCount++;
                    continue;
                }
                MOC.CullingResult cullingResult = mocBurstIntrinsic->TestRect(
                    test.screenMin.x, test.screenMin.y,
                    test.screenMax.x, test.screenMax.y, test.screenMin.w);

#if MOC_JOB_STATS
                numTestRectCalls++;
#endif
                bool visible = (cullingResult == MOC.CullingResult.VISIBLE);

#if UNITY_EDITOR
                visible = (visible != displayOccluded);
#endif

                int advance = visible ? 1 : 0;

#if UNITY_EDITOR
                ref var stats = ref Stats[ThreadIndex];
                stats.Stats[CullingStats.kCountOcclusionCulled] += (1 - advance);
                stats.Stats[CullingStats.kCountOcclusionInput]++;
#endif

                if (!visible)
                {
                    indices[entityIndex] = -1;
                }
                batchOutputCount += advance;
            }