コード例 #1
0
        public void Sort(ParticleSystemInstance instance, Vector3 camDir)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("system");
            }

            Debug.Assert(m_sortedIndices.Length == m_depth.Length);

            int totalParticles = instance.TotalLiveParticles;

            int destLength = m_sortedIndices.Length;
            while (destLength < totalParticles)
            {
                destLength *= 2;
            }

            if (destLength > m_sortedIndices.Length)
            {
                m_sortedIndices = new int[destLength];
                m_depth = new float[destLength];
            }

            // fill the indices
            for (int i = 0; i < totalParticles; ++i)
            {
                m_sortedIndices[i] = i;
            }

            // sort the indices by depth
            if (instance.System.BlendMode == BlendMode.Alpha)
            {
                int j = 0;
                foreach (var effect in instance.EffectInstances)
                {
                    effect.BatchProcess((particles, begin, end) =>
                    {
                        for (int i = begin; i < end; ++i)
                        {
                            var p = particles[i];
                            m_depth[j++] = Vector3.Dot(p.m_position, camDir);
                        }
                    });
                }

                Array.Sort(m_depth, m_sortedIndices, 0, totalParticles);
            }
        }
コード例 #2
0
        internal EffectInstance(Effect effect, ParticleSystemInstance instance)
        {
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }
            else if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            else if (instance.System != effect.System)
            {
                throw new ArgumentException("Effect and Instance is not from the same ParticleSystem.");
            }

            Effect = effect;
            SystemInstance = instance;
            IsEmitting = effect.EmitOnStart;
            m_oldAlignment = effect.Alignment;
        }