private void Rasterize(void *mocNative, OcclusionMesh mesh) { //Testing before rendering generally give good result, but it's a lot better if we are rasterize front to back INTEL_MOC.CullingResult cullingResult = INTEL_MOC.CullingResult.VISIBLE; cullingResult = INTEL_MOC.MOCNative.TestRect( mocNative, mesh.screenMin.x, mesh.screenMin.y, mesh.screenMax.x, mesh.screenMax.y, mesh.screenMin.w); if (cullingResult == INTEL_MOC.CullingResult.VISIBLE) { float *vertices = (float *)mesh.transformedVertexData.GetUnsafePtr(); uint * indices = (uint *)mesh.indexData.GetUnsafePtr(); Debug.Assert(mesh.indexCount % 3 == 0); INTEL_MOC.MOCNative.RenderTriangles(mocNative, vertices, indices, mesh.indexCount / 3); } }
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(); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkInfo = chunk.GetChunkComponentData(HybridChunkInfo); if (!chunkInfo.Valid) { return; } var occlusionTestArray = chunk.GetNativeArray(OcclusionTest); 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; void *mocNative = (void *)mocNativePtrArray[mocNativeIndexToUse]; 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; } 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); bool visible = (cullingResult == INTEL_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; }