13
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Embed Size (px)

Citation preview

Page 1: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Emerging Technologies for GamesAlpha Sorting and “Soft” Particles

CO3303

Week 15

Page 2: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Today’s LectureToday’s Lecture

1. Alpha Sorting Problems

2. Run-time Depth Sorting

3. Hard Flat Particles

4. Depth Particles

5. Soft Particles

6. Depth-Soft Particles

7. Further Possibilities

Page 3: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Alpha Sorting ProblemsAlpha Sorting Problems

• 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

• 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

Page 4: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Run-time Depth Sorting 1Run-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●ZCCP is vector from camera to poly,

ZC is camera z-axis

Page 5: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Run-time Depth Sorting 2Run-time Depth Sorting 2

• 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?

• How to sort polys that face in any direction?

• No, a more complex approach is needed

Page 6: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Run-time Depth Sorting 3Run-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

Page 7: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Run-time Depth Sorting 4Run-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

Page 8: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Run-time Sorting PracticalitiesRun-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

Page 9: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Hard Flat ParticlesHard 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)

Page 10: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Depth ParticlesDepth 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

Page 11: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Soft ParticlesSoft 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

Page 12: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Depth-Soft ParticlesDepth-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

Page 13: Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15

Further PossibilitiesFurther 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