コード例 #1
0
 /// <inheritdoc/>
 public override byte[] GetBytes()
 {
     // !!!!Caution: keep the order of the following code lines!!!!
     return(GetBytes(ParticleIndex.Bytes(),
                     SimpleTypeIndex.Bytes(),
                     AttributesCount.Bytes(),
                     StartIndexOfAttributes.Bytes()));
 }
コード例 #2
0
        private void UpdateBuffer(EvaluationContext context)
        {
            int count = Count.GetValue(context);

            if (count <= 0)
            {
                return;
            }

            if (_data == null || count != _data.Length)
            {
                _data = new ParticleIndex[count];
                var random = new Random(0);
                for (int i = 0; i < count; i++)
                {
                    _data[i].index = i;
                    _data[i].squaredDistToCamera = random.Next(-10000, 10000);
                }
            }

            ResourceManager.Instance().SetupStructuredBuffer(_data, ref Buffer.Value);
        }
コード例 #3
0
        private void DrawParticlesBackToFront(ParticleSystemData particleSystemData, bool requiresTransformation, ref Vector3 scale, ref Pose pose, ref Vector3 color, float alpha, float angleOffset)
        {
            var b = new BillboardArgs
            {
                Orientation    = particleSystemData.BillboardOrientation,
                Softness       = particleSystemData.Softness,
                ReferenceAlpha = particleSystemData.AlphaTest,
            };

            int numberOfParticles = particleSystemData.Particles.Count;
            var particles         = particleSystemData.Particles.Array;

            if (_particleIndices == null)
            {
                _particleIndices = new ArrayList <ParticleIndex>(numberOfParticles);
            }
            else
            {
                _particleIndices.Clear();
                _particleIndices.EnsureCapacity(numberOfParticles);
            }

            // Use linear distance for viewpoint-oriented and world-oriented billboards.
            bool useLinearDistance = (particleSystemData.BillboardOrientation.Normal != BillboardNormal.ViewPlaneAligned);

            // Compute positions and distance to camera.
            for (int i = 0; i < numberOfParticles; i++)
            {
                if (particles[i].IsAlive) // Skip dead particles.
                {
                    var particleIndex = new ParticleIndex();
                    particleIndex.Index = i;
                    if (requiresTransformation)
                    {
                        particleIndex.Position = pose.ToWorldPosition(particles[i].Position * scale);
                    }
                    else
                    {
                        particleIndex.Position = particles[i].Position;
                    }

                    // Planar distance: Project vector onto look direction.
                    Vector3 cameraToParticle = particleIndex.Position - _cameraPose.Position;
                    particleIndex.Distance = Vector3.Dot(cameraToParticle, _cameraForward);
                    if (useLinearDistance)
                    {
                        particleIndex.Distance = cameraToParticle.Length * Math.Sign(particleIndex.Distance);
                    }

                    _particleIndices.Add(ref particleIndex);
                }
            }

            // Sort particles back-to-front.
            _particleIndices.Sort(ParticleIndexComparer.Instance);

            bool isViewPlaneAligned = (particleSystemData.BillboardOrientation.Normal == BillboardNormal.ViewPlaneAligned);
            bool isAxisInViewSpace  = particleSystemData.BillboardOrientation.IsAxisInViewSpace;

            // Draw sorted particles.
            var indices = _particleIndices.Array;

            numberOfParticles = _particleIndices.Count; // Dead particles have been removed.
            for (int i = 0; i < numberOfParticles; i++)
            {
                int index = indices[i].Index;
                b.Position = indices[i].Position;
                if (requiresTransformation)
                {
                    b.Normal = isViewPlaneAligned ? _defaultNormal : pose.ToWorldDirection(particles[index].Normal);
                    b.Axis   = isAxisInViewSpace ? particles[index].Axis : pose.ToWorldDirection(particles[index].Axis);
                    b.Size   = particles[index].Size * scale.Y; // Assume uniform scale for size.
                }
                else
                {
                    b.Normal = isViewPlaneAligned ? _defaultNormal : particles[index].Normal;
                    b.Axis   = particles[index].Axis;
                    b.Size   = particles[index].Size;
                }

                b.Angle         = particles[index].Angle + angleOffset;
                b.Color         = particles[index].Color * color;
                b.Alpha         = particles[index].Alpha * alpha;
                b.AnimationTime = particles[index].AnimationTime;
                b.BlendMode     = particles[index].BlendMode;

                var texture = particleSystemData.Texture ?? _debugTexture;
                _billboardBatch.DrawBillboard(ref b, texture);
            }
        }
コード例 #4
0
 public GameObject GetParticle(ParticleIndex index)
 {
     return(ParticlePrefabList[(int)index].ParticleObj);
 }
コード例 #5
0
 public MyParticle(GameObject part, ParticleIndex index)
 {
     this.ParticleObj = part;
     this.index       = index;
 }