PDA

View Full Version : Multiple out variables in fragment shader



debonair
05-30-2013, 01:19 AM
I want to use two outs in frag shader and both of them are not vec4. If we use extended blending functionality it allows 2 outs which are vec4 and would be given input to blend equations. Now if my out is having only one channel, how can i use it, i mean in extended blending we have out variables with all 4 channels? How can we choose to use particular out variable at a time?

i have sample shader with two out vars:
i have sample shader with two out vars:



layout(location = 0) out float fragOut0;
layout(location = 1) out float fragOut1;
void main (void)
{
fragOut0 = float(vOutColour.r) + float(0.5);
fragOut1 = float(vOutColour.b) + float(0);
}



how can i write a program which will use above frag shader.

tonyo_au
05-30-2013, 01:37 AM
2 blend outs is different to just multiple output buffers. Your code will work so long as you create a frame buffer with 2 attached texture buffers each with size of 1 float.

debonair
05-30-2013, 02:09 AM
Thanks for your reply.

What i got from you comment is that:
Create FBO and 2 texture attachments, and each texture for each out variable. Now how can i select which out variable i am using. I know we can write to particular attachment by glDrawBuffers(). Is it like, if we have 2 variables with indexing done with "layout" in shader, then 0th indexed will be for first attachement?


frame buffer with 2 attached texture buffers each with size of 1 float..
Can you please explain this?