Brightness fragment shader problem

I’m trying to write a shader to control the brightness of
the displayed image.
the shader is activated (by me) before a call to a drawing of a big
component which contains non-textured polygons and textured polygon.
my question is how can I know if the fragment I’m drawing right now comes out of a textured polygon?

I had a shader which worked in previous versions and not working after a version update. it fails on the command “if (gl_TexCoord[0].st)”

uniform float brt; // brightness [0-1]
uniform sampler2D tex;

void main(void)
vec4 texCol = texture2D(tex,gl_TexCoord[0].st);
if (gl_TexCoord[0].st)


I have not seen this before… “if (gl_TexCoord[0].st)”.
It looks a bit unreliable to me.

You will have to tell the shader with a variable (attribute or uniform) that it is to texture or not to texture, as it replaces all of that functionality in the pipeline.

Alternatively break your model up and use a different shader for textured and non-textured parts.

AFAIK shaders will override / ignore most of the FF texture commands and always have access to whatever textures you give them with Uniform bindings. Accessing things which are not setup properly, or trying to make conditions from them seems like a bad method to me… and I would expect to give undefined behavior.

For example on a certain GPU I could get multiple copies of the viewport being sent to textured polygons when I accessed a texture that did not exist in a shader. Certainly a cool effect, but not exactly ‘defined’ behavior AFAIK.

i guess you’re right about the undefined behavior but the problem is that this drawing is done by a dll that i’m using which draws the whole “component” as a whole and i have no way to control its behavior. so any solution that works, goes.
there is no way to check whether GL_TEXTURE_2D is enabled from the shader?

Have you tried “if (gl_TexCoord[0].st == vec2(0,0))” instead of “if (gl_TexCoord[0].st)”? What is the exact error in the shader info log?

However, this method doesn’t seem reliable. If a textured fragment happens to have the texture coordinates (0,0), won’t the shader wrongly decide that it is not textured?

Not that I know off unfortunately… You could maybe hook the glEnable(GL_TEXTURE_2D) call to detect whether you should use the textured version or the untextured version.

glIntercept does just that to count the number of calls to each function.

I know its a little risky but this time, it does the job for me
thanks man

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.