OpenGL ES 2.0: How do I customize the convolution kernel? - opengl-es

I want to blur bitmap with some custom shape, like heart/circle or more shape.
box blur or gaussian blur kernel like this(below is box):
[1,1,1]
[1,1,1]
[1,1,1]
I want kernel is like below bitmap, black is 1, white is 0, then use it to blur.
How do I make the kernel of blur to heart shape? In fact, I already know how to make polygons(Efficiently Simulating the Bokeh of Polygonal Apertures
in a Post-Process Depth of Field Shader), but I don't know how to customize the irregular shapes (circles, hearts, moons, and all sorts of weird shapes).

Related

Android OpenGL ES: How to generate sharp circle by dilate?

I want use dilate to make lightspot on bitmap to sharp circle, like bokeh effect, the process is similar to convolution operation.
Below is a hexagon convolution kernel, and the circular convolution kernel is similar, it doesn't look like a perfect circle in the matrix. Using the circle Max blur in Photoshop, the result is not sharp and the edges are very rough.
How to fix it?

How do I make a line at surface?

I know there's a function to fill rectangles surface.FillRect(&Rect, uint32), but is there a way to draw a line in the surface, like a function for renderer renderer.DrawLine(x1, y1, x2, y2)?
In SDL2 Surface is just a structure that represents a bitmap (2D matrix of pixels) in driver agnostic format. In terms of drawing Surface API is limited to setting pixels or easily defined groups of them (rectangles) or blitting (copying) rectangles of one surface to the other. With that API you technically can draw a line by calculating coordinates of each pixel on that line between coords x1,y1 and x2,y2 and setting each pixel to the desired color. In SDL2 library itself there is no such utility function.
Renderer is much more advanced API that takes care of many underlying aspects of accelerated rendering. On top of single pixels and rectangles it offers also line primitives. Instead of Surface it uses Texture which stores pixels in an optimized format for underlying graphics driver (and thus provides higher performance when drawing). If you are working on something new you should stick with Renderer. If you need to plug code based on Surface to Renderer code, you can create Texture from Surface data using the Renderer.CreateTextureFromSurface() method.

Image Effect with Dark Borders

I was creating an effects library for a PhotoBooth App. I have created effects like Black/White, Vintage, Sepia, Retro etc. etc.
I wanted to create a few effects now in which I wanted to have a Dark Border at the edges which kind of form a frame for the image .. something like this -> Example Effect
How can I do this using Pixel Bender and Flash ?
The effect you are describing is called vignetting. It is basically just darkening the pixels with some weight that changes depending on distance from the center of the image. In image editing it corresponds to overlaying the image with black color and applying a circular or elliptic mask to it, for example:
(source: johnhpanos.com)
You can do this by several methods depending on how you operate with image and its pixels. For example by multiplying the pixels by a weight coefficient that is smaller when closer to the center and bigger when farther away from it. The distance can be calculated from the difference between pixel coordinates.

image smoothing in opengl?

Does opengl provide any facilities to help with image smoothing?
My project converts scientific data to textures, each of which is a single line of colored pixels which is then mapped onto the appropriate area of the image. Lines are mapped next to each other.
I'd like to do simple image smoothing of this, but am wondering of OGL can do any of it for me.
By smoothing, I mean applying a two-dimensional averaging filter to the image - effectively increasing the number of pixels but filling them with averages of nearby actual colors - basically normal image smoothing.
You can do it through a custom shader if you want. Essentially you just bind your input texture, draw it as a fullscreen quad, and in the shader just take multiple samples around each fragment, average them together, and write it out to a new texture. The new texture can be an arbitrary higher resolution than the input texture if you desire that as well.

How to draw "glowing" line in OpenGL ES

Could you please share some code (any language) on how draw textured line (that would be smooth or have a glowing like effect, blue line, four points) consisting of many points like on attached image using OpenGL ES 1.0.
What I was trying was texturing a GL_LINE_STRIP with texture 16x16 or 1x16 pixels, but without any success.
In ES 1.0 you can use render-to-texture creatively to achieve the effect that you want, but it's likely to be costly in terms of fill rate. Gamasutra has an (old) article on how glow was achieved in the Tron 2.0 game — you'll want to pay particular attention to the DirectX 7.0 comments since that was, like ES 1.0, a fixed pipeline. In your case you probably want just to display the Gaussian image rather than mixing it with an original since the glow is all you're interested in.
My summary of the article is:
render all lines to a texture as normal, solid hairline lines. Call this texture the source texture.
apply a linear horizontal blur to that by taking the source texture you just rendered and drawing it, say, five times to another texture, which I'll call the horizontal blur texture. Draw one copy at an offset of x = 0 with opacity 1.0, draw two further copies — one at x = +1 and one at x = -1 — with opacity 0.63 and a final two copies — one at x = +2 and one at x = -2 with an opacity of 0.17. Use additive blending.
apply a linear vertical blur to that by taking the horizontal blur texture and doing essentially the same steps but with y offsets instead of x offsets.
Those opacity numbers were derived from the 2d Gaussian kernel on this page. Play around with them to affect the fall off towards the outside of your lines.
Note the extra costs involved here: you're ostensibly adding ten full-screen textured draws plus some framebuffer swapping. You can probably get away with fewer draws by using multitexturing. A shader approach would likely do the horizontal and vertical steps in a single pass.

Resources