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.22k stars 4.62k forks source link

Draw particle effects offscreen and merge it with GPUMovie? #2422

Open vikram-gupta opened 7 years ago

vikram-gupta commented 7 years ago

I have a SkView which is having a SKEmitterNode to generate particle animation. When I attach this SkView to the parent view, I am able to see the particle animation. However, I want to be able to do draw the particle animation offscreen directly on the pixel buffer. How can I do this?

If the above is not possible, can I somehow blend SkView with the GPUImageMovie?

I came across this article where a snapshot of the SkView can be taken. However, I need to do this for every frame or every update on the SkView.

What is a best way to do this? Any pointers would be really helpful.

BradLarson commented 7 years ago

You'd need to somehow render this to a texture, and then use that texture as an input. You'd need to make sure that the texture this was rendered to was part of the same sharegroup as the GPUImage rendering context.

There's an example for how to do this with OpenGL rendering in the sample applications, and Scene Kit has capabilities for rendering scenes to textures.

vikram-gupta commented 7 years ago

Thanks @BradLarson !

Just wanted to confirm my understanding about the same. Please correct me if I am wrong.

We can use the following function to get the texture of the SkView for every render cycle and blend the extracted texture with GPUImageMovie.

- (SKTexture *)textureFromNode:(SKNode *)node;

However, the SkView is getting rendered by iOS as I added it as a subview, so I am not sure if this gets rendered in same context. Do you think that the SkView would be rendered in the same share group by default?

I also wanted to ask if there is a way to convert a dynamic/changing view into a stream similar to GPUImageMovie so that whenever there is a change in the view, the blend filter automatically gets updated frames from the view and outputs a new blended frame?