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.
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.
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.
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.
链接地址: http://www.djcxy.com/p/48860.html下一篇: GLSL可以同时输出两个/多个纹理吗?