PDA

View Full Version : Problem with Brightness / contrast of texture



Artem Bochkarev
09-21-2011, 09:29 AM
Hi, I need fast image processing in my application. I find example of code on some site:

static void brightness(V2fT2f *quad, float t) // t [0..2]
{
// One pass using one unit:
// brightness < 1.0 biases towards black
// brightness > 1.0 biases towards white
//
// Note: this additive definition of brightness is
// different than what matrix-based adjustment produces,
// where the brightness factor is a scalar multiply.
//
// A +/-1 bias will produce the full range from black to white,
// whereas the scalar multiply can never reach full white.

glVertexPointer (2, GL_FLOAT, sizeof(V2fT2f), &amp;quad[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &amp;quad[0].s);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
if (t > 1.0f)
{
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
glColor4f(t-1, t-1, t-1, t-1);
}
else
{
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_SUBTRACT);
glColor4f(1-t, 1-t, 1-t, 1-t);
}
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);

validateTexEnv();
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
i tried to use this code in my app,
but the result for t>1 was absolutely white image and black for t<1. I tried many variations of code changes, but still hadn't anyone differed from white or black color. What may be the problem? Could anyone help me?

BionicBytes
09-22-2011, 05:09 AM
The code looks fine to me (quite clever actually).
What values are you trying? You say > 1 but can you be specific?
I'd have thought you could try 1.3 or 1.5 and see what that produces. I assume this code is to be used during some sort of blending operation as the alpha is set to the texture alpha during the RGB_COMBINE operation.
Otherways to acheive this could be to use a shader to reproduce the same effect. Is that an option which is available to you?

Artem Bochkarev
09-22-2011, 09:57 AM
I never used shaders before. But i think, it is time to start using them. But i really don't know, why this code doesn't work. I spent about a day to make it works.
Topic may be closed. I'm starting learn shaders.