PDA

View Full Version : Output type of frag shader - can it be set dynamic



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;

}

}

Alfonse Reinheart
01-27-2012, 11:54 PM
And what exactly would be written to the other image?

If you want to do this kind of thing, you shouldn't use outputs. Use shader_image_load_store instead.

schr_10
01-28-2012, 12:51 AM
Thanks for reply.
Nothing would be written to the screen buffer when indxmode is false. The intention is to set indxmode to true only when there has been a spatial change in the scene and then only as a second render to the FBO (following/before the scene redraw).
Thanks for the pointer to the new functionality that I may make use of. It will either be that or simply have a second shader program for the integer buffer.
Thanks again,
Soren