schr_10

01-27-2012, 09:58 PM

Hi,

Is it possible for a fragment shader to write out either a uint OR a vec4 all depending on the state of a uniform bool?

Assuming the appropriate FBO is attached once the drawing is started of course?

I have tried but cannot make it work so I am just looking to double checking if I have missed something. I cannot see this explicitly stated in the standard, which says something about unused outputs being ignored.

I understand that I can write out two datatypes simultaneously, but that is not what I am looking for.

My frag shader is below and depending on the state of indxmode I would like to write out either "mcode" or "color".

Thanks!

#version 420

in vec3 texcoord;

out uint mcode;

out vec4 color;

uniform usampler3D texindx;

uniform usampler3D tex;

uniform vec2 winlevel;

uniform bool indxmode;

float colval;

float alpha=1.0;

uvec4 val;

void main()

{

if (!indxmode)

{

val=texture(tex,texcoord);

float imgmin=winlevel[1]-0.5*winlevel[0];

colval=(float(val.r)-imgmin)/(winlevel[0]);

color = vec4(colval,colval,colval,alpha);

} else

{

val=texture(texindx,texcoord);

//mcode=val.r;

mcode=1999;

}

}

Is it possible for a fragment shader to write out either a uint OR a vec4 all depending on the state of a uniform bool?

Assuming the appropriate FBO is attached once the drawing is started of course?

I have tried but cannot make it work so I am just looking to double checking if I have missed something. I cannot see this explicitly stated in the standard, which says something about unused outputs being ignored.

I understand that I can write out two datatypes simultaneously, but that is not what I am looking for.

My frag shader is below and depending on the state of indxmode I would like to write out either "mcode" or "color".

Thanks!

#version 420

in vec3 texcoord;

out uint mcode;

out vec4 color;

uniform usampler3D texindx;

uniform usampler3D tex;

uniform vec2 winlevel;

uniform bool indxmode;

float colval;

float alpha=1.0;

uvec4 val;

void main()

{

if (!indxmode)

{

val=texture(tex,texcoord);

float imgmin=winlevel[1]-0.5*winlevel[0];

colval=(float(val.r)-imgmin)/(winlevel[0]);

color = vec4(colval,colval,colval,alpha);

} else

{

val=texture(texindx,texcoord);

//mcode=val.r;

mcode=1999;

}

}