Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 656
Moss Avatar asked Nov 13 '10 04:11

Moss


People also ask

What is in and out in GLSL?

Ins and outs GLSL defined the in and out keywords specifically for that purpose. Each shader can specify inputs and outputs using those keywords and wherever an output variable matches with an input variable of the next shader stage they're passed along. The vertex and fragment shader differ a bit though.

What is GLSL computer graphics?

Shaders use GLSL (OpenGL Shading Language), a special OpenGL Shading Language with syntax similar to C. GLSL is executed directly by the graphics pipeline. There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders.

How do I edit a GLSL file?

You can also open and edit GLSL files with source code editors, such as Microsoft Visual Studio Code (multiplatform). Since GLSL files are saved in plain text, you can use any text editor, such as Microsoft Notepad (bundled with Windows), Apple TextEdit (bundled with macOS), or gedit (Linux) to open and edit them.


1 Answers

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.

like image 145
Chris Dodd Avatar answered Nov 15 '22 19:11

Chris Dodd