texture parameters vs. texture-unit parameters

I want to render billboards that are using GL_NEAREST texture mode while GL_BLEND and GL_ALPHA_TEST are enabled. To disable the problem with the pixels at the side of the billboard (the alpha channel is also smoothed) i’m using multitexturing with the alpha channel of a GL_NEAREST texture and the color channel of a GL_LINEAR texture.
The problem is that if I use the same texture for both texture units the GL_(LINEAR/NEAREST) is a texture parameter instead of an unit parameter and both of my textures are LINEAR. Is there a way to duplatate the texture (and thus I would be able tho set LINEAR/NEAREST independently)while pointing to the same data in texture memory?

Charles Hollemeersch

ps: If there is an earsier way to fix the billboard problem I would like to hear it.

I want to render billboards that are using GL_NEAREST texture mode while GL_BLEND and GL_ALPHA_TEST are enabled. To disable the problem with the pixels at the side of the billboard (the alpha channel is also smoothed) i’m using multitexturing with the alpha channel of a GL_NEAREST texture and the color channel of a GL_LINEAR texture.

Are you saying you want the color of the billboard texture bilinearly filtered and the alpha component not? I’ve never had to do anything like that for billboards. Use GL_REPEAT when loading the texture (that prevents it from blending with the border color), and set the edge’s alpha to 0 (that prevents it from blending with the wrap around edge). Alternatively you can use offset texture coordinates. Instead of using the full range [0,1] for the billboard’s s texture coordinates, use [1/width,1-1/width] where width is the width of the texture. Of course similiarly you’d use [1/height, 1-1/height] for the t coordinate range. In this instance, you’ll need to duplicate the logical edge in the physical edge so that when the logical edge is filtered with the physical edge, no effective blending occurs.

I want the color of the billboard texture bilinearly filtered and the alpha component not, but the problem is not the border of my billboard polygon. The billboards are actually trees so I have much pixels in the texture with alpha 0 to model the leafs. Every pixel in the texture with adjacent pixels with alpha=0 gradualy becomes more transparent and I want to eleminate this while still keeping the colors bilineary filtered.

Charles Hollemeersch

ps: Is there a way to post screenshots here it would be much clearer with a small screen shot.

instead of blending, you can do an alphatest… then you have your alphacomponetns filtered anyways, but it dont use the equation AB+CD wich results in halftransparent parts of the pixels, but it uses if alpha (EQUAL,LOWER,etc) a static value, the pixel is rendered or not… (results in more than pixel detailed transparence when it is billinear filtered… looks cool in my opinion)

void glAlphaFunc(
GLenum func,
GLclampf ref
);

Parameters
func
The alpha comparison function. The following are the accepted symbolic constants and their meanings. Symbolic Constant Meaning
GL_NEVER Never passes.
GL_LESS Passes if the incoming alpha value is less than the reference value.
GL_EQUAL Passes if the incoming alpha value is equal to the reference value.
GL_LEQUAL Passes if the incoming alpha value is less than or equal to the reference value.
GL_GREATER Passes if the incoming alpha value is greater than the reference value.
GL_NOTEQUAL Passes if the incoming alpha value is not equal to the reference value.
GL_GEQUAL Passes if the incoming alpha value is greater than or equal to the reference value.
GL_ALWAYS Always passes. This is the default.

ref
The reference value to which incoming alpha values are compared. This value is clamped to the range 0 through 1, where 0 represents the lowest possible alpha value and 1 the highest possible value. The default reference is 0.

Remarks
The alpha test discards fragments depending on the outcome of a comparison between the incoming fragments’ alpha values and a constant reference value. The glAlphaFunc function specifies the reference and comparison function. The comparison is performed only if alpha testing is enabled. (For more information on GL_ALPHA_TEST, see glEnable.)

The func and ref parameters specify the conditions under which the pixel is drawn. The incoming alpha value is compared to ref using the function specified by func. If the comparison passes, the incoming fragment is drawn, conditional on subsequent stencil and depth-buffer tests. If the comparison fails, no change is made to the frame buffer at that pixel location.

The glAlphaFunc function operates on all pixel writes, including those resulting from the scan conversion of points, lines, polygons, and bitmaps, and from pixel draw and copy operations. The glAlphaFunc function does not affect screen clear operations.

Alpha testing is done only in RGBA mode.

I know I can use an alpha test to fix the problem but I also need to blend (I use “tranparent fog” so that my trees blend with the skybox in the distance)

Hmmm, he said was using alpha testing. But now I guess I see his error.

You will not be able to set up an alpha test to reject only the pixels that initally have maximum alpha. Why? Because a pixel that intially has alpha 1, after filtering, could be as low as 1/4. And a pixel that initially has alpha 0, after filtering, could be as high as 3/4. In other words if you want to do what you say, you will have to use a seperate non-filtered texture to modulate the filtered texture. This way would return all alpha values that started as 0, back to 0. Then you could use an alpha test GL_GREATER with reference value 0. However notice that an artifact of this method is that the pixels that bound rejected pixels, will have lost some color. This could be minimized by repeating the boundary pixels.

A separate texture. But can it be done with the same texture?? I have tried it with:

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,tex1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
//setup combine_ext

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D,tex1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
//setup combine_ext

But the problem is that the texture rendered by TEXTURE0_ARB is also NEAREST. Wich explains the topic title is LINEAR/NEAREST bound to the texture or the texture-unit. I know you can do this way of multitexturing in D3d on a GeForce2 (At least ultima9 pretends to do it), all I actually needed to know is how you set it up under opengl.

its because opengl stores the filtering per texture (as thought before…)
like that it is not possible to set up the same texture in one texturestage bilinear, and in the other nearest…

I THINK I found a way to do this with one texture and linear filtering on. My technique would require you to have alpha testing set to reject pixels with < .5 alpha, and to NOT use alpha blending.

In your graphic file, generate the RGB image as usual. In the alpha channel, give all pixels in the opaque section an alpha value of 1, and all transparent pixels in the transparent section an alpha of 0, EXCEPT…

If you take the border between transparent and nontransparent pixels, you should see that you have 2 outlines ( one outline for the transparent pixels, one outline for the opaque pixels). Assuming an 8 bit alpha channel (values 0 to 255), set the pixels in the opaque outline to an alpha of 128, and the pixels in the transparent outline to 127.

Although I cant quite explain my reasoning, I think this should work reasonably well (although you might have a few incorrectly accepted/rejected pixels here and there…Im not positive).

As far as this generating of border pixels, you could conceivable have the artwork stored as all fully transparent and fully opaque pixels and have you image loader automatically generate the border alpha values as it loads them into openGL texture objects.

Use premultiplied alpha textures. Set RGB to 0 when A is 0, and use a blend mode of (for example) ONE,ONE_MINUS_SRC_ALPHA.

  • Matt

Originally posted by mcraighead:
[b]Use premultiplied alpha textures. Set RGB to 0 when A is 0, and use a blend mode of (for example) ONE,ONE_MINUS_SRC_ALPHA.

  • Matt[/b]

As I understand this, I dont think it will work. What he is looking for is a linear textured billboard but with sharp edged transparency rather than edges that fade out.

LordKronos’s idea might work with alpha testing but (as I understand it) it won’t work with blending (as he said) enabled (the pixels between the opaque parts with alpha 1.0 and the border with alpha 128 would also be lineary filtered and would thus be transparent). But I need the blending

And what are “premultiplied alpha textures”?
Does it require another texture and a second rendering pass?

Pentagram