0

I have a webgl shader set up with some shaders. I'm using multiple render targets (gl_FragData[])

In the first shader, I can output to

gl_FragData[0] = vec4(..);
gl_FragData[1] = vec4(..);
gl_FragData[2] = vec4(..);

Now with my second shader, I want to output to gl_FragData[3] and save the texture to pass to my third shader.

The second shader doesn't seem to output to gl_FragData[3], yet this works if I use it in my first shader. I want the output of gl_FragData[3] to be stored in a texture and sent to the third shader.

I think it may have to do with the framebuffer, but I've tried changing that and have had no luck. What am I missing?

  • Why not just make 2 framebuffers. One with 3 attachments, one with 1 attachment, output to gl_FragData[0] in the second shader – gman Apr 08 '17 at 13:39

1 Answers1

0

If you want to use the same framebuffer, you'll need to mask off the unused draw buffers: drawBuffers([COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, COLOR_ATTACHMENT2]) for the first shader, and drawBuffers([NONE, NONE, NONE, COLOR_ATTACHMENT3]) for the second shader.

From EXT_draw_buffers:

Any colors, or color components, associated with a fragment that are not written by the fragment shader are undefined.

Jeff Gilbert
  • 406
  • 2
  • 4