PDA

View Full Version : return in fragment shader and linking multiple fragment shaders



divide
03-20-2004, 03:31 AM
I wrote this simple fragment shader to test the "return" command:

void main (void)
{
gl_FragColor = vec4 (1.0,0,0,0);
return;
gl_FragColor = vec4 (0,0,1.0,0);
}

However it seems not to return, since the final color I get is blue (0,0,1) and not red (1,0,0). What is the problem ?

Second question: how to "link" multiple fragment shaders, so that when the first fragment shader return, a second fragment shader do his job, based on results from the first fragment shader ?

Corrail
03-20-2004, 04:43 AM
I wrote this simple fragment shader to test the "return" command:

void main (void)
{
gl_FragColor = vec4 (1.0,0,0,0);
return;
gl_FragColor = vec4 (0,0,1.0,0);
}

However it seems not to return, since the final color I get is blue (0,0,1) and not red (1,0,0). What is the problem ?


Seems like a bug... Which gaphic card/driver do you use=



Second question: how to "link" multiple fragment shaders, so that when the first fragment shader return, a second fragment shader do his job, based on results from the first fragment shader ?


Try this:

Fragment Shader 1:



vec4 my_frag_shader();

void main()
{
gl_FragColor = my_frag_shader();
}


Fragment Shader 2:



vec4 my_frag_shader()
{
vec4 tmp;
// do something
return tmp;
}


This should work, hope that is what you wanted!

divide
03-20-2004, 05:24 AM
thanks for help

My card is ATI Radeon 9800SE with Catalyst 4.3

Can you test this shader



void main (void)
{
gl_FragColor = vec4 (1.0,0,0,0);
return;
gl_FragColor = vec4 (0,0,1.0,0);
}


and tell me if you have the same problem ? (that is, blue color instead of red)

Corrail
03-20-2004, 07:51 AM
*hm*

This shader is a red color shader here:



void main (void)
{
gl_FragColor = vec4 (1.0,0,0,0);
return;
gl_FragColor = vec4 (0,0,1.0,0);
}


I've got a Radoen 9800Pro with Catalyst 4.3...

divide
03-20-2004, 09:35 AM
well.. maybe it's because I've tested this with 3DLabs SDK example, and maybe it only fully works with 3DLabs cards.

Corrail
03-20-2004, 09:58 AM
?

This code:



void main (void)
{
gl_FragColor = vec4 (1.0,0,0,0);
return;
gl_FragColor = vec4 (0,0,1.0,0);
}

should be red and it is red when I've tested it.

[This message has been edited by Corrail (edited 03-20-2004).]

divide
03-20-2004, 12:08 PM
yes I agree it should be but it is not in the 3DLabs SDK example running with my Radeon 9800SE. But I'll make another test with a clean code, not 3DLabs related.

divide
03-20-2004, 12:34 PM
No way.. I've tried with Ffelagund's ShaderDesigner (www.typhoonlabs.com) but it doesn't change anything: I still have a blue render when I paste this code into a fragments shader:

void main (void)
{
gl_FragColor = vec4 (1,0,0,0);
return;
gl_FragColor = vec4 (0,0,1,0);
}

I'm... puzzled ! anyone with a radeon 9800se ?

divide
03-21-2004, 12:25 AM
Works !
Actually I was running with Catalyst 4.2
I installed Catalyst 4.3 and everything works well !