Esempio n. 1
0
 private void OnDecalPropertyChange(DecalProjector decalProjector)
 {
     if (m_DecalEntityManager.IsValid(decalProjector.decalEntity))
     {
         m_DecalEntityManager.UpdateDecalEntityData(decalProjector.decalEntity, decalProjector);
     }
 }
Esempio n. 2
0
 private void OnDecalAdd(DecalProjector decalProjector)
 {
     if (!m_DecalEntityManager.IsValid(decalProjector.decalEntity))
     {
         decalProjector.decalEntity = m_DecalEntityManager.CreateDecalEntity(decalProjector);
     }
 }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
 private void OnDecalMaterialChange(DecalProjector decalProjector)
 {
     // Decal will end up in new chunk after material change
     OnDecalRemove(decalProjector);
     OnDecalAdd(decalProjector);
 }
Esempio n. 6
0
 private void OnDecalRemove(DecalProjector decalProjector)
 {
     m_DecalEntityManager.DestroyDecalEntity(decalProjector.decalEntity);
 }