BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

Fill only filters - radial gradient fill shader #716

Open jacobjennings opened 11 years ago

jacobjennings commented 11 years ago

I'd like to implement a radial gradient fill shader, since the core graphics one is very slow. A source texture won't be used. Is GPUImage the right tool for this job? Any tips the high-level approach?

jacobjennings commented 11 years ago

From what I'm reading, alpha compositing mixing CAEAGLLayer-backed views is slow, so I'm thinking of using a UIImageView subclass to present that uses GPUImage to generate radial gradient images.

jacobjennings commented 11 years ago

I am also speculating about how CA implicit animation might be implemented with GPU acceleration to make a full-featured analog to CAGradientLayer for radial gradients.

BradLarson commented 11 years ago

This shouldn't be that hard to do, you'll just need to create a custom shader that draws the gradient within your image. You'd need to specify center, start and ending colors, and start and ending positions, and from that you should be able to use some sort of interpolation to calculate the color at that location based on its radial distance. Look at something like the bulge distortion filter to see how you'd calculate radial distance and others for how you feed in colors for display.

I was going to create a linear gradient generator at one point, but only got up to a solid color in the GPUImageSolidColorGenerator.