DPSF 2.0.1 to 2.1.0

DPSF 2.0.1 to 2.1.0

Top  Previous  Next

1 - New Sprite 3D Billboard Particle System type added

 

The new DefaultSprite3DBillboardParticleSystem is almost always faster (up to 50%) than the traditional DefaultTexturedQuad particle system that updates its particles to always face the camera (i.e. billboards).  Unlike the Textured Quad particle systems though, the Sprite 3D Billboard Particle Systems always have their particles facing the camera, so if you require your particles to be oriented or rotate in all 3 dimensions, then you must still use a Textured Quad particle system.

 

1a - Converting a Textured Quad Particle System to a Sprite 3D Billboard Particle System

If you were using a billboarded Textured Quad particle system, you will likely want to change it to be a Sprite 3D Billboard particle system for better performance by doing the following:

 

- Change particle system class to inherit from the DefaultSprite3DBillboardParticleSystem instead of DefaultTexturedQuadParticleSystem.

 

class FireParticleSystem : DefaultTexturedQuadParticleSystem

 

To:

 

class FireParticleSystem : DefaultSprite3DBillboardParticleSystem

 

 

- Change particles to be of type DefaultSpriteParticle3DBillboardParticle instead of DefaultTexturedQuadParticle.

 

public void InitializeParticleFireOnVerticalRing(DefaultTexturedQuadParticle cParticle)

 

To:

 

public void InitializeParticleFireOnVerticalRing(DefaultSprite3DBillboardParticle cParticle)

 

 

- Initialize the particle system as a Sprite particle system instead of a Quad one.

 

InitializeTexturedQuadParticleSystem(cGraphicsDevice, cContentManager, 1000, 50000, UpdateVertexProperties, "Textures/Fire");

 

To:

 

InitializeSpriteParticleSystem(cGraphicsDevice, cContentManager, 1000, 50000, "Textures/Fire");

 

 

- Change particle orientation from using a Quaternion to just use a scalar value.

 

cParticle.Orientation = DPSF.Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation);

 

To:

 

cParticle.Rotation = RandomNumber.Between(0, MathHelper.TwoPi);

 

 

- Change particle rotations from using Vector3s to just use scalar values.

 

InitialProperties.RotationMin = Vector3.Zero;

InitialProperties.RotationMax.Z = MathHelper.TwoPi;

InitialProperties.RotationalVelocityMin = new Vector3(0, 0, -MathHelper.TwoPi);

InitialProperties.RotationalVelocityMax = new Vector3(0, 0, MathHelper.TwoPi);

 

To:

 

InitialProperties.RotationMin = 0;

InitialProperties.RotationMax = MathHelper.TwoPi;

InitialProperties.RotationalVelocityMin = -MathHelper.TwoPi;

InitialProperties.RotationalVelocityMax = MathHelper.TwoPi;

 

 

- Add Vector3 CameraPosition and override the SetCameraPosition() function to set it.

 

        /// <summary>

        /// Get / Set the Camera Position used by the particle system

        /// </summary>

        public Vector3 CameraPosition { getset; }

 

        /// <summary>

        /// Sets the camera position.

        /// </summary>

        /// <param name="cameraPosition">The camera position.</param>

        public override void SetCameraPosition(Vector3 cameraPosition)

        {

            this.CameraPosition = cameraPosition;

        }

 

 

- No more ColorBlendAmount parameter in the overridden SetEffectParameters() function since it doesn’t use the DPSFDefaultEffect (it uses the AlphaTestEffect) and ColorBlendAmount is only in the DPSFDefaultEffect.  If you don’t want to tint the texture with a color at all (i.e. just use the texture with its original colors), then disable using Vertex Colors on the effect. Change:

 

protected override void SetEffectParameters()

{

       base.SetEffectParameters();

 

       // Specify to not use the Color component when drawing (Texture color is not tinted)

       Effect.Parameters["xColorBlendAmount"].SetValue(0.0f);

}

 

To:

 

protected override void InitializeRenderProperties()

{

  base.InitializeRenderProperties();

 

    AlphaTestEffect effect = this.Effect as AlphaTestEffect;

    if (effect != null)

    {

        // Use the Texture's original colors

        effect.VertexColorEnabled = false;

    }

}

 

 

- Remove the UpdateParticleToFaceTheCamera EveryTime Event:

 

ParticleEvents.AddEveryTimeEvent(UpdateParticleToFaceTheCamera, 200);

 

To (or just delete it):

 

//ParticleEvents.AddEveryTimeEvent(UpdateParticleToFaceTheCamera, 200);

 

 

-  Change fade-out to keep brighter colors.  Because the AlphaTestEffect uses Premultiplied colors, once you start to fade colors out they appear darker.  To help keep your particle colors brighter, you may not want them to be as faded out for most of their lifetime, so consider changing the EveryTime Event you are using to fade the particles out from:

UpdateParticleTransparencyToFadeOutUsingLerp

 

To something like:

 

UpdateParticleTransparencyWithQuickFadeInAndQuickFadeOut

 

 

2 - Changed particle system's IsInitialized() function into IsInitialized boolean property

 

If the compiler complains that the function ".IsInitialized()" doesn't exist on your particle system, simply change it to ".IsInitialized".

 

 

3 - Drawing particles in properly depth-sorted order:

 

Some particle systems don't look quite right unless their particles are drawn in the proper depth-sorted order.  Particularly particles that have semi-transparent sections and are not using additive blending.  To depth-sort your Quad or Sprite3DBillboard particles, first try (as shown in the DPSF Demo's FountainPS.cs):

protected override void InitializeRenderProperties()

{

    base.InitializeRenderProperties();

 

    // Turn on depth buffer writing so particles are drawn in the correct order.

    // This can cause clipping problems with some textures.

    RenderProperties.DepthStencilState = DepthStencilState.Default;

}

 

If it produces clipping problems with the texture you plan on using, then you instead will need to use the more expensive method of (as shown in DPSF Demo's StarPS.cs), which only sorts the particles in a single particle system:

// These textures contain both opaque and semi-transparent portions, so in order to get them drawn correctly (so that

// particles further away aren't drawn overtop of closer particles), we must sort the particles so that they are drawn 

// in the order of farthest from the camera to closest to the camera.

// These operations are expensive, so they should only be used if it is important that particles in front hide the particles behind them.

ParticleEvents.AddEveryTimeEvent(UpdateParticleDistanceFromCameraSquared);

ParticleSystemEvents.AddEveryTimeEvent(UpdateParticleSystemToSortParticlesByDistanceFromCamera);