后处理和生成的纹理 [英] Post processing and resulting texture

查看:126
本文介绍了后处理和生成的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解后处理的工作原理.

I'm trying to understand how post processing work.

根据我的理解,我需要做类似的事情:

From what I understood, I need to to something like that:

-> Bind render texture
-> Draw my scene
-> Unbind render texture
-> Draw a quad full screen using the resulting texture using a shader to apply an effect (blur, …)

该系统的问题是:如何在生成的四边形上应用多种效果?

The problem with that system is: How can I apply multiple effects on the resulting quad?

在我看来,我认为在最终的纹理上应用效果"(着色器),然后绘制四边形可能是最好的解决方案,但是我不知道是否可能.

In my mind, I think applying the "effects" (shaders) on the resulting texture then drawing the quad his probably the best solution, but I don't know if it is possible.

我可以直接在材质上应用着色器吗?

Can I apply shaders on texture directly?

PS:这是我目前所做的,我现在可以在纹理中绘制所有场景:

PS: Here is what I've done for the moment, I can draw all my scene in a texture currently:

  • PostEffect类(要应用的效果)

  • A PostEffect class (an effect to apply)

EffectManager(创建输出纹理并使用方法"add(PostEffect *)"

EffectManager (create the output texture and have a method "add(PostEffect*)"

推荐答案

我不知道将直接"着色器直接应用于"纹理的含义,但是要渲染具有特殊效果的纹理,则需要渲染全屏使用所需的着色器将其四分之一到屏幕,然后将纹理馈入着色器中.要产生多种效果,您需要使用两个帧缓冲区(ping响应),如下所示:

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

您不能在同一帧缓冲区中连续渲染两次,这就是为什么您需要这样做(请参见 https://www.opengl.org/wiki/Framebuffer_Object#Feedback_Loops ).

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.

这篇关于后处理和生成的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆