Esempio n. 1
0
        public void Execute(int index)
        {
            // Each invocation is culling 8 renderers (8 split bits * 8 renderers = 64 bit bitfield)
            int start = index * 8;
            int end   = math.min(start + 8, renderers.Length);

            ulong visibleBits = 0;

            for (int i = start; i < end; i++)
            {
                ulong splitMask = FrustumPlanes.Intersect2NoPartialMulti(planes, splitCounts, renderers[i].bounds);
                visibleBits |= splitMask << (8 * (i - start));
            }

            rendererVisibility[index] = visibleBits;
        }
Esempio n. 2
0
    public JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCullingContext cullingContext, BatchCullingOutput cullingOutput, IntPtr userContext)
    {
        if (!m_initialized)
        {
            return(new JobHandle());
        }

#if ENABLE_PICKING
        bool isPickingCulling = cullingContext.viewType == BatchCullingViewType.Picking;
#endif

        var splitCounts = new NativeArray <int>(cullingContext.cullingSplits.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
        for (int i = 0; i < splitCounts.Length; ++i)
        {
            var split = cullingContext.cullingSplits[i];
            splitCounts[i] = split.cullingPlaneCount;
        }

        var planes = FrustumPlanes.BuildSOAPlanePacketsMulti(cullingContext.cullingPlanes, splitCounts, Allocator.TempJob);

        BatchCullingOutputDrawCommands drawCommands = new BatchCullingOutputDrawCommands();
        drawCommands.drawRanges   = Malloc <BatchDrawRange>(m_drawRanges.Length);
        drawCommands.drawCommands = Malloc <BatchDrawCommand>(m_drawBatches.Length *
                                                              splitCounts.Length * 10); // TODO: Multiplying the DrawCommand count by splitCount*10 is NOT an conservative upper bound. But in practice is enough. Sorting would give us a real conservative bound...

        drawCommands.visibleInstances = Malloc <int>(m_instanceIndices.Length);
#if ENABLE_PICKING
        drawCommands.drawCommandPickingInstanceIDs = isPickingCulling ? Malloc <int>(m_drawBatches.Length) : null;
#endif

        // Zero init: Culling job sets the values!
        drawCommands.drawRangeCount       = 0;
        drawCommands.drawCommandCount     = 0;
        drawCommands.visibleInstanceCount = 0;

        drawCommands.instanceSortingPositions          = null;
        drawCommands.instanceSortingPositionFloatCount = 0;

        cullingOutput.drawCommands[0] = drawCommands;

        var visibilityLength   = (m_renderers.Length + 7) / 8;
        var rendererVisibility = new NativeArray <ulong>(visibilityLength, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

        var cullingJob = new CullingJob
        {
            planes             = planes,
            splitCounts        = splitCounts,
            renderers          = m_renderers,
            rendererVisibility = rendererVisibility
        };

        var drawOutputJob = new DrawCommandOutputJob
        {
            batchID            = m_batchID,
            rendererVisibility = rendererVisibility,
            instanceIndices    = m_instanceIndices,
            drawBatches        = m_drawBatches,
            drawRanges         = m_drawRanges,
            drawIndices        = m_drawIndices,
            drawCommands       = cullingOutput.drawCommands
        };

        var jobHandleCulling = cullingJob.Schedule(visibilityLength, 8);
        var jobHandleOutput  = drawOutputJob.Schedule(jobHandleCulling);

        return(jobHandleOutput);
    }