openGL fixed function pipeline - scale texture intensity beyond 1.0

1.3k views Asked by At

is there a way other than multitexturing or multipass rendering to scale a texture's intensity above factor 1.0 using the fixed function pipeline?

it can be achived with multipass rendering. for example factor 1.5 can be achieved by rendering the texture at full intensity once and then with color(0.5,0.5,0.5,1.0) a second time using additive blending.

but is there also a way to achieve this with a single pass and without multitexturing?

2

There are 2 answers

4
Jeremy CD On

I'm assuming you're using either an OpenGL 3.0 or OpenGL ES library. I think you could do something like this, though I'm not sure how supported it is.

This should be a bit more supported than my original answer, but you're stuck with using 1.5 as the modulation value.

// Setup...
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex1);

// Combine: Result.rgb = Texture + Texture - 0.5
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

// Combine: Result.a = Texture
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

If you can do it using shaders, you'd be much better off:

//Fragment shader
uniform sampler2D texture;
uniform float blend;
varying vec2 texcoord;
void main()
{
   vec4 texel0 = texture2D(texture, texcoord);
   texel0 *= blend;
   gl_FragColor = texel;
}
0
Pivot On

You can use the GL_RGB_SCALE and GL_ALPHA_SCALE properties of the texture environment to apply a 2× or 4× scale factor, but this requires you to use the GL_COMBINE texture environment mode instead of the predefined modes. To get your 1.5 scale factor, you’d set GL_RGB_SCALE to 2.0 and set a color of {0.75, 0.75, 0.75, 1.0}. Note that the texture environment for each texture unit still clamps to [0, 1], so if you need this type of scaling, you should apply the scale on the last texture unit to avoid any clipping.