views:

192

answers:

1

I know that OpenGL has functionality that allow fog drawing.

But, how to draw fog (smoke) using Core Graphics? Is this hard task? And, what concepts for implementing this task?

+3  A: 

I'm not aware of any built-in support for fog in Core Graphics, except insofar as Core Graphics can give you access to an OpenGL viewport.

From a graphics perspective, drawing fog is very different from drawing smoke.

Drawing fog is conceptually simple: for each pixel, you track the distance from the camera to the nearest point. Points that are far away from the camera (past an arbitrary "far" cutoff) fade out to some uniform color, usually light gray. Points that are nearer than some arbitrary "near" cutoff are not modified at all. And the color of points in between is some interpolation of the point's natural color and the fog color. Exactly what sort of interpolation you do is mostly an artistic choice.

Drawing smoke is a harder problem. One common approach is to use a particle system. Each particle in the system represents a clump of smoke. Larger particles are faster but not as realistic looking. Then you animate the bits of smoke using whatever approach gives you the look you want, and draw a translucent blob for each simulated smoke particle.

Ben Karel