Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragment shaders: output variables

Reading the GLSL 1.40 specification:

Fragment outputs can only be float, floating-point vectors, signed or unsigned integers or integer vectors, or arrays of any these. Matrices and structures cannot be output. Fragment outputs are declared as in the following examples:

out vec4 FragmentColor; out uint Luminosity;

The fragment color is defined writing gl_FragColor... is it right? Somebody could clear my ideas about these outputs? May I write only 'FragmentColor' of the example to determine fragment color? May I read back them ('Luminosity' for example)?

like image 851
Luca Avatar asked Nov 14 '09 09:11

Luca


People also ask

Where fragments output from fragment shader are processed?

Per-Sample Processing is a stage of the OpenGL rendering pipeline, where Fragments output from a Fragment Shader are processed, and their resulting data are written to various buffers.

Can uniform variables be declared in a fragment shader?

Uniform variables can appear in any shader within a shader program, and are always used as input variables. They can be declared in one or more shaders within a program, but if a variable with a given name is declared in more than one shader, its type must be the same in all shaders.

What are the inputs and outputs of a vertex shader?

The Vertex-shader Each vertex shader input vertex can be comprised of up to 16 32-bit vectors (up to 4 components each) and each output vertex can be comprised of as many as 16 32-bit 4-component vectors. All vertex-shaders must have a minimum of one input and one output, which can be as little as one scalar value.

Can you send data from fragment shader to vertex shader?

All shader stages can pass data between them by using input and output variables. If in the vertex shader we create an output variable, we will be able to read it on the fragment shader as an input variable.


1 Answers

The global output variable gl_FragColor is deprecated after GLSL version 120. Now you have to give it a name and type by yourself, as in your example. Regarding several outputs, this link gives you information about the mapping: http://www.opengl.org/wiki/GLSL_Objects#Program_linking

(And I found that link at: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=270999 )

Hope this helps! :D

Ooops! I see that kvark gave the relevant information. Anyway, maybe you got something out of my text too.

like image 137
Deorbit Avatar answered Oct 31 '22 14:10

Deorbit