Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15 Today’s Lecture 1. 2. 3. 4. 5. 6. 7. Alpha Sorting Problems Run-time Depth Sorting Hard Flat Particles Depth Particles Soft Particles Depth-Soft Particles Further Possibilities Alpha Sorting Problems • Saw alpha blending in the second year – A very attractive blending technique • However, it causes sorting issues – Without resolving these, method is not very useful • Problem is depth buffer ignores transparency – Transparent pixels drawn in nearby polygons “obscure” distant polygons drawn later • Avoid problem by drawing polygons from back to front Run-time Depth Sorting 1 • One solution is to sort all alpha blended polys in back-to-front order – Every frame (can be slow) • If all polygons face camera (e.g. a particle system): – Sort polygons based on camera-space z distance – Camera space z = CP●ZC CP is vector from camera to poly, ZC is camera z-axis Run-time Depth Sorting 2 • How to sort polys that face in any direction? • Might think to sort on camera-space z again – But distance to which point on the polygon? – Nearest? – Furthest? – Average? • Will any of these work? • No, a more complex approach is needed Run-time Depth Sorting 3 • First, assume that polygons don’t intersect • Then, given two polygons, one of them will be entirely on one side of the plane of the other • Identify this polygon, and see if it is on the side nearer the camera or not • First step is to get a face normal for each polygon – Reverse normal if it faces away from the camera – Do this prior to sorting Run-time Depth Sorting 4 • Join either point of polygon 2 to each of the points of polygon 1 • Calculate dot products of these vectors with normal of polygon 2: – Results all +ve: poly 1 is nearer – Results all -ve: poly 1 is further – Results mixed: poly 1 is split by plane of poly 2. So repeat test the other way round (2nd diagram) – If split both ways, then the polygons are intersecting Run-time Sorting Practicalities • Must ensure this sorting is efficient as possible – Sort pointers to polygons not polygon data itself (less to sort) – Retain previous sorting and use a sort algorithm that is good with almost sorted data (e.g. insertion sort) – Don’t sort every frame, only every two or three – Run the sorting concurrently – Reduce density of particle systems based on distance – Use partitions to help: • Sort partitions from back to from, then particles in one partition at a time – reducing number polygons in each sort • In practice, another technique (not covered here), alpha-to-coverage is often used as an alternative Hard Flat Particles • Alpha blending is as useful as other blending methods once the polygons are sorted – Note: just like other blending (additive, multiplicative etc.), we need to render all the opaque polygons first • However, all blending methods exhibit hard edges if they intersect other polygons – Makes dense particle systems look poor – Particularly large particles like smoke (indoors is particularly bad) Depth Particles • A simple improvement is to give alpha blended particles some depth – Simulated bumpiness, like normal / parallax mapping – Store it in the alpha channel of the texture • Adjust the depth used for the depth-buffer by this value – Improves hard edges by making them bumpy • Must hand calculate depth value in shader – Not done this before Soft Particles • To improve further, note that visual problems mainly occur when a particle intersects with an opaque object • We know the opaque objects have already been drawn… – So they are already in depth buffer • Can compare depth of particle with depth already in buffer • Fade pixels out when the difference is small – Adjust alpha towards 0 Depth-Soft Particles • This method can be combined with the depth particles idea presented earlier – Or can just be used on flat particles • We must do some detailed work with depth buffer – Rather unfamiliar • But almost completely removes hard edges where alpha particles intersect solid objects – Can work with other blending modes too Further Possibilities • The SoftParticles DirectX10 sample in the DirectX SDK takes this idea a little further – Explores volumetric particles - consider the volume of particle that camera is looking through
© Copyright 2026 Paperzz