简体   繁体   English

后处理和产生的纹理

[英]Post processing and resulting texture

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: Here is what I've done for the moment, I can draw all my scene in a texture currently: PS:这是我目前所做的,我现在可以在纹理中绘制所有场景:

  • A PostEffect class (an effect to apply) PostEffect类(要应用的效果)

  • EffectManager (create the output texture and have a method "add(PostEffect*)" EffectManager(创建输出纹理并具有方法“ add(PostEffect *)”

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: 要产生多种效果,您需要使用两个帧缓冲区(ping响应),如下所示:

-> 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 ). 您不能连续向同一帧缓冲区渲染两次,这就是为什么需要这样做的原因(请参阅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. 唯一使用着色器的时间是当您通过glDrawArrays或glDrawElements进行绘制调用时,假定您正确创建了FBO和RBO。 So yes, you must use a full screen rendering technique of some sort. 所以是的,您必须使用某种全屏渲染技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM