コード例 #1
0
 internal ParticleSystem(
     FXParticleSystemTemplate template,
     AssetLoadContext loadContext,
     GetMatrixReferenceDelegate getWorldMatrix)
     : this(template, loadContext)
 {
     _getWorldMatrix = getWorldMatrix;
 }
コード例 #2
0
        public ParticleSystem Create(
            FXParticleSystemTemplate template,
            ParticleSystem.GetMatrixReferenceDelegate getWorldMatrix)
        {
            ParticleSystem result;

            _particleSystems.Add(
                AddDisposable(
                    result = new ParticleSystem(
                        template,
                        _loadContext,
                        getWorldMatrix)));

            return(result);
        }
コード例 #3
0
 internal ParticleSystem(
     FXParticleSystemTemplate template,
     AssetLoadContext loadContext,
     in Matrix4x4 worldMatrix)
コード例 #4
0
 public ParticleSystem Create(
     FXParticleSystemTemplate template,
     in Matrix4x4 worldMatrix)
コード例 #5
0
ファイル: ParticleSystem.cs プロジェクト: ybwsfl/OpenSAGE
        public ParticleSystem(
            ContentManager contentManager,
            FXParticleSystemTemplate template,
            GetMatrixReferenceDelegate getWorldMatrix)
        {
            Template = template;

            _getWorldMatrix = getWorldMatrix;

            var maxParticles = CalculateMaxParticles();

            // If this system never emits any particles, there's no reason to fully initialise it.
            if (maxParticles == 0)
            {
                return;
            }

            _graphicsDevice = contentManager.GraphicsDevice;

            _renderItemConstantsBufferVS = AddDisposable(new ConstantBuffer <MeshShaderResources.RenderItemConstantsVS>(_graphicsDevice));

            _velocityType = Template.EmissionVelocity;
            _volumeType   = Template.EmissionVolume;

            var texturePath = Path.Combine("Art", "Textures", Template.ParticleName);
            var texture     = contentManager.Load <Texture>(texturePath);

            _particleResourceSet = AddDisposable(contentManager.ShaderResources.Particle.CreateParticleResoureSet(
                                                     _renderItemConstantsBufferVS.Buffer,
                                                     texture));

            _shaderSet = contentManager.ShaderResources.Particle.ShaderSet;
            _pipeline  = contentManager.ShaderResources.Particle.GetCachedPipeline(Template.Shader);

            _initialDelay = Template.InitialDelay.GetRandomInt();

            _startSizeRate = Template.StartSizeRate.GetRandomFloat();
            _startSize     = 0;

            _colorKeyframes = new List <ParticleColorKeyframe>();

            var colors = Template.Colors;

            if (colors.Color1 != null)
            {
                _colorKeyframes.Add(new ParticleColorKeyframe(colors.Color1));
            }

            void addColorKeyframe(RgbColorKeyframe keyframe, RgbColorKeyframe previous)
            {
                if (keyframe != null && keyframe.Time > previous.Time)
                {
                    _colorKeyframes.Add(new ParticleColorKeyframe(keyframe));
                }
            }

            addColorKeyframe(colors.Color2, colors.Color1);
            addColorKeyframe(colors.Color3, colors.Color2);
            addColorKeyframe(colors.Color4, colors.Color3);
            addColorKeyframe(colors.Color5, colors.Color4);
            addColorKeyframe(colors.Color6, colors.Color5);
            addColorKeyframe(colors.Color7, colors.Color6);
            addColorKeyframe(colors.Color8, colors.Color7);

            _particles = new Particle[maxParticles];
            for (var i = 0; i < _particles.Length; i++)
            {
                _particles[i].AlphaKeyframes = new List <ParticleAlphaKeyframe>();
                _particles[i].Dead           = true;
            }

            _deadList = new List <int>();
            _deadList.AddRange(Enumerable.Range(0, maxParticles));

            var numVertices = maxParticles * 4;

            _vertexBuffer = AddDisposable(contentManager.GraphicsDevice.ResourceFactory.CreateBuffer(
                                              new BufferDescription(
                                                  (uint)(ParticleShaderResources.ParticleVertex.VertexDescriptor.Stride * maxParticles * 4),
                                                  BufferUsage.VertexBuffer | BufferUsage.Dynamic)));

            _vertices = new ParticleShaderResources.ParticleVertex[numVertices];

            _indexBuffer = AddDisposable(CreateIndexBuffer(
                                             contentManager.GraphicsDevice,
                                             maxParticles,
                                             out _numIndices));

            State = ParticleSystemState.Active;

            _beforeRender = (cl, context) =>
            {
                // Only update once we know this particle system is visible on screen.
                Update(cl, context.GameTime);

                if (_worldMatrixChanged)
                {
                    _renderItemConstantsBufferVS.Update(cl);
                }

                cl.SetGraphicsResourceSet(1, _particleResourceSet);

                cl.SetVertexBuffer(0, _vertexBuffer);
            };
        }