conflict with Fog + Blending

Hi guys !
I did billboards with mask like shown with nehe tutorial #20.
I use them to make trees and they are just fine…
but with my fog…when the trees are far…I see white quads…it’s like if what was blended was now fogged and become like white…
I wonder 2 things :

  1. If you understand my problem
  2. If you know how to solve it
    thanks alot !

Evil-Dog
Sleep is a waste of time

fog becomes before blending in the pipeline thus with certain modes eg one,one u will have problems. a possible solution is to do your own fog

If you are using cut-out masks (alpha test) the proper blending mode is one,zero, because all the fragments that pass the alpha test should replace the destination. Then fogging should work right.

As zed said, one,one won’t work with fog, unless perhaps if you change the fog color to black for pixels previously touched by fog (good luck on that one if the first pass doesn’t cover the screen :slight_smile:

zed,

normal fog does the ‘right thing’ for this situation with the source_alpha, one_minus_source_alpha blend function you need for trees.

The problem is most likely that the trees are not sorted against the opaque geometry.

jwatte’s solution is correct, but only a partial fix, the trees will still have a halo if blended depending on the reference value for the alpha test. You trade soft filtered edges or aliasing vs halo size.

You should do this for sure, but you should also draw the trees last, and depth sort them against each other and other blended stuff in the scene if possible.

Another solution on hardware with multisample buffers which avoids the need to sort the trees is to use the alpha to mask multisample mode, to generate a subpixel screendoor and avoid the transparency problem, this will quantize the alpha based on the number of subsamples. Alpha to mask gives you order invariance for transparent geometry, but is not without side effects.

P.S. there may be a bug where the alpha in the trees is being defeated by the fog. This would be a bug for standard OpenGL fog plain and simple.

No, it’s not in the specification for fog to use the alpha of the texture. However, you can make the alpha of the texture change the color of the incoming fragment by changing the texture environment. I think. :stuck_out_tongue: I’m not sure what it’s called, but I would know it if I saw it again. It’s the function where oyu can use GL_BLEND, GL_DECAL, and those other two. Shut up. :stuck_out_tongue: I think you’ll want to use GL_BLEND… but I dunno how it would work. Or you could just compute your own fog.

That’s not what I said patches, but it is what is being reported. I think the original report is a little confused, graphics issues like this are like performing a diagnosis.

Often the difficulty trying to figure out the problem with software you haven’t seen is interpreting the description, in part because it is colored by the users opinion of what is going on rather than the raw facts.

Think about this patches, the tree is blended, and fogged, fog shouldn’t affect the alpha, so it shouldn’t cause a white quad to appear IF the tree has alpha. The fact that it does is most likely one of two things. Either there is a bug in the OpenGL implementation where alpha is being affected, or the description is a symptom not the real problem, and the white quad is actually just a result of zbuffer alpha occlusion.

There is an outside chance that the trees have no alpha and it’s an application error, or that the alpha information is being dropped before getting loaded into the minified MIP map texture levels.

The texture environment you are most likely thinking about is the GL_DECAL texenv, it would do as you say, but it would NOT do it as a function of distance from the viewer or the ammount of fog in the scene. Maybe if application is changing the texture environment with range and the distant trees used a GL_DECAL instead of GL_MODULATE or GL_REPLACE it could cause this problem. That seems unlikely though.

Reading your post it looks like you have confused a bug report with a request for a feature, you realize that evil-dog is reporting a problem he wants to eliminate not requesting help with a feature he wants to implement don’t you?

[This message has been edited by dorbie (edited 01-04-2002).]

well thanks everyone for your concern.
Can someone tell me a solution or there’s no real solution to my problem ?
I don’t use glTexEnvf() at all…should I ?
why ?
I just make my blending with an alphamask and 2 passes to render my blended trees…
like this :
glBlendFunc(GL_DST_COLOR,GL_ZERO);
//Draw a quad with the mask texture here
glBlendFunc(GL_ONE,GL_ONE);
//Draw the same quad with the real texture here

anyone ? hehehe


Evil-Dog
Sleep is a waste of time

Ahh… that’s your problem right there. You aren’t even using alpha.

You have 2 choices.

  1. disable fog when you draw your mask texture.

  2. USE ALPHA!!!

The way you do this is fraught with difficulty, I’m not sure why it works at all, probably because you draw against a black background, and nothing else in the scene. It really is the WRONG way to do it.

Use a glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and add an alpha component to your texture to hold the mask instead of a separate texture. GL_MODULATE texture environment or GL_REPLACE will be fine. Then you only draw the trees ONCE.

Just when you think you’ve seen it all…

P.S.

If you insist on using a separate mask, you could use destination alpha, it’ll cause you fewer problems down the line if you have a graphics system which supports destination alpha, you draw the mask to the alpha channel with an alpha texture and then draw modulate the second pass with glBlendFunc(DST_ALPHA, GL_ONE_MINUS_DST_ALPHA), I still wouldn’t recommend doing this. If you need a separate mask texture you should probably use multitexture, but you probably don’t need this and you should use a single rgba texture.

Hey dorbie thanks a lot.
I thought I understand blending…seems not hehehe
I tried with GL_REPLACE…I’m not sure if I understand now…

float color[4] = {1.0f, 1.0f, 1.0f, 0.0f};
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);

//glColor4f(1.0f,1.0f,1.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D, m_iTextureID2);
glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(0.0f, 0.0f, m_vDimension.x / -2.0f);

	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(0.0f, m_vDimension.y, m_vDimension.x / -2.0f);

	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(0.0f, m_vDimension.y, m_vDimension.x / 2.0f);

	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f, 0.0f, m_vDimension.x / 2.0f);
glEnd();

is this ok ?
please help !
I should’ve posted in the beginner hahaha


Evil-Dog
Sleep is a waste of time

You don’t need the texenv color for a GL_REPLACE texenv.

Ultimately you need to understand texenv, this is key. GL_REPLACE just uses the raw texture data, it replaces the color and alpha totally with the texture color and alpha.

It looks OK, but this assumes you have a texture with alpha. The glBlendFunc using GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA, requires source alpha (surprise :-)), and with a GL_REPLACE texenv that can only come from your texture.

Make sure your tree texture includes an alpha component.

Thanks a lot Dorbie your help is really appriciated.

Ok…I understand that with GL_REPLACE the color key in my texture will be transparent…so my textures need the alpha component.
I use BMP with the Nehe loading technique with glaux. What are better way to load textures ?
What type of image format should I use.
And photoshop don’t seem to have the alpha property for the image type.
What should I do ?
Thanks a lot !


Evil-Dog
Sleep is a waste of time

Well having an image with transparency on file helps, for example an SGI format .rgba image.

You don’t need this though. You can interleave your mask image with the rgb data in memory, just pack them together after loading in software. It would help if they are the same size to begin with.

Hey dorbie, thank you very very much for all your answers…all the others too.

I did it. my blending works just fine.
and the fog also works fine with the blending.
I use tga file format. so i have the alpha component.
That’s great !
the only problem is that I’m not able to make good tga file…only those in a blending demo are working hehehe.
Well i’ll find out !

Thanks guys !


Evil-Dog
Sleep is a waste of time

just to have the little flame over my topic !
hahhahaha !!!

Case closed !


Evil-Dog
Sleep is a waste of time