예제 #1
0
        public void DestroyDecalEntity(DecalEntity decalEntity)
        {
            if (!m_DecalEntityIndexer.IsValid(decalEntity))
            {
                return;
            }

            var decalItem = m_DecalEntityIndexer.GetItem(decalEntity);

            m_DecalEntityIndexer.DestroyDecalEntity(decalEntity);

            int chunkIndex = decalItem.chunkIndex;
            int arrayIndex = decalItem.arrayIndex;

            DecalEntityChunk   entityChunk   = entityChunks[chunkIndex];
            DecalCachedChunk   cachedChunk   = cachedChunks[chunkIndex];
            DecalCulledChunk   culledChunk   = culledChunks[chunkIndex];
            DecalDrawCallChunk drawCallChunk = drawCallChunks[chunkIndex];

            int lastArrayIndex = entityChunk.count - 1;

            if (arrayIndex != lastArrayIndex)
            {
                m_DecalEntityIndexer.UpdateIndex(entityChunk.decalEntities[lastArrayIndex], arrayIndex);
            }

            entityChunk.RemoveAtSwapBack(arrayIndex);
            cachedChunk.RemoveAtSwapBack(arrayIndex);
            culledChunk.RemoveAtSwapBack(arrayIndex);
            drawCallChunk.RemoveAtSwapBack(arrayIndex);
        }
예제 #2
0
        public void UpdateIndex(DecalEntity decalEntity, int newArrayIndex)
        {
            Assert.IsTrue(IsValid(decalEntity));
            var item = m_Entities[decalEntity.index];

            item.arrayIndex = newArrayIndex;
            item.version    = decalEntity.version;
            m_Entities[decalEntity.index] = item;
        }
예제 #3
0
        public bool IsValid(DecalEntity decalEntity)
        {
            if (m_Entities.Count <= decalEntity.index)
            {
                return(false);
            }

            return(m_Entities[decalEntity.index].version == decalEntity.version);
        }
예제 #4
0
        public void DestroyDecalEntity(DecalEntity decalEntity)
        {
            Assert.IsTrue(IsValid(decalEntity));
            m_FreeIndices.Enqueue(decalEntity.index);

            // Update version that everything that points to it will have outdated version
            var item = m_Entities[decalEntity.index];

            item.version++;
            m_Entities[decalEntity.index] = item;
        }
예제 #5
0
        public DecalEntity CreateDecalEntity(DecalProjector decalProjector)
        {
            var material = decalProjector.material;

            if (material == null)
            {
                material = errorMaterial;
            }

            using (new ProfilingScope(null, m_AddDecalSampler))
            {
                int chunkIndex  = CreateChunkIndex(material);
                int entityIndex = entityChunks[chunkIndex].count;

                DecalEntity entity = m_DecalEntityIndexer.CreateDecalEntity(entityIndex, chunkIndex);

                DecalEntityChunk   entityChunk   = entityChunks[chunkIndex];
                DecalCachedChunk   cachedChunk   = cachedChunks[chunkIndex];
                DecalCulledChunk   culledChunk   = culledChunks[chunkIndex];
                DecalDrawCallChunk drawCallChunk = drawCallChunks[chunkIndex];

                // Make sure we have space to add new entity
                if (entityChunks[chunkIndex].capacity == entityChunks[chunkIndex].count)
                {
                    using (new ProfilingScope(null, m_ResizeChunks))
                    {
                        int newCapacity = entityChunks[chunkIndex].capacity + entityChunks[chunkIndex].capacity;
                        newCapacity = math.max(8, newCapacity);

                        entityChunk.SetCapacity(newCapacity);
                        cachedChunk.SetCapacity(newCapacity);
                        culledChunk.SetCapacity(newCapacity);
                        drawCallChunk.SetCapacity(newCapacity);
                    }
                }

                entityChunk.Push();
                cachedChunk.Push();
                culledChunk.Push();
                drawCallChunk.Push();

                entityChunk.decalProjectors[entityIndex] = decalProjector;
                entityChunk.decalEntities[entityIndex]   = entity;
                entityChunk.transformAccessArray.Add(decalProjector.transform);

                UpdateDecalEntityData(entity, decalProjector);

                return(entity);
            }
        }
예제 #6
0
        public void UpdateDecalEntityData(DecalEntity decalEntity, DecalProjector decalProjector)
        {
            var decalItem = m_DecalEntityIndexer.GetItem(decalEntity);

            int chunkIndex = decalItem.chunkIndex;
            int arrayIndex = decalItem.arrayIndex;

            DecalCachedChunk cachedChunk = cachedChunks[chunkIndex];

            cachedChunk.sizeOffsets[arrayIndex] = Matrix4x4.Translate(decalProjector.decalOffset) * Matrix4x4.Scale(decalProjector.decalSize);

            float   drawDistance   = decalProjector.drawDistance;
            float   fadeScale      = decalProjector.fadeScale;
            float   startAngleFade = decalProjector.startAngleFade;
            float   endAngleFade   = decalProjector.endAngleFade;
            Vector4 uvScaleBias    = decalProjector.uvScaleBias;
            int     layerMask      = decalProjector.gameObject.layer;
            ulong   sceneLayerMask = decalProjector.gameObject.sceneCullingMask;
            float   fadeFactor     = decalProjector.fadeFactor;

            cachedChunk.drawDistances[arrayIndex] = new Vector2(drawDistance, fadeScale);
            // In the shader to remap from cosine -1 to 1 to new range 0..1  (with 0 - 0 degree and 1 - 180 degree)
            // we do 1.0 - (dot() * 0.5 + 0.5) => 0.5 * (1 - dot())
            // we actually square that to get smoother result => x = (0.5 - 0.5 * dot())^2
            // Do a remap in the shader. 1.0 - saturate((x - start) / (end - start))
            // After simplification => saturate(a + b * dot() * (dot() - 2.0))
            // a = 1.0 - (0.25 - start) / (end - start), y = - 0.25 / (end - start)
            if (startAngleFade == 180.0f) // angle fade is disabled
            {
                cachedChunk.angleFades[arrayIndex] = new Vector2(0.0f, 0.0f);
            }
            else
            {
                float angleStart = startAngleFade / 180.0f;
                float angleEnd   = endAngleFade / 180.0f;
                var   range      = Mathf.Max(0.0001f, angleEnd - angleStart);
                cachedChunk.angleFades[arrayIndex] = new Vector2(1.0f - (0.25f - angleStart) / range, -0.25f / range);
            }
            cachedChunk.uvScaleBias[arrayIndex]     = uvScaleBias;
            cachedChunk.layerMasks[arrayIndex]      = layerMask;
            cachedChunk.sceneLayerMasks[arrayIndex] = sceneLayerMask;
            cachedChunk.fadeFactors[arrayIndex]     = fadeFactor;
            cachedChunk.scaleModes[arrayIndex]      = decalProjector.scaleMode;

            cachedChunk.positions[arrayIndex] = decalProjector.transform.position;
            cachedChunk.rotation[arrayIndex]  = decalProjector.transform.rotation;
            cachedChunk.scales[arrayIndex]    = decalProjector.transform.lossyScale;
            cachedChunk.dirty[arrayIndex]     = true;
        }
예제 #7
0
 public DecalEntityItem GetItem(DecalEntity decalEntity)
 {
     Assert.IsTrue(IsValid(decalEntity));
     return(m_Entities[decalEntity.index]);
 }
예제 #8
0
 public bool IsValid(DecalEntity decalEntity)
 {
     return(m_DecalEntityIndexer.IsValid(decalEntity));
 }