开发者

Fragment shaders: output variables

开发者 https://www.devze.com 2022-12-11 16:02 出处:网络
Reading the GLSL 1.40 specification: Fragment outputs can only be float, floating-point vectors, signed or

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? 开发者_JAVA技巧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)?


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.


Your example has 2 outputs. They have corresponding FBO slots associated after GLSL program linking. You can redirect them using glBindFragDataLocation.

Once you activated the shader and bound FBO, it all depends on a draw mask, set by glDrawBuffers. For example, if you passed GL_COLOR_ATTACHMENT0 and GL_COLOR_ATTACHMENT2 there, that would mean that output index 0 will go to the attachment 0, and output index 1 would go to the color attachment 2.


i want to give some examples:

void add(in float a, in float b, out float c)
{
    //you can not use c here. only set value
    //changing values of a and b does not change anything.
    c = a + b;
}

void getColor(out float r, out float g, out float b)
{
   //you can not use r, g, b here. only set value
   r = gl_FragColor.r;
   g = gl_FragColor.g;
   b = gl_FragColor.b;
}

void amplify(inout vec4 pixelColor, in value)
{
   //inout is like a reference
   pixelColor = pixelColor * value;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消