Moss
Moss

Reputation: 3803

Can GLSL output to two/multiple textures at the same time?

I can get a shader to read in two textures but for output it seems there is only gl_FragColor. Is there any way to render to two different textures from one shader? I am using Processing and the GLGraphics library btw.

Upvotes: 8

Views: 5539

Answers (3)

ShannonLiu
ShannonLiu

Reputation: 101

Yes. We can. BUT Notice that gl_FragData is no longer supported in GLSL 4.0. Specify the location as:

glBindFragDataLocation(programHandle, 0, "FragColor");

.....

I hope you could read the book of glsl 4.0 shading language cookbook.

Upvotes: 1

Chris Dodd
Chris Dodd

Reputation: 126140

Yes, you can write to gl_FragData, which is an array of outputs (size depends on your implementation). Or with newer versions of GL, both gl_FragColor and gl_FragData are deprecated and you declare your own out variables for the fragment shader to write to. Declare multiple such out vars for multiple output buffers.

Upvotes: 5

Drew Hall
Drew Hall

Reputation: 29047

I don't know if this is exactly what you're trying to do, but with Frame Buffer Objects (FBOs) you can draw to multiple color buffers simultaneously.

Within the shader, though, it will still just be as if you're writing one fragment. That is, the shader is unaware of how many attachments the FBO has.

Upvotes: 0

Related Questions