1
\$\begingroup\$

I have set up my blur shader with the following header:

#version 400
in vec2 texCoord;

uniform sampler2D u_texture;
uniform vec2 resolution;
uniform float radius;
uniform vec2 dir;

layout (location = 0) out vec4 out_color;
void main() { *some code*; out_color = vec4(*some code*); }

The vertical pass is working well but I would like to use the same Framebuffer for both passes.

My idea was to create Color Attachment1 and Color Attachment2. In the first pass, Attachment1 is the target (out_color) attachment. Now I want the second pass to bind Attachment1 to the sampler2D (u_texture) and write the resulting pixels (out_color) into Attachment2.

If there is any possibility to read from one Attachment and write to another, please let me know.

Thanks in advance!

\$\endgroup\$
2
\$\begingroup\$

Well, I tried a bit with glDrawBuffers and found a working solution.

Before the second pass starts, I simply switched the shader output:

layout (location = 0) out vec4 out_color;

to the second attachment (Attachment2) simply by writing:

GL.DrawBuffer(DrawBufferMode.ColorAttachment2);

This line of code will change the target of the 1st shader output (layout location = 0) so that it writes to Attachment2. Also, I restore the DrawBuffer after the second pass, so the first pass won't have any problems.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.