public void RegisterEntity(IOcclusionEntity entity) { // Early rejection if (!entity.IsOccluder()) { return; } // Entities are added too often and clearing them would result in significant // impact on performance due to GC. Therefore, instead of adding and clearing, // we add and rewrite. if (m_currEntiesCnt >= m_entites.Count) { m_entites.Add(entity); } else { m_entites[m_currEntiesCnt] = entity; } ++m_currEntiesCnt; m_entites.Add(entity); Rasterizer.Add(entity); }
public void PerformOcclusion() { Rasterizer.PerformRaterization(); Profiler.BeginSample("OcclusionCulling"); for (int i = 0; i < m_currEntiesCnt; i++) { IOcclusionEntity entity = m_entites[i]; entity.Visible = false; List <Vector3> vertices = entity.BBoxVerticesTransformed; for (int j = 0; j < vertices.Count; j += 4) { Vector3[] verts = { vertices[j], vertices[j + 1], vertices[j + 2], vertices[j + 3] }; // Rasterize triangles and compare theirs pixels against depth buffer // Once a proper points is found, return. if (ProcessTriangle(ref verts[2], ref verts[1], ref verts[0])) { entity.Visible = true; break; } if (ProcessTriangle(ref verts[3], ref verts[2], ref verts[0])) { entity.Visible = true; break; } } } Profiler.EndSample(); // In order to not grow into infinity we clear m_entites if the difference // with m_currEntitesCnt is too big if (m_entites.Count > 1000 && m_entites.Count > 2 * m_currEntiesCnt) { m_entites.Clear(); } m_currEntiesCnt = 0; }
public void RegisterEntity(IOcclusionEntity entity) { // Entities are added too often and clearing them would result in significant // impact on performance due to GC. Therefore, instead of adding and clearing, // we add and rewrite. if (m_currEntiesCnt >= m_entites.Count) m_entites.Add(entity); else m_entites[m_currEntiesCnt] = entity; ++m_currEntiesCnt; m_entites.Add(entity); Rasterizer.Add(entity); }