Wednesday 14 March 2012

Steam System Finalization

In XNA 4.0 there is a common problem with rendering point sprites with Alpha Blending.  For the Steam System I am using Alpha Blending vs Additive Blending because it is crucial to give the clouds the needed voluminous effect.  Additive Blending looks great for the darker exhaust, but for particles that are more detailed and fade out from center, Alpha Blending is the right choice.

As each pixel is written to the Z-Buffer, even those with full alpha, normal rendering results are box artifacts around point sprites for certain camera orientations. These artifacts occur when point sprites are drawn out of order, (relative to the camera position) but even if the list is sorted, the artifacts are extremely visible when two particles have the same distance.  The solution to this problem is to disable writing to Z-Buffer, but maintaining the read function, so the point sprites do not show through other objects in the scene.

This simple solution still has problems with my steam system.  After particles spawn, they fade out linearly until their transparency value is 0.  The sprites are rendered correctly when viewed from the front of the chain, but appear hollow from behind.  This requires that the list needs to be sorted relative to the camera.  From behind the point sprites with the most opacity are drawn last, so the over all effect appears to be a smoke funnel, which is a nice effect, but is not what I am looking for.

As the collection of Point Sprites is a linked list, I can simple choose draw from start or draw from end depending on the position of the camera relative to the spawn point and the wind direction.  This looks fine except at the point where the order changes, there is a very obvious shift in the smoke column because of the details in the steam clouds, and the faded borders necessary to give the steam volume.

My solution to this transition point is to multiply the color of each smoke cloud by the dot product of the vector between the camera and the spawn point, and the wind vector.  This gives a smooth blending as you rotate around the steam column, but the steam only renders fully when viewed exactly from behind or in front.  Make the transition quadratic preserves the full volume effect longer and then quickly changes to the fade transition.

The following video shows these problems:


The transition ends up becoming very white, but I am able to specify the color of the transition to match the color of the smoke.  I am also slightly reducing the size of the point sprites at the transition, otherwise it appears that they grow in the transition.  After balancing these different functions and constant scalars, I have been able to produce steam columns that have volume, texture, and transition smoothly for all orientations.

Using multiple emitters, each emitter must be sorted by its relative position to the camera.  The number of emitters should be very small, (unless the implementation is showing an over all view of the Tar Sands or the coal plants in China)  Unfortunately there is an obvious shift at the transition point, but most of the time this is not too noticeable, and for my purposes this artifact can be tolerated, as it can be avoided.



The second part of this video is integrating the factory with a land map created with my terrain editor.  As particles spawn and dissipate, they effect the land by saturating nearby vertices. 

No comments:

Post a Comment