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

Alpha channel in GPUImageView ? #315

Open og0 opened 12 years ago

og0 commented 12 years ago

Hi,

First congratulations for GPUImage. I have a question, i would like to simulate a video with alpha channel, so i'm trying to use two H.264 videos : one with RGB and another with alpha informations in its RGB channels (i.e. opaque on white pixels and translucent in black pixels). Ideally this video would be played in a GPUImageView, which will be on top of another background UIView.

My first step is to check that the GPUImageView can be translucent. At the moment i'm playing only the grayscale mask video and i don't manage to see my background, the video is always fully opaque. In my custom shader, even if i force alpha to 0, i can see the whole opaque video (i shouldn't see the video, i even shouldn't see the GPUImage view). I forced the GPUImageView alpha to 0.

Is it possible to obtain what i want ? This is my code :

varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;

void main() { lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); lowp vec4 outputColor;

outputColor.r = textureColor.r;
outputColor.g = textureColor.g;
outputColor.b = textureColor.b;
outputColor.a = 0.;

gl_FragColor = outputColor;

}

Thanks in advance !

BradLarson commented 12 years ago

For performance reasons, GPUImageView is always opaque. Rendering translucent OpenGL ES content over other interface elements imposes a significant penalty.

That said, it might be possible to make this an option with the view. I can look into that, but in the meantime the only way to get overlaid content is via the appropriate blends.

TomCorwine commented 12 years ago

@og0 I'm not sure what your exact use case is, but could you do all the compositing in the GPUImage framework and render that to an opaque GPUImageView? That would seem to be the best solution.

og0 commented 12 years ago

Hello and thanks for your answers. Sorry to answer so late i was in holidays.

What i need to do is to display a network streamed video in the background, and i read somewhere it was not possible to do it in GPUImage, am i wrong ? That's why i thought about using a GPUImageView to display a translucent video on top of a Quicktime movie player (used for the stream). But i'm not sure this is the best idea...

So an option to make the GPUImageView translucent would be useful for me (if performances allow it of course).

ghost commented 11 years ago

hello, BradLarson. Could you please add an option to make the gpuimageview translucent.

mdejong commented 11 years ago

Here is a blog post about a alpha + h.264 implementation for iOS http://iosgraphicsanimation.wordpress.com/2013/06/05/h-264-video-with-an-alpha-channel/

BradLarson commented 11 years ago

@mdejong - You're really promoting this everywhere, aren't you, Mo?

mdejong commented 11 years ago

I don't know about everywhere? Only places that nerdy types who might want to implement animations on iOS might see it :)

lucomim commented 10 years ago

@BradLarson really good job on GPUImage!

I find the solution of the GPUImageView solid backgroundColor with this aswer http://stackoverflow.com/a/25167715/1549585