Skip to main content
GameDev.net gamedev.net
🔒 Locked

Fog and Blend

Started by Maxwan Jul 11, 2004 at 6:02 PM 41 replies 5.5k views
Original Post
Maxwan
Maxwan
I've heard alot of this problem but I don't know what to do about it. I've searched the forum but didn't find any results so I hope you guys can help me. First have a look at this screenshot:
zedzeek
zedzeek
fog works per vertex thus tesselate the water quad more.
also check out radex fog (or someit, it was first a nvidia extension) its better than linear.
Maxwan
Maxwan
Sorry to say it, but that did not help me that much :( Can't you, or someone else, point me to a internetpage with some "hard stuff" to work with. 'Cause I've tried to solve this problem and I can't find a soulution.
zedzeek
zedzeek
tesselate means to devide up into smaller area
thus if youre using 1 quad to draw the water, draw the water with say 10,000 quads (which are each 10,000x as small)
Maxwan
Maxwan
First of all, tell me one thing better with drawing 10000 quads instead of 1 ... :) An no, it is not 1 quad, it's about 100, cause they are still quite big. That is not the problem however, the problem is that I don't want it to be visual where the terrain is "building up" in the end of the fog.

The problem is that the blending, as I said before, works poor with fog. If I remove the blend from the water, just making it to solid quads, then the fog works. So it has nothing to do with the size of the quads.

Anyone with another solution ?
tomek_zielinski
tomek_zielinski
How do you want fog to work with blnding if you didn't take it into account?


Look at what you are doing:

1. FragmentColor = PixelColor*fog + (1-fog)*FogColor
2. NewFrameBuffer = BLEND( OldFrameBuffer, FragmentColor )


So you are blending AFTER fogging!! You have to recalculate it to achieve desirable results. There is no 'one valid way' to do it - just recalculate it to work good - you can change blending mode, make two passes or sth else...

I usually solve an equation and adjust background color
www.tmreality.com
Hamster
Hamster
Try switching the fog colour to black before rendering your stuff using blending, and switch it back to whatever it previously was before continuing, that sometimes helps fog & blending issues along.
mikeman
mikeman
Quote:

glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, bakgrund[2].texturId);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);


What are you trying to do here?GL_BLEND works only with 1 or 2-component textures.For 3 or 4,the results are undefined.The procedure you should follow is simple,and I don't know why you need multitexturing to blend the water with the background.
1)Enable fog
2)Render all solid geometry:trees,ground,and the ground below the water
3)glEnable(GL_BLEND);glBlendFunc(...);
4)Render the water
5)Disable blending








FReY
FReY
Are all your texstages setup correctly?

You may be doing a glTexEnv(...,GL_ADD) somewhere there still. Disable your unused texture stages - what happened to GL_TEXTURE0_ARB? is it still active?


do unto others... and then run like hell.
Maxwan
Maxwan
mikeman: The steps you explain is the steps I take, even if it maybe doesn't look like that. If I changed the order, than it doesn't work at all. Well, it is like you said so it don't matter anyway :)

FReY: Yeah it is correct, or at least I'm 90% sure at it. If I use like GL_ADD, then it won't work as it should at all. And GL_TEXTURE0_ARB is already disabled.


Anyway, the problem is like when the fog fade's to one color, the blended water blends the fog (or really, the water, that is blended in one color and now get many colors) and because of that you still can see the water. But how to .. argh. Any new ideas?
mikeman
mikeman
As I already said,GL_BLEND does not work with RGB or RGBA textures.And I really can't see why you want to use it.
Can you describe what's in the texture units?What texture is in tex1 and tex2?What are you using them for?

Quote:

Well, as you can see, the fog is loaded in the startup and then later the texture that should be blended is, well, blended :)


There is no texture that needs to be blended.There are the fragments the compose the water that need to be blended with the background(colors already present in the buffer).Or maybe I'm misunderstanding something here?

-EDIT:I just saw your BlendFunc,and it's not right.You must use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);





[Edited by - mikeman on July 12, 2004 11:51:53 AM]
vincoof
vincoof
It looks like your water is multitextured in multipass, and that one of the passes doesn't enable fog.
zedzeek
zedzeek
tomek_zielinski is correct blending comes after fog in the pipeline, u can always roll yourown fog (a simple calculation per vertex) and add this as a texture layer (works on all hardware)
or alternatively u can use vertex programs to do the fog
tomek_zielinski
tomek_zielinski
So just write an equation with one unknown variable, one parameter and a number of constants:

bg_color = f( [param]fog_color, [const]texture, [consts]... )

then either calculate bg_color(fog_color) or fog_color(bg_color)...
www.tmreality.com
Maxwan
Maxwan
mikeman:
"Can you describe what's in the texture units?What texture is in tex1 and tex2?What are you using them for?"
The first texture is, well, it's nothing but if I don't have that one the second will not be visible cause that one is blended. And the second, blended one, is like waves on the water. It looks nice :)

"There is no texture that needs to be blended.There are the fragments the compose the water that need to be blended with the background(colors already present in the buffer).Or maybe I'm misunderstanding something here?"
I don't really understand what you mean. Maybe you're right but I guess that the texture still needs to be blended. Agh, damn, I don't know... :)

---------------
vincoof:
"It looks like your water is multitextured in multipass, and that one of the passes doesn't enable fog."
Both passes the fog cause if they didn't, then it would look alot diffrent. If I do not missunderstand you.

----------------
zedzeek:
Do you mean that I need to "blend" all the vertexes in the water to a specified color (and that would be the soft blue)? If so - just by using glColor3f or?

----------------
tomek_zielinski:
I am really sorry but I don't understand what you mean. Not at all :) Call me stupid but, you have to explain it alot easier...

:)

Thanks for the help guys, even if I'm to stupid to understand what I need to do... I'll go to sleep now, and wake up in the morning, hoping for a really nice explanation or some code :)
kburkhart84
kburkhart84
I don't honestly know so much what the fuss is about. In reality, I think the screenshot looks good enough to me. The water kind of fades in to the fog just like the rest of the scene. It looks fine to me.


zedzeek
zedzeek
>>soft blue)? If so - just by using glColor3f or?<< it is possible (see an article in gamastura from about 3-4years ago i believe it was about vol fog), alternatively u can use a texture.

check out volumetric fog it does exactly what u want it to do
mikeman
mikeman
Quote:
Original post by Maxwan
mikeman:
"Can you describe what's in the texture units?What texture is in tex1 and tex2?What are you using them for?"
The first texture is, well, it's nothing but if I don't have that one the second will not be visible cause that one is blended.

Honestly,what you've just said make no sense at all.Blended with what?And why will not be visible?Trust me,you're wrong at this.


Quote:
Original post by Maxwan
"There is no texture that needs to be blended.There are the fragments the compose the water that need to be blended with the background(colors already present in the buffer).Or maybe I'm misunderstanding something here?"
I don't really understand what you mean. Maybe you're right but I guess that the texture still needs to be blended. Agh, damn, I don't know... :)


Ok,now I'm convinced that you know very little about blending.So quick lesson:

First,forget about multitexturing.You don't need multitexturing to achieve blending.As far as I can see,you don't need it.Just use one texture stage,and that's it.And for the 3rd time:GL_BLEND USED AS TEXTURE ENVIRONMENT DOES NOT WORK WITH RGB OR RGBA TEXTURES AND DOES NOT DO WHAT YOU THINK IT DOES(are that parts of my posts invisible or something?I said it 2 times and no response from you).Forget multitexturing for now,erase it from your memory,what else can I say?

Now,we're working with just one texture.Set the texture environment to GL_MODULATE.Render all the solid objects.
Now the water.Enable blending.Set glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA).That means that,for every pixel,if D is the color already present in the buffer(from the rendering of the solid objects),S is the color of the water,and a is the alpha value of the water,the final color will be:
C=S*a+D*(1-a)
As you can see,the water will be blended with the solid objects that are behind it.I suggest that,when rendering the water,disable lighting and z-writes,set the alpha value using glColor4f(1,1,1,a) and set the fog color to (fr,fg,fb,a).


That's it.I hope you won't respond with a post that contains the words "blended texture".Try to understand here that you want to blend fragments,not textures.
vincoof
vincoof
Quote:
Original post by Maxwan
vincoof:
"It looks like your water is multitextured in multipass, and that one of the passes doesn't enable fog."
Both passes the fog cause if they didn't, then it would look alot diffrent. If I do not missunderstand you.

You understood me very well, but I still think one of the passes doesn't hit fog. Why ? Because if all passes hit fog, you could not notice any detail above line #3. And I can see some kind of "detail" in shades of light blue and grey (probably texture mapping of zone #1) above this line, so it means not everything is fogged.
mikeman
mikeman
Quote:
Original post by vincoof
Quote:
Original post by Maxwan
vincoof:
"It looks like your water is multitextured in multipass, and that one of the passes doesn't enable fog."
Both passes the fog cause if they didn't, then it would look alot diffrent. If I do not missunderstand you.

You understood me very well, but I still think one of the passes doesn't hit fog. Why ? Because if all passes hit fog, you could not notice any detail above line #3. And I can see some kind of "detail" in shades of light blue and grey (probably texture mapping of zone #1) above this line, so it means not everything is fogged.


Vincoof,when you say multipass,you mean that the scene is rendered more than once,right?But MaxWan doesn't mention it,he just says he uses multitexturing,although it's completely useless to him.I think he should post his rendering code,because all he's posted is how he setup multitexturing,and,as I said,he doesn't even need it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.