Post processing and resulting texture

巧了我就是萌 提交于 2019-12-06 08:23:37

I don't know what you mean with "directly applying" shaders to a texture, but to render a texture with a special effect you need to render a fullscreen quad to the screen with the shader you need, and of course feed the texture into the shader. To have multiple effects you need to use two framebuffers (ping-ponging), like this:

-> Bind 1st render texture
-> Draw scene

-> Bind 2nd render texture
-> Feed 1st render texture to a shader and draw quad

-> Bind 1st render texture
-> Feed 2nd render texture to another shader and draw quad

-> Bind 2nd render texture
-> Feed 1st render texture to a third shader and draw quad

...
-> Unbind
-> Draw quad

You cannot render two times in a row to the same framebuffer, which is why you need to do this way (see https://www.opengl.org/wiki/Framebuffer_Object#Feedback_Loops).

If you can, try to pack as many effects as possible into the same shader to minimize overhead when feeding uniforms and drawing.

Post processing tecniques can vary depending on what you want to accomplish. You can either write a single shader that applies multiple post processing effects and render to the texture a single time, or if the renderings are sequential in nature then you need a double buffer:

render to texture 1
use texture one and render to texture 2
use texture 2 and render to texture 1
etc 
etc

and do that until all of your post effects are applied. But then you should render the final pass straight to your screen render buffer to avoid a costly 'copying' of the texture to the screen render buffer.

Can I apply shaders on texture directly?

Not sure what you even mean by that. The only time a shader is utilized is when you do a draw call via glDrawArrays or glDrawElements assumming you created your FBO and RBOs correctly. So yes, you must use a full screen rendering technique of some sort.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!